phpatom-editorphpcs

Configure PHP-cs-fixer indentation for 2 spaces rather than 4?


Not sure if this a better question for here or SuperUser. If it belongs there feel free to move it.

I'm using php-cs-fixer, and I have a unique requirement on indentations - I need two spaces rather than four. Is there a way to change this setting?

Note that I'm using atom-beautifier to run php-cs-fixer, so any solution should ideally be workable from there.


Solution

  • You can set the PHP-CS-Fixer config file path and set the setIndent() value as defined at PHP-CS-Fixer's documentation website.

    See image for Atom package settings

    Set the .php_cs with something like this. Note the ->setIndent(" ") with two spaces instead of a \t character.

    <?php
    
    /*
     * This file is part of PHP CS Fixer.
     * (c) Fabien Potencier <fabien@symfony.com>
     *     Dariusz Rumiński <dariusz.ruminski@gmail.com>
     * This source file is subject to the MIT license that is bundled
     * with this source code in the file LICENSE.
     */
    
    $header = <<<'EOF'
    This file is part of PHP CS Fixer.
    (c) Fabien Potencier <fabien@symfony.com>
        Dariusz Rumiński <dariusz.ruminski@gmail.com>
    This source file is subject to the MIT license that is bundled
    with this source code in the file LICENSE.
    EOF;
    
    return PhpCsFixer\Config::create()
      /* ... other settings */
      ->setIndent("  ")
      /* ... other settings */
    

    I am using php-cs-fixer plugin version 4.1.0 here.