$ php -v):PHP 7.1.19 (cli) (built: Jul 11 2018 11:45:03) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans
$ php-cs-fixer -V):PHP CS Fixer 2.12.2 Long Journey by Fabien Potencier and Dariusz Ruminski
./vendor/bin/php-cs-fixer fix --dry-run --config=.php_cs -v -- a.php b.php
<?php
$finder = \PhpCsFixer\Finder::create()
->in([__DIR__]);
$config = (new \PhpCsFixer\Config('MyConfig'))
->setRiskyAllowed(false)
->setRules([
'@PSR2' => true,
//Our line endings (LF) are handled by git.
'line_ending' => false
])
->setCacheFile('.php_cs.cache')
->setFinder($finder)
->setFormat('txt')
->setHideProgress(false)
->setIndent(' ')
->setLineEnding("\n")
->setPhpExecutable(null)
->setUsingCache(true)
;
return $config;
a.php:
<?php
class A {};
b.php:
<?php
class B{};
Some errors should be fixed and finished normally.
Loaded config MyConfig from ".php_cs".
Using cache file ".php_cs.cache".
Paths from configuration file have been overridden by paths provided as command arguments.
FF
Legend: ?-unknown, I-invalid file syntax, file ignored, S-Skipped, .-no changes, F-fixed, E-error
1) a.php (class_definition, braces)
2) b.php (class_definition, braces)
Checked all files in 0.018 seconds, 10.000 MB memory used
An unexpected option --ansi is appended to the command line. It is regarded as one of the paths given and causes abort.
Loaded config MyConfig from ".php_cs".
Using cache file ".php_cs.cache".
In ConfigurationResolver.php line 384:
[PhpCsFixer\ConfigurationException\InvalidConfigurationException (16)]
The path "--ansi" is not readable.
Exception trace:
PhpCsFixer\Console\ConfigurationResolver::PhpCsFixer\Console\{closure}() at n/a:n/a
array_map() at /private/tmp/test-cs-fix/vendor/friendsofphp/php-cs-fixer/src/Console/ConfigurationResolver.php:392
PhpCsFixer\Console\ConfigurationResolver->getPath() at /private/tmp/test-cs-fix/vendor/friendsofphp/php-cs-fixer/src/Console/ConfigurationResolver.php:808
PhpCsFixer\Console\ConfigurationResolver->resolveFinder() at /private/tmp/test-cs-fix/vendor/friendsofphp/php-cs-fixer/src/Console/ConfigurationResolver.php:514
PhpCsFixer\Console\ConfigurationResolver->getFinder() at /private/tmp/test-cs-fix/vendor/friendsofphp/php-cs-fixer/src/Console/Command/FixCommand.php:183
PhpCsFixer\Console\Command\FixCommand->execute() at /private/tmp/test-cs-fix/vendor/symfony/console/Command/Command.php:251
Symfony\Component\Console\Command\Command->run() at /private/tmp/test-cs-fix/vendor/symfony/console/Application.php:886
Symfony\Component\Console\Application->doRunCommand() at /private/tmp/test-cs-fix/vendor/symfony/console/Application.php:262
Symfony\Component\Console\Application->doRun() at /private/tmp/test-cs-fix/vendor/friendsofphp/php-cs-fixer/src/Console/Application.php:84
PhpCsFixer\Console\Application->doRun() at /private/tmp/test-cs-fix/vendor/symfony/console/Application.php:145
Symfony\Component\Console\Application->run() at /private/tmp/test-cs-fix/vendor/friendsofphp/php-cs-fixer/php-cs-fixer:76
fix [--path-mode PATH-MODE] [--allow-risky ALLOW-RISKY] [--config CONFIG] [--dry-run] [--rules RULES] [--using-cache USING-CACHE] [--cache-file CACHE-FILE] [--diff] [--diff-format DIFF-FORMAT] [--format FORMAT] [--stop-on-violation] [--show-progress SHOW-PROGRESS] [--] [<path>...]
I believe this is due to: https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/v2.12.2/php-cs-fixer#L71
Hi and thanks for report,
After looking around the XdebugHandler seems to do the following;
original command
$ php php-cs-fixer fix --dry-run -vvv --config .php_cs.dist -- src/Differ/ src/WordMatcher.php
new command
'/usr/bin/php7.2' '-c' '/tmp/0jDX63' 'php-cs-fixer' 'fix' '--dry-run' '-vvv' '--config' '.php_cs.dist' '--' 'src/Differ/' 'src/WordMatcher.php' '--ansi'
so indeed, the handler causes this issue.
May I ask why you add the -- before the list of files/directories you want to fix?
If this is a standard maybe the XdebugHandler needs to be changed so it inserts the --ansi flag at a better location.
@SpacePossum
Thanks for the quick review.
May I ask why you add the -- before the list of files/directories you want to fix?
Yes. That's just because the usage tells so:
$ ./vendor/bin/php-cs-fixer help fix | head -n 8
Description:
Fixes a directory or a file.
Usage:
fix [options] [--] [<path>...]
Arguments:
path The path.
If this is a standard maybe the XdebugHandler needs to be changed so it inserts the --ansi flag at a better location.
Well, it looks commonly used for well-known commands (e.g. grep) and it could be POSIX convention, but I have no idea where the standard document is and what it actually says.
Maybe I should report this issue to XdebugHandler.
@SpacePossum
Looks like the --ansi parameter should NOT be passed to the handler when variadic paths are given, according to the readme of XdebugHandler:
$colorOption
Do not use this parameter if the input handler cannot cope with an option as the last argument.
Thanks for the explanations, good reads as well :)
Than I agree this is a bug in the fixer, we shouldn't pass the --ansi flag.
If we don't want to drop the colors in the output for users running with XDebug we can take the long route and see if can change the XdebugHandler itself. Maybe for a first fix we drop the flag and in the meantime we check over @ the XdebugHandler repo to see what can be done there?
shall be fix on xdebug-handler level indeed
https://github.com/composer/xdebug-handler/pull/69
https://github.com/composer/xdebug-handler/pull/69 has been release as 1.2.0
Most helpful comment
https://github.com/composer/xdebug-handler/pull/69 has been release as 1.2.0