A set of custom fixers for PHP CS Fixer .
Note
This is in active development. New fixers will be introduced gradually.
Indents each chained methods.
- Foo::bar()->baz()->qux()->quux()->corge();
+ Foo::bar()
+ ->baz()
+ ->qux()
+ ->quux()
+ ->corge();
Tip
single-line
: Set chains on single line {true|false}
multi-line
: Set chains on next line if {number}
chains
Adds a given number of lines after imports.
- use Baz;
- class Qux {}
+ use Baz;
+
+
+ class Qux {}
Tip
lines
: Set {number}
blank lines after the use statements block
Adds spaces inside squared braces.
- $foo = ["bar", "baz", "qux"];
+ $foo = [ "bar", "baz", "qux" ];
Tip
space
: Set space inside parentheses {single|none}
.
- Install dependency
composer require --dev capsulescodes/php-cs-fixer-custom-fixers
- Using
.php-cs-fixer.php
config file by PHP CS Fixer
<?php
use PhpCsFixer\Config;
return ( new PhpCsFixer\Config() )
...
->registerCustomFixers( [
...
new \CapsulesCodes\PhpCsFixerCustomFixers\Fixers()
...
or
...
new \CapsulesCodes\PhpCsFixerCustomFixers\MethodChainingIndentationFixer(),
new \CapsulesCodes\PhpCsFixerCustomFixers\MultipleLinesAfterImportsFixer(),
new \CapsulesCodes\PhpCsFixerCustomFixers\SpacesInsideSquareBracesFixer()
...
] )
->setRules( [
...
"CapsulesCodes/method_chaining_indentation" : { "multi-line" : 4 },
"CapsulesCodes/multiple_lines_after_imports" : { "lines" : 2 },
"CapsulesCodes/spaces_inside_square_braces" : { "space" : "single" }
...
] )
;
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate.