|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Configuration file for https://github.com/FriendsOfPHP/PHP-CS-Fixer |
| 4 | + * Install with composer: $ composer global require friendsofphp/php-cs-fixer |
| 5 | + * Usage (in this directory) : ~/.composer/vendor/bin/php-cs-fixer fix . |
| 6 | + */ |
| 7 | + |
| 8 | +$finder = PhpCsFixer\Finder::create() |
| 9 | + ->exclude('vendor') |
| 10 | + ->in(__DIR__) |
| 11 | + ->name('*.php') |
| 12 | + ->ignoreDotFiles(true) |
| 13 | + ->ignoreVCS(true); |
| 14 | + |
| 15 | +$config = new PhpCsFixer\Config(); |
| 16 | +return $config |
| 17 | + ->setIndent("\t") |
| 18 | + ->setLineEnding("\r\n") |
| 19 | + ->setRules([ |
| 20 | +// '@PSR2' => true, |
| 21 | + |
| 22 | + // Array. |
| 23 | + 'array_syntax' => ['syntax' => 'long'], |
| 24 | + |
| 25 | + // Basic. |
| 26 | + 'braces' => [ |
| 27 | + 'allow_single_line_closure' => true, |
| 28 | + 'position_after_anonymous_constructs' => 'same', |
| 29 | + 'position_after_functions_and_oop_constructs' => 'same' |
| 30 | + ], |
| 31 | + |
| 32 | + // Casing. |
| 33 | + // 'class_reference_name_casing' => true, |
| 34 | + 'constant_case' => ['case' => 'lower'], |
| 35 | + |
| 36 | + // Cast Notation. |
| 37 | + 'cast_spaces' => true, |
| 38 | + 'lowercase_cast' => true, |
| 39 | + 'no_short_bool_cast' => true, |
| 40 | + 'short_scalar_cast' => true, |
| 41 | + |
| 42 | + // Class Notation. |
| 43 | + //'class_attributes_separation' => true, |
| 44 | + 'class_definition' => true, |
| 45 | + 'no_blank_lines_after_class_opening' => true, |
| 46 | + //'no_null_property_initialization' => true, |
| 47 | + 'no_php4_constructor' => true, |
| 48 | + 'ordered_class_elements' => true, |
| 49 | + 'ordered_traits' => true, |
| 50 | + 'self_accessor' => true, |
| 51 | + 'single_class_element_per_statement' => true, |
| 52 | + 'single_trait_insert_per_statement' => true, |
| 53 | + 'visibility_required' => true, |
| 54 | + |
| 55 | + // Comment. |
| 56 | + //'multiline_comment_opening_closing' => true, |
| 57 | + 'no_empty_comment' => true, |
| 58 | + 'no_trailing_whitespace_in_comment' => true, |
| 59 | + // 'single_line_comment_spacing' => true, |
| 60 | + 'single_line_comment_style' => true, |
| 61 | + |
| 62 | + // Control Structure |
| 63 | + // 'control_structure_braces' => true, |
| 64 | + 'control_structure_continuation_position' => true, |
| 65 | + 'elseif' => true, |
| 66 | + 'include' => true, |
| 67 | + 'no_alternative_syntax' => true, |
| 68 | + 'no_superfluous_elseif' => true, |
| 69 | + 'no_unneeded_control_parentheses' => true, |
| 70 | + 'no_useless_else' => true, |
| 71 | + 'switch_case_semicolon_to_colon' => true, |
| 72 | + 'switch_case_space' => true, |
| 73 | + 'switch_continue_to_break' => true, |
| 74 | + 'trailing_comma_in_multiline' => true, |
| 75 | + 'yoda_style' => true, |
| 76 | + |
| 77 | + // Function Notation |
| 78 | + 'combine_nested_dirname' => true, |
| 79 | + 'function_typehint_space' => true, |
| 80 | + 'implode_call' => true, |
| 81 | + 'lambda_not_used_import' => true, |
| 82 | + 'native_function_invocation' => true, |
| 83 | + 'no_spaces_after_function_name' => true, |
| 84 | + // 'no_trailing_comma_in_singleline_function_call' => true, |
| 85 | + 'no_unreachable_default_argument_value' => true, |
| 86 | + 'nullable_type_declaration_for_default_null_value' => true, |
| 87 | + 'return_type_declaration' => true, |
| 88 | + //'single_line_throw' => true, |
| 89 | + 'void_return' => true, |
| 90 | + |
| 91 | + // Import |
| 92 | + 'fully_qualified_strict_types' => true, |
| 93 | + 'global_namespace_import' => true, |
| 94 | + 'no_leading_import_slash' => true, |
| 95 | + 'no_unused_imports' => true, |
| 96 | + 'ordered_imports' => true, |
| 97 | + 'single_import_per_statement' => true, |
| 98 | + 'single_line_after_imports' => true, |
| 99 | + |
| 100 | + // Language Construct |
| 101 | + //'combine_consecutive_issets' => true, |
| 102 | + //'combine_consecutive_unsets' => true, |
| 103 | + 'function_to_constant' => true, |
| 104 | + |
| 105 | + // Namespace Notation |
| 106 | + 'blank_line_after_namespace' => true, |
| 107 | + 'clean_namespace' => true, |
| 108 | + 'no_leading_namespace_whitespace' => true, |
| 109 | + 'single_blank_line_before_namespace' => true, |
| 110 | + |
| 111 | + // Operator |
| 112 | + 'concat_space' => ['spacing' => 'one'], |
| 113 | + 'increment_style' => ['style' => 'post'], |
| 114 | + 'logical_operators' => true, |
| 115 | + 'new_with_braces' => true, |
| 116 | + 'no_space_around_double_colon' => true, |
| 117 | + 'not_operator_with_space' => true, |
| 118 | + 'object_operator_without_whitespace' => true, |
| 119 | + 'standardize_increment' => true, |
| 120 | + 'standardize_not_equals' => true, |
| 121 | + 'ternary_operator_spaces' => true, |
| 122 | + 'ternary_to_null_coalescing' => true, |
| 123 | + 'binary_operator_spaces' => ['default' => 'align_single_space'], |
| 124 | + |
| 125 | + // PHP Tag |
| 126 | + 'echo_tag_syntax' => true, |
| 127 | + //'linebreak_after_opening_tag' => true, |
| 128 | + 'no_closing_tag' => true, |
| 129 | + |
| 130 | + // PHPUnit |
| 131 | + 'php_unit_fqcn_annotation' => true, |
| 132 | + 'php_unit_method_casing' => ['case' => 'snake_case'], |
| 133 | + 'php_unit_test_annotation' => true, |
| 134 | + 'php_unit_test_class_requires_covers' => true, |
| 135 | + 'php_unit_internal_class' => true, |
| 136 | + 'php_unit_construct' => true, |
| 137 | + |
| 138 | + // PHPDoc |
| 139 | + 'align_multiline_comment' => true, |
| 140 | + 'general_phpdoc_annotation_remove' => true, |
| 141 | + 'no_empty_phpdoc' => true, |
| 142 | + 'phpdoc_add_missing_param_annotation' => true, |
| 143 | + 'phpdoc_align' => true, |
| 144 | + 'phpdoc_indent' => true, |
| 145 | + 'phpdoc_line_span' => true, |
| 146 | + 'phpdoc_no_access' => true, |
| 147 | + 'phpdoc_no_alias_tag' => true, |
| 148 | + 'phpdoc_no_package' => true, |
| 149 | + 'phpdoc_order_by_value' => true, |
| 150 | + 'phpdoc_order' => true, |
| 151 | + 'phpdoc_return_self_reference' => true, |
| 152 | + 'phpdoc_scalar' => true, |
| 153 | + 'phpdoc_separation' => true, |
| 154 | + 'phpdoc_summary' => true, |
| 155 | + 'phpdoc_tag_casing' => true, |
| 156 | + 'phpdoc_tag_type' => true, |
| 157 | + 'phpdoc_to_comment' => true, |
| 158 | + 'phpdoc_trim_consecutive_blank_line_separation' => true, |
| 159 | + 'phpdoc_trim' => true, |
| 160 | + 'phpdoc_types' => true, |
| 161 | + 'phpdoc_types_order' => true, |
| 162 | + 'phpdoc_var_annotation_correct_order' => true, |
| 163 | + 'phpdoc_var_without_name' => true, |
| 164 | + |
| 165 | + // Return Notation. |
| 166 | + 'no_useless_return' => true, |
| 167 | + 'return_assignment' => true, |
| 168 | + |
| 169 | + // Semicolon. |
| 170 | + 'multiline_whitespace_before_semicolons' => true, |
| 171 | + 'no_singleline_whitespace_before_semicolons' => true, |
| 172 | + 'semicolon_after_instruction' => true, |
| 173 | + 'space_after_semicolon' => true, |
| 174 | + |
| 175 | + // Strict. |
| 176 | + //'declare_strict_types' => true, |
| 177 | + //'strict_comparison' => true, |
| 178 | + 'strict_param' => true, |
| 179 | + |
| 180 | + // Whitespace. |
| 181 | + 'array_indentation' => true, |
| 182 | + 'blank_line_before_statement' => true, |
| 183 | + // 'blank_line_between_import_groups' => true, |
| 184 | + 'compact_nullable_typehint' => true, |
| 185 | + 'indentation_type' => true, |
| 186 | + 'line_ending' => true, |
| 187 | + 'method_chaining_indentation' => true, |
| 188 | + //'no_spaces_around_offset' => true, // conflict with wp. |
| 189 | + //'no_spaces_inside_parenthesis' => true, // conflict with wp. |
| 190 | + 'no_trailing_whitespace' => true, |
| 191 | + //'no_whitespace_in_blank_line' => true, |
| 192 | + 'single_blank_line_at_eof' => true, |
| 193 | + // 'statement_indentation' => true, |
| 194 | + //'types_spaces' => true, |
| 195 | + |
| 196 | + ]) |
| 197 | + ->setUsingCache(false) |
| 198 | + ->setRiskyAllowed(true) |
| 199 | + ->setFinder($finder); |
0 commit comments