Created
July 30, 2021 17:21
-
-
Save Truzze/4ad8f615ef419d4adbea95a4a6390b70 to your computer and use it in GitHub Desktop.
php-cs-fixer for laravel application
This file contains 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 | |
use PhpCsFixer\Config; | |
use PhpCsFixer\Finder; | |
$rules = [ | |
'@PSR12' => true, | |
'array_syntax' => ['syntax' => 'short'], | |
'no_multiline_whitespace_around_double_arrow' => true, | |
'no_trailing_comma_in_singleline_array' => true, | |
'no_whitespace_before_comma_in_array' => true, | |
'normalize_index_brace' => true, | |
'trim_array_spaces' => true, | |
'whitespace_after_comma_in_array' => true, | |
'braces' => [ | |
'position_after_functions_and_oop_constructs' => 'next', | |
], | |
'non_printable_character' => ['use_escape_sequences_in_strings' => true], | |
'constant_case' => ['case' => 'lower'], | |
'lowercase_keywords' => true, | |
'lowercase_static_reference' => true, | |
'magic_constant_casing' => true, | |
'magic_method_casing' => true, | |
'native_function_casing' => true, | |
'native_function_type_declaration_casing' => true, | |
'cast_spaces' => ['space' => 'single'], | |
'lowercase_cast' => true, | |
'modernize_types_casting' => true, | |
'no_short_bool_cast' => true, | |
'short_scalar_cast' => true, | |
'class_attributes_separation' => ['elements' => ['const' => 'one', 'method' => 'one', 'property' => 'one']], | |
'class_definition' => ['single_line' => true], | |
'no_blank_lines_after_class_opening' => true, | |
'no_null_property_initialization' => true, | |
'no_php4_constructor' => true, | |
'ordered_class_elements' => [ | |
'order' => ['use_trait', 'constant_public', 'constant_protected', 'constant_private', 'property_public', 'property_protected', 'property_private', 'construct', 'destruct', 'magic', 'phpunit', 'method_public', 'method_protected', 'method_private'], | |
'sort_algorithm' => 'none', | |
], | |
'self_accessor' => true, | |
'single_class_element_per_statement' => ['elements' => ['const', 'property']], | |
'single_trait_insert_per_statement' => true, | |
'visibility_required' => ['elements' => ['property', 'method', 'const']], | |
'multiline_comment_opening_closing' => true, | |
'no_empty_comment' => true, | |
'no_trailing_whitespace_in_comment' => true, | |
'single_line_comment_style' => ['comment_types' => ['asterisk', 'hash']], | |
'elseif' => true, | |
'include' => true, | |
'no_alternative_syntax' => true, | |
'no_break_comment' => ['comment_text' => 'no break'], | |
'no_superfluous_elseif' => true, | |
'no_trailing_comma_in_list_call' => true, | |
'no_unneeded_control_parentheses' => ['statements' => ['break', 'clone', 'continue', 'echo_print', 'return', 'switch_case', 'yield']], | |
'no_unneeded_curly_braces' => ['namespaces' => true], | |
'no_useless_else' => true, | |
'switch_case_semicolon_to_colon' => true, | |
'switch_case_space' => true, | |
'trailing_comma_in_multiline' => ['elements' => ['arrays']], | |
'function_declaration' => ['closure_function_spacing' => 'one'], | |
'function_typehint_space' => true, | |
'implode_call' => true, | |
'lambda_not_used_import' => true, | |
'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'], | |
'no_spaces_after_function_name' => true, | |
'no_unreachable_default_argument_value' => true, | |
'return_type_declaration' => ['space_before' => 'one'], | |
'void_return' => true, | |
'fully_qualified_strict_types' => true, | |
'no_unused_imports' => true, | |
'ordered_imports' => ['sort_algorithm' => 'alpha'], | |
'single_import_per_statement' => true, | |
'single_line_after_imports' => true, | |
'combine_consecutive_issets' => true, | |
'combine_consecutive_unsets' => true, | |
'declare_equal_normalize' => ['space' => 'single'], | |
'explicit_indirect_variable' => true, | |
'single_space_after_construct' => ['constructs' => ['abstract', 'as', 'attribute', 'break', 'case', 'catch', 'class', 'clone', 'comment', 'const', 'const_import', 'continue', 'do', 'echo', 'else', 'elseif', 'extends', 'final', 'finally', 'for', 'foreach', 'function', 'function_import', 'global', 'goto', 'if', 'implements', 'include', 'include_once', 'instanceof', 'insteadof', 'interface', 'match', 'named_argument', 'new', 'open_tag_with_echo', 'php_doc', 'php_open', 'print', 'private', 'protected', 'public', 'require', 'require_once', 'return', 'static', 'throw', 'trait', 'try', 'use', 'use_lambda', 'use_trait', 'var', 'while', 'yield', 'yield_from']], | |
'blank_line_after_namespace' => true, | |
'clean_namespace' => true, | |
'no_leading_namespace_whitespace' => true, | |
'single_blank_line_before_namespace' => true, | |
'binary_operator_spaces' => ['default' => 'single_space'], | |
'concat_space' => ['spacing' => 'one'], | |
'new_with_braces' => true, | |
'object_operator_without_whitespace' => true, | |
'operator_linebreak' => ['position' => 'beginning'], | |
'standardize_not_equals' => true, | |
'ternary_operator_spaces' => true, | |
'ternary_to_null_coalescing' => true, | |
'unary_operator_spaces' => true, | |
'blank_line_after_opening_tag' => true, | |
'full_opening_tag' => true, | |
'no_closing_tag' => true, | |
'no_useless_return' => true, | |
'return_assignment' => true, | |
'multiline_whitespace_before_semicolons' => ['strategy' => 'no_multi_line'], | |
'no_empty_statement' => true, | |
'no_singleline_whitespace_before_semicolons' => true, | |
'semicolon_after_instruction' => true, | |
'simple_to_complex_string_variable' => true, | |
'single_quote' => ['strings_containing_single_quote_chars' => false], | |
'array_indentation' => true, | |
'blank_line_before_statement' => ['statements' => ['case', 'continue', 'declare', 'default', 'do', 'for', 'foreach', 'if', 'return', 'switch', 'throw', 'try', 'while', 'yield']], | |
'compact_nullable_typehint' => true, | |
'indentation_type' => true, | |
'line_ending' => true, | |
'method_chaining_indentation' => true, | |
'no_extra_blank_lines' => ['tokens' => ['break', 'case', 'continue', 'curly_brace_block', 'default', 'extra', 'parenthesis_brace_block', 'return', 'square_brace_block', 'throw']], | |
'no_spaces_around_offset' => ['positions' => ['inside', 'outside']], | |
'no_spaces_inside_parenthesis' => true, | |
'no_trailing_whitespace' => true, | |
'no_whitespace_in_blank_line' => true, | |
'single_blank_line_at_eof' => true, | |
]; | |
$project_path = dirname(__FILE__); | |
$finder = Finder::create() | |
->in([ | |
$project_path . '/app', | |
$project_path . '/config', | |
$project_path . '/database', | |
$project_path . '/resources', | |
$project_path . '/routes', | |
$project_path . '/tests', | |
]) | |
->name('*.php') | |
->notName('*.blade.php') | |
->ignoreDotFiles(true) | |
->ignoreVCS(true); | |
return (new Config()) | |
->setFinder($finder) | |
->setRules($rules) | |
->setRiskyAllowed(true) | |
->setUsingCache(true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment