Search code examples
phpphp-cs-fixer

Use tab for indentation in PHP-CS-Fixer


How can I configure PHP-CS-Fixer to use tab for indentation?

I can see the indentation_type fixer

* indentation_type [@PSR2, @Symfony]
  | Code MUST use configured indentation type.

But how do I configure the indentation type? If I try to set 'indentation_type' => 'tab',, I am getting the error

[indentation_type] Is not configurable.

Solution

  • It was there in the documentation, and some how I missed it (probably because I was searching for the term 'tab' instead of 'indentation')

    For anyone else looking for the same, there is a setIndent method in PhpCsFixer\Config.

    return PhpCsFixer\Config::create()
        ->setRules([
            '@PSR2' => true,
            'indentation_type' => true,
        ])
        ->setIndent("\t")
        ->setLineEnding("\n")
        ->setFinder($finder)