Skip to content

capsulescodes/php-cs-fixer-custom-fixers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

A set of custom fixers for PHP CS Fixer .

Note

This is in active development. New fixers will be introduced gradually.


Fixers


MethodChainingIndentationFixer

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


MultipleLinesAfterImportsFixer

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


SpacesInsideSquareBracesFixer :

Adds spaces inside squared braces.

- $foo = ["bar", "baz", "qux"];

+ $foo = [ "bar", "baz", "qux" ];

Tip

space : Set space inside parentheses {single|none}.





Installation

  1. Install dependency
composer require --dev capsulescodes/php-cs-fixer-custom-fixers

Usage

<?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" }
        ...

   ] )
;



Contributing

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.

Credits

Capsules Codes

License

MIT