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