|
| 1 | +<?php declare(strict_types=1); |
| 2 | + |
| 3 | +use PhpCsFixer\Config; |
| 4 | +use PhpCsFixer\Finder; |
| 5 | + |
| 6 | +$finder = Finder::create() |
| 7 | + ->exclude([ |
| 8 | + '.build/', |
| 9 | + '.github/', |
| 10 | + ]) |
| 11 | + ->in(__DIR__); |
| 12 | + |
| 13 | +$config = new Config(); |
| 14 | + |
| 15 | +$config->setFinder($finder); |
| 16 | +$config->setRules([ |
| 17 | + // Basic PER Coding Style 2.0 ruleset plus our overrides for it, see https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/doc/ruleSets/PER-CS2.0.rst |
| 18 | + '@PER-CS2.0' => true, // https://www.php-fig.org/per/coding-style/} |
| 19 | + 'new_with_parentheses' => ['anonymous_class' => true], // It will be changed in PHP-CS-Fixer v4.0 (but we want to enforce it), see https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/pull/8148 |
| 20 | + // overrides for PER-CS2.0 |
| 21 | + 'concat_space' => ['spacing' => 'none'], // make strings shorter "'hello' . $name . '!'" => "'hello'.$name.'!'" |
| 22 | + 'blank_line_after_opening_tag' => false, // it makes "<?php declare(strict_types=1);" multiline (and more verbose) |
| 23 | + |
| 24 | + // Additional rules on the top of PER-CS2 |
| 25 | + // Please keep these rules alphabetically |
| 26 | + 'align_multiline_comment' => ['comment_type' => 'phpdocs_only'], |
| 27 | + 'array_indentation' => true, |
| 28 | + 'assign_null_coalescing_to_coalesce_equal' => true, |
| 29 | + 'binary_operator_spaces' => ['default' => 'single_space'], |
| 30 | + 'cast_spaces' => ['space' => 'single'], |
| 31 | + 'class_attributes_separation' => ['elements' => ['method' => 'one']], |
| 32 | + 'declare_strict_types' => true, |
| 33 | + 'explicit_string_variable' => true, |
| 34 | + 'final_public_method_for_abstract_class' => true, |
| 35 | + 'general_phpdoc_annotation_remove' => [ |
| 36 | + 'annotations' => [ |
| 37 | + 'access', |
| 38 | + 'author', |
| 39 | + 'category', |
| 40 | + 'copyright', |
| 41 | + 'created', |
| 42 | + 'license', |
| 43 | + 'link', |
| 44 | + 'package', |
| 45 | + 'since', |
| 46 | + 'subpackage', |
| 47 | + ], |
| 48 | + ], |
| 49 | + 'modernize_types_casting' => true, |
| 50 | + 'mb_str_functions' => true, |
| 51 | + 'no_alias_functions' => true, |
| 52 | + 'no_binary_string' => true, |
| 53 | + 'no_empty_comment' => true, |
| 54 | + 'no_empty_phpdoc' => true, |
| 55 | + 'no_empty_statement' => true, |
| 56 | + 'no_extra_blank_lines' => ['tokens' => ['extra', 'curly_brace_block']], |
| 57 | + 'no_homoglyph_names' => true, |
| 58 | + 'no_leading_namespace_whitespace' => true, |
| 59 | + 'no_mixed_echo_print' => true, |
| 60 | + 'no_short_bool_cast' => true, |
| 61 | + 'no_singleline_whitespace_before_semicolons' => true, |
| 62 | + 'no_spaces_around_offset' => true, |
| 63 | + 'no_trailing_comma_in_singleline' => false, // it's a good marker that there are more elements in an array |
| 64 | + 'no_unneeded_braces' => true, |
| 65 | + 'no_unneeded_control_parentheses' => true, |
| 66 | + 'no_unneeded_final_method' => true, |
| 67 | + 'no_unreachable_default_argument_value' => true, |
| 68 | + 'no_unused_imports' => true, |
| 69 | + 'no_useless_concat_operator' => true, |
| 70 | + 'no_useless_return' => true, |
| 71 | + 'no_whitespace_before_comma_in_array' => true, |
| 72 | + 'normalize_index_brace' => true, |
| 73 | + 'nullable_type_declaration' => ['syntax' => 'question_mark'], |
| 74 | + 'object_operator_without_whitespace' => true, |
| 75 | + 'ordered_class_elements' => [ |
| 76 | + 'order' => [ |
| 77 | + 'use_trait', |
| 78 | + 'constant', |
| 79 | + 'case', // for enums only |
| 80 | + 'property', |
| 81 | + 'method', |
| 82 | + ] |
| 83 | + ], |
| 84 | + 'php_unit_attributes' => true, |
| 85 | + 'php_unit_construct' => true, |
| 86 | + 'php_unit_dedicate_assert' => ['target' => 'newest'], |
| 87 | + 'php_unit_expectation' => true, |
| 88 | + 'php_unit_fqcn_annotation' => true, |
| 89 | + 'php_unit_method_casing' => ['case' => 'snake_case'], |
| 90 | + 'php_unit_no_expectation_annotation' => true, |
| 91 | + 'php_unit_set_up_tear_down_visibility' => true, |
| 92 | + 'php_unit_strict' => true, |
| 93 | + 'php_unit_test_annotation' => ['style' => 'annotation'], |
| 94 | + 'phpdoc_align' => ['align' => 'left'], |
| 95 | + 'phpdoc_array_type' => true, |
| 96 | + 'phpdoc_indent' => true, |
| 97 | + 'phpdoc_line_span' => ['const' => 'single', 'property' => 'single', 'method' => 'single'], |
| 98 | + 'phpdoc_param_order' => true, |
| 99 | + 'phpdoc_scalar' => true, |
| 100 | + 'phpdoc_single_line_var_spacing' => true, |
| 101 | + 'phpdoc_tag_casing' => true, |
| 102 | + 'phpdoc_types' => true, |
| 103 | + 'protected_to_private' => true, |
| 104 | + 'psr_autoloading' => true, |
| 105 | + 'self_accessor' => true, |
| 106 | + 'self_static_accessor' => true, |
| 107 | + 'single_line_comment_spacing' => true, |
| 108 | + 'single_line_comment_style' => ['comment_types' => ['asterisk', 'hash']], |
| 109 | + 'space_after_semicolon' => true, |
| 110 | + 'standardize_not_equals' => true, |
| 111 | + 'strict_param' => true, |
| 112 | + 'ternary_to_null_coalescing' => true, |
| 113 | + 'trim_array_spaces' => true, |
| 114 | + 'trailing_comma_in_multiline' => true, |
| 115 | + 'type_declaration_spaces' => true, |
| 116 | + 'types_spaces' => ['space' => 'single'], |
| 117 | + 'whitespace_after_comma_in_array' => true, |
| 118 | + 'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false], |
| 119 | +]); |
| 120 | + |
| 121 | +return $config; |
0 commit comments