Php-cs-fixer: indentation_type unexpected indentation

Created on 22 Jun 2018  路  3Comments  路  Source: FriendsOfPHP/PHP-CS-Fixer

The PHP version you are using ($ php -v):

=>7.1.11

PHP CS Fixer version you are using ($ php-cs-fixer -V):

=> 2.12.1

The command you use to run PHP CS Fixer:

=> Using Sublime text (3.1.1) plugin php cs fixer
=> Also tried in visual studio code (1.24.1)

The configuration file you are using, if any:

return PhpCsFixer\Config::create()
    ->setRules(array(
        '@PSR2' => true,
        'method_argument_space' => array('on_multiline' =>'ignore','keep_multiple_spaces_after_comma' => false),
    ))
    ->setIndent("  ")
    ->setLineEnding("\n")
    ->setUsingCache(false)
    ->setCacheFile(__DIR__.'\php_cs.cache')
;

same if i set on_multiline='ensure_fully_multiline'

If applicable, please provide minimum samples of PHP code (as plain text, not screenshots):

  • before running PHP CS Fixer (no changes):
if (true) {
  if (true) {
    (new stdClass())->asdf(
      'text',
      'text2'
    );
  }
}

  • with unexpected changes applied when running PHP CS Fixer:
if (true) {
  if (true) {
    (new stdClass())->asdf(
    'text',
    'text2'
  );
  }
}

if i run PHP CS Fixer again

if (true) {
  if (true) {
    (new stdClass())->asdf(
  'text',
  'text2'
  );
  }
}
  • with the changes you expected instead:
    No changes
kinbug

Most helpful comment

Same here. Ths produces problems with arguments on multiple lines.

This seems to work as workaround:

return PhpCsFixer\Config::create()
    ->setUsingCache(false)
    ->setRules([
        '@PSR1' => true,
        '@PSR2' => true,
        'indentation_type' => false
    ])
    ->setIndent("  ")
    ->setFinder($finder)
;

Running this multiple times changes it again.

All 3 comments

Same here. Ths produces problems with arguments on multiple lines.

This seems to work as workaround:

return PhpCsFixer\Config::create()
    ->setUsingCache(false)
    ->setRules([
        '@PSR1' => true,
        '@PSR2' => true,
        'indentation_type' => false
    ])
    ->setIndent("  ")
    ->setFinder($finder)
;

Running this multiple times changes it again.

Getting the same problems using 2.15.1 with 'php cs fixer' extension for VS Code.

It is not even idempotent, each time you format the same file it changes as multi-line arrays and function call arguments march left by 2 spaces each time like @amitbisht511's example.

.\php-cs-fixer.phar -V
PHP CS Fixer 2.15.1 Europe Round by Fabien Potencier and Dariusz Ruminski (2006451)

should be fixed by https://github.com/FriendsOfPHP/PHP-CS-Fixer/pull/4183 , please let us know if there is still an issue :+1:

Was this page helpful?
0 / 5 - 0 ratings