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

aplus-framework / coding-standard / 16396142624

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

push

github

natanfelles
Show image in user guide

301 of 301 relevant lines covered (100.0%)

2.86 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);
3✔
22
        $this->setRiskyAllowed(true);
3✔
23
        $this->setIndent('    ');
3✔
24
        $this->setLineEnding("\n");
3✔
25
        $this->setCacheFile('.php-cs-fixer.cache');
3✔
26
        $this->prepareRules();
3✔
27
    }
28

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

319
    public function setHeaderComment(string $header) : static
320
    {
321
        $this->replaceRules([
2✔
322
            'header_comment' => [
2✔
323
                'comment_type' => 'comment',
2✔
324
                'header' => $header,
2✔
325
                'location' => 'after_declare_strict',
2✔
326
                'separate' => 'none',
2✔
327
            ],
2✔
328
        ]);
2✔
329
        return $this;
2✔
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 === '') {
1✔
341
            $copyright = [];
1✔
342
        }
343
        $copyright = (array) $copyright;
1✔
344
        $copyrightLines = "\n";
1✔
345
        if ($copyright) {
1✔
346
            $copyrightLines .= "\n";
1✔
347
            foreach ($copyright as $cr) {
1✔
348
                $copyrightLines .= '(c) ' . $cr . "\n";
1✔
349
            }
350
        }
351
        $header = <<<EOF
1✔
352
            This file is part of {$packageName}.{$copyrightLines}
1✔
353
            For the full copyright and license information, please view the LICENSE
354
            file that was distributed with this source code.
355
            EOF;
1✔
356
        $this->setHeaderComment($header);
1✔
357
        return $this;
1✔
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