Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.
like image 735
Joyce Babu Avatar asked Mar 17 '17 04:03

Joyce Babu


2 Answers

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)
like image 89
Joyce Babu Avatar answered Nov 10 '22 08:11

Joyce Babu


First create .php_cs file in your project root directory. Then add the below lines to .php_cs file

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

Then run the below command to fix the issue

vendor/bin/php-cs-fixer fix . --config .php_cs
like image 2
Aryashree Pritikrishna Avatar answered Nov 10 '22 10:11

Aryashree Pritikrishna