Skip to content

Instantly share code, notes, and snippets.

@nasrulhazim
Last active December 1, 2021 12:21
Show Gist options
  • Save nasrulhazim/574b65b80ef43a069ad0e91a87841aad to your computer and use it in GitHub Desktop.
Save nasrulhazim/574b65b80ef43a069ad0e91a87841aad to your computer and use it in GitHub Desktop.
PHP CS Fixer Config File
<?php
ini_set('memory_limit','1024M');
$finder = PhpCsFixer\Finder::create()
->notPath('bootstrap/cache')
->notPath('storage')
->notPath('vendor')
->notPath('node_modules')
->notPath('nova')
->in(__DIR__)
->name('*.php')
->notName('*.blade.php')
->ignoreDotFiles(true)
->ignoreVCS(true)
;
return PhpCsFixer\Config::create()
->setRules(array(
'@Symfony' => true,
'class_definition' => [
'multiLineExtendsEachSingleLine' => true,
],
'ordered_class_elements' => [
'use_trait', 'constant_public', 'constant_protected', 'constant_private',
'property_public', 'property_protected', 'property_private', 'construct',
'destruct', 'magic', 'phpunit', 'method_public', 'method_protected',
'method_private'
],
'binary_operator_spaces' => ['default' => 'align_single_space_minimal'],
'array_syntax' => ['syntax' => 'short'],
'concat_space' => ['spacing' => 'one'],
'blank_line_after_namespace' => true,
'linebreak_after_opening_tag' => true,
'not_operator_with_successor_space' => true,
'ordered_imports' => true,
'phpdoc_order' => true,
))
->setFinder($finder);
@nasrulhazim
Copy link
Author

Updating to latest version:

<?php
ini_set('memory_limit','1024M');
$finder = Symfony\Component\Finder\Finder::create()
    ->in([
        __DIR__ . '/app',
        __DIR__ . '/support',
        __DIR__ . '/config',
        __DIR__ . '/database',
        __DIR__ . '/routes',
        __DIR__ . '/tests',
    ])
    ->name('*.php')
    ->notName('*.blade.php')
    ->ignoreDotFiles(true)
    ->ignoreVCS(true);

return (new PhpCsFixer\Config())
    ->setRules([
        '@PSR12' => true,
        'array_syntax' => ['syntax' => 'short'],
        'ordered_imports' => ['sort_algorithm' => 'alpha'],
        'no_unused_imports' => true,
        'not_operator_with_successor_space' => true,
        'trailing_comma_in_multiline' => true,
        'phpdoc_scalar' => true,
        'unary_operator_spaces' => true,
        'binary_operator_spaces' => true,
        'blank_line_before_statement' => [
            'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
        ],
        'phpdoc_single_line_var_spacing' => true,
        'phpdoc_var_without_name' => true,
        'class_attributes_separation' => [
            'elements' => [
                'method' => 'one',
            ],
        ],
        'method_argument_space' => [
            'on_multiline' => 'ensure_fully_multiline',
            'keep_multiple_spaces_after_comma' => true,
        ],
        'single_trait_insert_per_statement' => true,
    ])
    ->setFinder($finder);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment