Skip to content

Instantly share code, notes, and snippets.

@macghriogair
Created December 16, 2021 13:36
Show Gist options
  • Save macghriogair/fb2ddb3d2ec26c2e802d2c8774d5c718 to your computer and use it in GitHub Desktop.
Save macghriogair/fb2ddb3d2ec26c2e802d2c8774d5c718 to your computer and use it in GitHub Desktop.
[PHP-CS-Fixer Config] #phpcs #php #codestyle
<?php
use PhpCsFixer\Finder;
use PhpCsFixer\Config;
$finder = Finder::create()
->in([
__DIR__ . '/',
])
->ignoreDotFiles(true)
->ignoreVCS(true)
->ignoreVCSIgnored(false)
->exclude([
])
->files()
// do not fix views
->notName('*.html.php')
->notName('*.blade.php')
// do not fix example files
->notName('*.example.php')
;
// do not enable self_accessor as it breaks pimcore models relying on get_called_class()
$config = new PhpCsFixer\Config();
$config
->setRiskyAllowed(true)
->setRules([
'@PSR1' => true,
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
// keep aligned = and => operators as they are: do not force aligning, but do not remove it
'binary_operator_spaces' => [
'default' => 'single_space',
//'align_equals' => null,
//'default' => 'single_space'
],
'blank_line_before_statement' => ['statements' => ['return']],
'encoding' => true,
'single_line_comment_style' => ['comment_types' => ['hash']],
'lowercase_cast' => true,
'magic_constant_casing' => true,
// 'method_argument_space' => [],
'phpdoc_separation' => true,
'native_function_casing' => true,
'no_blank_lines_after_class_opening' => true,
'no_blank_lines_after_phpdoc' => true,
'no_empty_comment' => true,
'no_empty_phpdoc' => true,
'no_extra_blank_lines' => true,
'no_short_bool_cast' => true,
'no_spaces_around_offset' => true,
'no_unneeded_control_parentheses' => true,
'no_unused_imports' => true,
'no_whitespace_before_comma_in_array' => true,
'object_operator_without_whitespace' => true,
'ordered_imports' => true,
'phpdoc_indent' => true,
'phpdoc_no_useless_inheritdoc' => true,
'phpdoc_scalar' => true,
'phpdoc_separation' => true,
'phpdoc_single_line_var_spacing' => true,
'no_superfluous_phpdoc_tags' => true,
'short_scalar_cast' => true,
'single_blank_line_before_namespace' => true,
'single_quote' => true,
'space_after_semicolon' => true,
'standardize_not_equals' => true,
'ternary_operator_spaces' => true,
'whitespace_after_comma_in_array' => true,
'general_phpdoc_annotation_remove' => ['annotations' => ["author", "package"]],
// Provisional PSR-12 ruleset, cf. https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/4502#issuecomment-570408101
'blank_line_after_opening_tag' => false,
'compact_nullable_typehint' => true,
'declare_equal_normalize' => ['space' => 'single'],
'function_typehint_space' => true,
'new_with_braces' => true,
'no_empty_statement' => true,
'no_leading_import_slash' => true,
'no_leading_namespace_whitespace' => true,
'no_whitespace_in_blank_line' => true,
'return_type_declaration' => ['space_before' => 'none'],
'single_trait_insert_per_statement' => true,
'trailing_comma_in_multiline' => true,
// FOO
'braces' => [
'allow_single_line_closure' => true,
'position_after_functions_and_oop_constructs' => 'same'],
// risky fixers:
//'declare_strict_types' => true,
'modernize_strpos' => true,
'general_phpdoc_annotation_remove' => ['annotations' => ['expectedDeprecation']],
'heredoc_indentation' => false,
'@PHP81Migration' => true,
'@PHP80Migration:risky' => true,
])
->setFinder($finder);
return $config;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment