Created
May 17, 2024 11:52
-
-
Save WendellAdriel/8dbcd77a6c658e5b57727c1fdfd55292 to your computer and use it in GitHub Desktop.
Default PHP CS Fixer configuration for my projects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$finder = Symfony\Component\Finder\Finder::create() | |
->in([ | |
__DIR__ . '/src', | |
]) | |
->name('*.php') | |
->ignoreDotFiles(true) | |
->ignoreVCS(true); | |
return (new PhpCsFixer\Config()) | |
->setRules([ | |
'@PSR12' => true, | |
'array_indentation' => true, | |
'array_syntax' => ['syntax' => 'short'], | |
'array_push' => true, | |
'assign_null_coalescing_to_coalesce_equal' => true, | |
'binary_operator_spaces' => ['default' => 'single_space'], | |
'blank_line_after_namespace' => true, | |
'blank_line_after_opening_tag' => true, | |
'blank_line_between_import_groups' => true, | |
'blank_lines_before_namespace' => true, | |
'blank_line_before_statement' => [ | |
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'], | |
], | |
'braces_position' => [ | |
'control_structures_opening_brace' => 'same_line', | |
'functions_opening_brace' => 'next_line_unless_newline_at_signature_end', | |
'anonymous_functions_opening_brace' => 'same_line', | |
'classes_opening_brace' => 'next_line_unless_newline_at_signature_end', | |
'anonymous_classes_opening_brace' => 'next_line_unless_newline_at_signature_end', | |
'allow_single_line_empty_anonymous_classes' => false, | |
'allow_single_line_anonymous_functions' => false, | |
], | |
'cast_spaces' => true, | |
'class_attributes_separation' => [ | |
'elements' => [ | |
'const' => 'one', | |
'method' => 'one', | |
'property' => 'one', | |
'trait_import' => 'none', | |
], | |
], | |
'class_definition' => [ | |
'multi_line_extends_each_single_line' => true, | |
'single_item_single_line' => true, | |
'single_line' => true, | |
], | |
'clean_namespace' => true, | |
'combine_consecutive_issets' => true, | |
'combine_consecutive_unsets' => true, | |
'concat_space' => ['spacing' => 'one'], | |
'control_structure_braces' => true, | |
'control_structure_continuation_position' => ['position' => 'same_line'], | |
'declare_equal_normalize' => true, | |
'declare_parentheses' => true, | |
'declare_strict_types' => true, | |
'explicit_indirect_variable' => true, | |
'explicit_string_variable' => true, | |
'full_opening_tag' => true, | |
'fully_qualified_strict_types' => ['import_symbols' => true], | |
'global_namespace_import' => true, | |
'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'], | |
'method_chaining_indentation' => true, | |
'modernize_strpos' => true, | |
'modernize_types_casting' => true, | |
'new_with_braces' => true, | |
'no_blank_lines_after_class_opening' => true, | |
'no_blank_lines_after_phpdoc' => true, | |
'no_closing_tag' => true, | |
'no_empty_comment' => true, | |
'no_empty_phpdoc' => true, | |
'no_empty_statement' => true, | |
'no_extra_blank_lines' => [ | |
'tokens' => [ | |
'extra', | |
'throw', | |
'use', | |
], | |
], | |
'no_leading_import_slash' => true, | |
'no_leading_namespace_whitespace' => true, | |
'no_mixed_echo_print' => ['use' => 'echo'], | |
'no_multiline_whitespace_around_double_arrow' => true, | |
'no_multiple_statements_per_line' => true, | |
'no_short_bool_cast' => true, | |
'no_singleline_whitespace_before_semicolons' => true, | |
'no_space_around_double_colon' => true, | |
'no_spaces_after_function_name' => true, | |
'no_spaces_around_offset' => [ | |
'positions' => ['inside', 'outside'], | |
], | |
'no_superfluous_elseif' => true, | |
'no_superfluous_phpdoc_tags' => [ | |
'allow_mixed' => true, | |
'allow_unused_params' => true, | |
], | |
'no_trailing_comma_in_singleline' => true, | |
'no_trailing_whitespace' => true, | |
'no_trailing_whitespace_in_comment' => true, | |
'no_unneeded_import_alias' => true, | |
'no_unused_imports' => true, | |
'no_useless_else' => true, | |
'no_whitespace_before_comma_in_array' => true, | |
'no_whitespace_in_blank_line' => true, | |
'not_operator_with_successor_space' => true, | |
'nullable_type_declaration_for_default_null_value' => true, | |
'ordered_imports' => ['sort_algorithm' => 'alpha'], | |
'ordered_class_elements' => [ | |
'order' => [ | |
'use_trait', | |
'case', | |
'constant', | |
'constant_public', | |
'constant_protected', | |
'constant_private', | |
'property_public', | |
'property_protected', | |
'property_private', | |
'construct', | |
'destruct', | |
'magic', | |
'phpunit', | |
'method_abstract', | |
'method_public_static', | |
'method_public', | |
'method_protected_static', | |
'method_protected', | |
'method_private_static', | |
'method_private' | |
], | |
'sort_algorithm' => 'none', | |
], | |
'phpdoc_scalar' => true, | |
'phpdoc_no_useless_inheritdoc' => true, | |
'phpdoc_order' => [ | |
'order' => ['param', 'return', 'throws'], | |
], | |
'phpdoc_single_line_var_spacing' => true, | |
'phpdoc_trim' => true, | |
'phpdoc_var_without_name' => true, | |
'single_class_element_per_statement' => [ | |
'elements' => ['const', 'property'], | |
], | |
'single_import_per_statement' => true, | |
'single_line_after_imports' => true, | |
'single_quote' => true, | |
'single_trait_insert_per_statement' => true, | |
'strict_comparison' => true, | |
'ternary_operator_spaces' => true, | |
'ternary_to_null_coalescing' => true, | |
'trailing_comma_in_multiline' => true, | |
'trim_array_spaces' => true, | |
'unary_operator_spaces' => true, | |
'use_arrow_functions' => true, | |
'visibility_required' => true, | |
]) | |
->setFinder($finder); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment