• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

aplus-framework / coding-standard / 16536124402

16 Oct 2024 10:16PM UTC coverage: 100.0%. Remained the same
16536124402

push

github

natanfelles
Show image in user guide

301 of 301 relevant lines covered (100.0%)

5.73 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/Config.php
1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of Aplus Framework Coding Standard Library.
4
 *
5
 * (c) Natan Felles <natanfelles@gmail.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace Framework\CodingStandard;
11

12
/**
13
 * Class Config.
14
 *
15
 * @package coding-standard
16
 */
17
class Config extends \PhpCsFixer\Config
18
{
19
    public function __construct(mixed ...$params)
20
    {
21
        parent::__construct(...$params);
6✔
22
        $this->setRiskyAllowed(true);
6✔
23
        $this->setIndent('    ');
6✔
24
        $this->setLineEnding("\n");
6✔
25
        $this->setCacheFile('.php-cs-fixer.cache');
6✔
26
        $this->prepareRules();
6✔
27
    }
28

29
    protected function prepareRules() : void
30
    {
31
        $this->setRules([
6✔
32
            'align_multiline_comment' => true,
6✔
33
            'array_indentation' => false,
6✔
34
            'array_syntax' => [
6✔
35
                'syntax' => 'short',
6✔
36
            ],
6✔
37
            'assign_null_coalescing_to_coalesce_equal' => true,
6✔
38
            'binary_operator_spaces' => [
6✔
39
                'default' => 'single_space',
6✔
40
            ],
6✔
41
            'blank_line_after_namespace' => true,
6✔
42
            'blank_line_after_opening_tag' => false,
6✔
43
            'blank_line_before_statement' => false,
6✔
44
            'blank_lines_before_namespace' => [
6✔
45
                'min_line_breaks' => 1,
6✔
46
                'max_line_breaks' => 1,
6✔
47
            ],
6✔
48
            'braces_position' => true,
6✔
49
            'cast_spaces' => [
6✔
50
                'space' => 'single',
6✔
51
            ],
6✔
52
            'class_attributes_separation' => [
6✔
53
                'elements' => [
6✔
54
                    'method' => 'one',
6✔
55
                    'trait_import' => 'none',
6✔
56
                ],
6✔
57
            ],
6✔
58
            'class_definition' => [
6✔
59
                'multi_line_extends_each_single_line' => false,
6✔
60
                'single_item_single_line' => true,
6✔
61
                'single_line' => true,
6✔
62
            ],
6✔
63
            'combine_consecutive_issets' => true,
6✔
64
            'combine_consecutive_unsets' => true,
6✔
65
            'combine_nested_dirname' => false,
6✔
66
            'comment_to_phpdoc' => false,
6✔
67
            'compact_nullable_type_declaration' => true,
6✔
68
            'concat_space' => [
6✔
69
                'spacing' => 'one',
6✔
70
            ],
6✔
71
            'constant_case' => true,
6✔
72
            'control_structure_braces' => true,
6✔
73
            'control_structure_continuation_position' => ['position' => 'same_line'],
6✔
74
            'date_time_immutable' => false,
6✔
75
            'declare_equal_normalize' => [
6✔
76
                'space' => 'none',
6✔
77
            ],
6✔
78
            'declare_parentheses' => true,
6✔
79
            'declare_strict_types' => false,
6✔
80
            'dir_constant' => true,
6✔
81
            'echo_tag_syntax' => [
6✔
82
                'format' => 'short',
6✔
83
            ],
6✔
84
            'elseif' => true,
6✔
85
            'empty_loop_condition' => true,
6✔
86
            'encoding' => true,
6✔
87
            'ereg_to_preg' => true,
6✔
88
            'error_suppression' => false,
6✔
89
            'explicit_indirect_variable' => true,
6✔
90
            'explicit_string_variable' => true,
6✔
91
            'final_internal_class' => false,
6✔
92
            'fopen_flag_order' => true,
6✔
93
            'full_opening_tag' => true,
6✔
94
            'fully_qualified_strict_types' => true,
6✔
95
            'function_declaration' => [
6✔
96
                'closure_function_spacing' => 'one',
6✔
97
            ],
6✔
98
            'function_to_constant' => true,
6✔
99
            'general_phpdoc_annotation_remove' => [
6✔
100
                'annotations' => [],
6✔
101
                'case_sensitive' => true,
6✔
102
            ],
6✔
103
            /*'header_comment' => [
104
                'comment_type' => 'comment',
105
                'header' => '',
106
                'location' => 'after_declare_strict',
107
                'separate' => 'none',
108
             ],*/
109
            'heredoc_indentation' => true,
6✔
110
            'heredoc_to_nowdoc' => true,
6✔
111
            'implode_call' => false,
6✔
112
            'include' => true,
6✔
113
            'increment_style' => false,
6✔
114
            'indentation_type' => true,
6✔
115
            'is_null' => false,
6✔
116
            'line_ending' => true,
6✔
117
            'linebreak_after_opening_tag' => false,
6✔
118
            'list_syntax' => ['syntax' => 'short'],
6✔
119
            'logical_operators' => true,
6✔
120
            'lowercase_cast' => true,
6✔
121
            'lowercase_keywords' => true,
6✔
122
            'lowercase_static_reference' => true,
6✔
123
            'magic_constant_casing' => true,
6✔
124
            'magic_method_casing' => true,
6✔
125
            'mb_str_functions' => false,
6✔
126
            'method_argument_space' => [
6✔
127
                'keep_multiple_spaces_after_comma' => false,
6✔
128
                'on_multiline' => 'ensure_fully_multiline',
6✔
129
            ],
6✔
130
            'method_chaining_indentation' => true,
6✔
131
            'modernize_strpos' => true,
6✔
132
            'modernize_types_casting' => true,
6✔
133
            'multiline_comment_opening_closing' => true,
6✔
134
            'multiline_whitespace_before_semicolons' => [
6✔
135
                'strategy' => 'no_multi_line',
6✔
136
            ],
6✔
137
            'native_constant_invocation' => true,
6✔
138
            'native_function_casing' => true,
6✔
139
            'native_function_invocation' => [
6✔
140
                'include' => ['@internal'],
6✔
141
                'scope' => 'namespaced',
6✔
142
                'strict' => true,
6✔
143
            ],
6✔
144
            'new_with_parentheses' => true,
6✔
145
            'no_alias_functions' => true,
6✔
146
            'no_alternative_syntax' => false,
6✔
147
            'no_binary_string' => true,
6✔
148
            'no_blank_lines_after_class_opening' => true,
6✔
149
            'no_blank_lines_after_phpdoc' => true,
6✔
150
            'no_break_comment' => false,
6✔
151
            'no_closing_tag' => true,
6✔
152
            'no_empty_comment' => false,
6✔
153
            'no_empty_phpdoc' => true,
6✔
154
            'no_empty_statement' => true,
6✔
155
            'no_extra_blank_lines' => [
6✔
156
                'tokens' => [
6✔
157
                    'break',
6✔
158
                    'case',
6✔
159
                    'continue',
6✔
160
                    'curly_brace_block',
6✔
161
                    'default',
6✔
162
                    'extra',
6✔
163
                    'parenthesis_brace_block',
6✔
164
                    'return',
6✔
165
                    'square_brace_block',
6✔
166
                    'switch',
6✔
167
                    'throw',
6✔
168
                    'use',
6✔
169
                ],
6✔
170
            ],
6✔
171
            'no_homoglyph_names' => false,
6✔
172
            'no_leading_import_slash' => true,
6✔
173
            'no_leading_namespace_whitespace' => true,
6✔
174
            'no_mixed_echo_print' => true,
6✔
175
            'no_multiline_whitespace_around_double_arrow' => true,
6✔
176
            'no_multiple_statements_per_line' => true,
6✔
177
            'no_null_property_initialization' => true,
6✔
178
            'no_php4_constructor' => false,
6✔
179
            'no_short_bool_cast' => true,
6✔
180
            'no_singleline_whitespace_before_semicolons' => true,
6✔
181
            'no_space_around_double_colon' => true,
6✔
182
            'no_spaces_after_function_name' => true,
6✔
183
            'no_spaces_around_offset' => true,
6✔
184
            'no_superfluous_elseif' => true,
6✔
185
            'no_superfluous_phpdoc_tags' => false,
6✔
186
            'no_trailing_comma_in_singleline' => true,
6✔
187
            'no_trailing_whitespace' => true,
6✔
188
            'no_trailing_whitespace_in_comment' => true,
6✔
189
            'no_unneeded_braces' => true,
6✔
190
            'no_unneeded_control_parentheses' => true,
6✔
191
            'no_unneeded_final_method' => true,
6✔
192
            'no_unreachable_default_argument_value' => false,
6✔
193
            'no_unset_cast' => false,
6✔
194
            'no_unset_on_property' => false,
6✔
195
            'no_unused_imports' => true,
6✔
196
            'no_useless_else' => true,
6✔
197
            'no_useless_return' => true,
6✔
198
            'no_whitespace_before_comma_in_array' => true,
6✔
199
            'no_whitespace_in_blank_line' => true,
6✔
200
            'non_printable_character' => true,
6✔
201
            'normalize_index_brace' => true,
6✔
202
            'not_operator_with_space' => false,
6✔
203
            'not_operator_with_successor_space' => false,
6✔
204
            'nullable_type_declaration' => true,
6✔
205
            'nullable_type_declaration_for_default_null_value' => true,
6✔
206
            'object_operator_without_whitespace' => true,
6✔
207
            'ordered_class_elements' => [
6✔
208
                'order' => [
6✔
209
                    'use_trait',
6✔
210
                    'case',
6✔
211
                    'constant',
6✔
212
                    'property',
6✔
213
                    'construct',
6✔
214
                    'destruct',
6✔
215
                    'magic',
6✔
216
                    'method',
6✔
217
                    'method_static',
6✔
218
                ],
6✔
219
                'sort_algorithm' => 'none',
6✔
220
            ],
6✔
221
            'ordered_imports' => true,
6✔
222
            'ordered_types' => [
6✔
223
                'case_sensitive' => true,
6✔
224
                'null_adjustment' => 'always_last',
6✔
225
            ],
6✔
226
            'php_unit_construct' => true,
6✔
227
            'phpdoc_add_missing_param_annotation' => true,
6✔
228
            'phpdoc_align' => false,
6✔
229
            'phpdoc_annotation_without_dot' => true,
6✔
230
            'phpdoc_indent' => true,
6✔
231
            'phpdoc_inline_tag_normalizer' => true,
6✔
232
            'phpdoc_line_span' => true,
6✔
233
            'phpdoc_no_access' => true,
6✔
234
            'phpdoc_no_alias_tag' => ['replacements' => ['type' => 'var', 'link' => 'see']],
6✔
235
            'phpdoc_no_empty_return' => false,
6✔
236
            'phpdoc_no_package' => false,
6✔
237
            'phpdoc_no_useless_inheritdoc' => true,
6✔
238
            'phpdoc_order' => true,
6✔
239
            'phpdoc_return_self_reference' => true,
6✔
240
            'phpdoc_scalar' => true,
6✔
241
            'phpdoc_separation' => true,
6✔
242
            'phpdoc_single_line_var_spacing' => true,
6✔
243
            'phpdoc_summary' => true,
6✔
244
            'phpdoc_to_comment' => false,
6✔
245
            'phpdoc_trim' => true,
6✔
246
            'phpdoc_trim_consecutive_blank_line_separation' => true,
6✔
247
            'phpdoc_types' => true,
6✔
248
            'phpdoc_types_order' => [
6✔
249
                'case_sensitive' => true,
6✔
250
                'null_adjustment' => 'always_last',
6✔
251
                'sort_algorithm' => 'alpha',
6✔
252
            ],
6✔
253
            'phpdoc_var_annotation_correct_order' => true,
6✔
254
            'phpdoc_var_without_name' => false,
6✔
255
            'pow_to_exponentiation' => false,
6✔
256
            'protected_to_private' => false,
6✔
257
            'psr_autoloading' => false,
6✔
258
            'random_api_migration' => false,
6✔
259
            'return_assignment' => true,
6✔
260
            'return_type_declaration' => [
6✔
261
                'space_before' => 'one',
6✔
262
            ],
6✔
263
            'self_accessor' => false,
6✔
264
            'semicolon_after_instruction' => false,
6✔
265
            'set_type_to_cast' => true,
6✔
266
            'short_scalar_cast' => true,
6✔
267
            'simplified_null_return' => false,
6✔
268
            'single_blank_line_at_eof' => true,
6✔
269
            'single_class_element_per_statement' => true,
6✔
270
            'single_import_per_statement' => true,
6✔
271
            'single_line_after_imports' => true,
6✔
272
            'single_line_comment_style' => true,
6✔
273
            'single_quote' => true,
6✔
274
            'single_space_around_construct' => true,
6✔
275
            'space_after_semicolon' => true,
6✔
276
            'spaces_inside_parentheses' => [
6✔
277
                'space' => 'none',
6✔
278
            ],
6✔
279
            'standardize_increment' => true,
6✔
280
            'standardize_not_equals' => true,
6✔
281
            'static_lambda' => true,
6✔
282
            'strict_comparison' => true,
6✔
283
            'string_implicit_backslashes' => [
6✔
284
                'double_quoted' => 'escape',
6✔
285
                'heredoc' => 'escape',
6✔
286
                'single_quoted' => 'unescape',
6✔
287
            ],
6✔
288
            'strict_param' => false,
6✔
289
            'string_line_ending' => true,
6✔
290
            'switch_case_semicolon_to_colon' => true,
6✔
291
            'switch_case_space' => true,
6✔
292
            'ternary_operator_spaces' => true,
6✔
293
            'ternary_to_null_coalescing' => true,
6✔
294
            'trailing_comma_in_multiline' => ['elements' => ['arrays']],
6✔
295
            'trim_array_spaces' => true,
6✔
296
            'type_declaration_spaces' => ['elements' => ['function', 'property']],
6✔
297
            'types_spaces' => ['space' => 'single'],
6✔
298
            'unary_operator_spaces' => true,
6✔
299
            'visibility_required' => true,
6✔
300
            'void_return' => true,
6✔
301
            'whitespace_after_comma_in_array' => [
6✔
302
                'ensure_single_space' => true,
6✔
303
            ],
6✔
304
            'yoda_style' => false,
6✔
305
        ]);
6✔
306
    }
307

308
    /**
309
     * @param array<string,mixed> $rules
310
     *
311
     * @return static
312
     */
313
    public function replaceRules(array $rules) : static
314
    {
315
        $this->setRules(\array_replace_recursive($this->getRules(), $rules));
4✔
316
        return $this;
4✔
317
    }
318

319
    public function setHeaderComment(string $header) : static
320
    {
321
        $this->replaceRules([
4✔
322
            'header_comment' => [
4✔
323
                'comment_type' => 'comment',
4✔
324
                'header' => $header,
4✔
325
                'location' => 'after_declare_strict',
4✔
326
                'separate' => 'none',
4✔
327
            ],
4✔
328
        ]);
4✔
329
        return $this;
4✔
330
    }
331

332
    /**
333
     * @param string $packageName
334
     * @param array<string>|string $copyright
335
     */
336
    public function setDefaultHeaderComment(
337
        string $packageName,
338
        array | string $copyright = []
339
    ) : static {
340
        if ($copyright === '') {
2✔
341
            $copyright = [];
2✔
342
        }
343
        $copyright = (array) $copyright;
2✔
344
        $copyrightLines = "\n";
2✔
345
        if ($copyright) {
2✔
346
            $copyrightLines .= "\n";
2✔
347
            foreach ($copyright as $cr) {
2✔
348
                $copyrightLines .= '(c) ' . $cr . "\n";
2✔
349
            }
350
        }
351
        $header = <<<EOF
2✔
352
            This file is part of {$packageName}.{$copyrightLines}
2✔
353
            For the full copyright and license information, please view the LICENSE
354
            file that was distributed with this source code.
355
            EOF;
2✔
356
        $this->setHeaderComment($header);
2✔
357
        return $this;
2✔
358
    }
359
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc