$ php -v):=> PHP 7.2.12 (cli) (built: Nov 9 2018 11:00:45) ( NTS )
$ php-cs-fixer -V):=> PHP CS Fixer 2.14.0 Sunrise by Fabien Potencier and Dariusz Ruminski
=> php vendor/bin/php-cs-fixer fix ./src
No custom configuration.
<?php
class C{
public function __construct(){
sprintf(
'%s',
'A',
'B'
);
}
}
<?php
class C
{
public function __construct()
{
sprintf(
'%s',
'A',
'B'
); // -> whoops?!
}
}
<?php
class C
{
public function __construct()
{
sprintf(
'%s',
'A',
'B'
);
}
}
_I think_ this is a priority case where BracesFixer needs to run before MethodArgumentSpace, or MethodArgumentSpace needs to be(come) aware of indentation level and indentation configuration.
I get a similar issue with just indention_type set. Reappling the fixer will keep decreasing the indent level until every line is indented at most once.
--- Original
+++ New
@@ @@
<?php
function foo() {
if (mt_rand() % 2) {
- return 1;
+ return 1;
}
return 100;
}
Test file:
<?php
function foo() {
if (mt_rand() % 2) {
return 1;
}
return 100;
}
Test config:
<?php
return PhpCsFixer\Config::create()
->setIndent(' ')
->setRules(['indentation_type' => true]);
Same behaviour in arrays
$foo = [
'bar' => [
'baz',
'qrz' => [
1,
2
]
]
];
After 1st fix:
$foo = [
'bar' => [
'baz',
'qrz' => [
1,
2
]
]
];
After 2nd fix:
$foo = [
'bar' => [
'baz',
'qrz' => [
1,
2
]
]
];
Configuration:
$finder = PhpCsFixer\Finder::create()
->exclude('vendor')
->notPath('*.phtml')
->in(__DIR__);
return PhpCsFixer\Config::create()
->setIndent(' ')
->setRules([
'indentation_type' => true,
])
->setFinder($finder);
This only happens if indentation is user-defined (not 4 spaces).
Probably caused by this line:
https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/2.14/src/Fixer/Whitespace/IndentationTypeFixer.php#L136
I have the same issue as #4282
The original code :
public function __construct(
UserPasswordEncoderInterface $userPasswordEncoder,
AccessTokenManager $accessTokenManager,
RefreshTokenManager $refreshTokenManager,
AuthorizationCodeManager $authorizationCodeManager
)
{
$this->userPasswordEncoder = $userPasswordEncoder;
$this->accessTokenManager = $accessTokenManager;
$this->refreshTokenManager = $refreshTokenManager;
$this->authorizationCodeManager = $authorizationCodeManager;
}
And PHP-CS-Fixer fix :
public function __construct(
UserPasswordEncoderInterface $userPasswordEncoder,
AccessTokenManager $accessTokenManager,
RefreshTokenManager $refreshTokenManager,
AuthorizationCodeManager $authorizationCodeManager
) {
$this->userPasswordEncoder = $userPasswordEncoder;
$this->accessTokenManager = $accessTokenManager;
$this->refreshTokenManager = $refreshTokenManager;
$this->authorizationCodeManager = $authorizationCodeManager;
}
Do you have any workaround to bypass this ?
Our CI/CD is broken because of this :(
Most helpful comment
_I think_ this is a priority case where
BracesFixerneeds to run beforeMethodArgumentSpace, orMethodArgumentSpaceneeds to be(come) aware of indentation level and indentation configuration.