Hello,
I have problem automatically fixing the files using the Magento Code Standard.
The command I use:
vendor/bin/phpcbf -p -n --colors --extensions=php/php --standard=dev/tests/static/framework/Magento app/code/Qsl
An example output of phpcs:
[1mFILE: anonymized.php[0m
--------------------------------------------------------------------------------------------------------------------------
[1mFOUND 9 ERRORS AFFECTING 9 LINES[0m
--------------------------------------------------------------------------------------------------------------------------
13 | [31mERROR[0m | [x] Short description must start with a capital letter
19 | [31mERROR[0m | [x] Missing short description
20 | [31mERROR[0m | [x] There must be exactly one blank line before tags
26 | [31mERROR[0m | [x] Missing short description
27 | [31mERROR[0m | [x] There must be exactly one blank line before tags
31 | [31mERROR[0m | [x] Missing short description
32 | [31mERROR[0m | [x] There must be exactly one blank line before tags
38 | [31mERROR[0m | [x] Missing short description
39 | [31mERROR[0m | [x] There must be exactly one blank line before tags
--------------------------------------------------------------------------------------------------------------------------
[1mPHPCBF CAN FIX THE 9 MARKED SNIFF VIOLATIONS AUTOMATICALLY[0m
--------------------------------------------------------------------------------------------------------------------------
So, it says "CAN FIX THE 9 MARKED SNIFF VIOLATIONS AUTOMATICALLY", but it doesn't.
When I execute phpcbf on that file, with verbose option, it says:
Registering sniffs in the Magento standard... DONE (84 sniffs registered)
Creating file list... DONE (1 files in queue)
Changing into directory anonymized.php [PHP => 195 tokens in 42 lines]... DONE in 52ms (9 fixable violations)
=> Fixing file: 0/9 violations remaining [made 1 pass]... DONE in 62ms
=> File was overwritten
PHPCBF RESULT SUMMARY
-----------------------------------------------------------------------------------------------------------------------------------------
FILE FIXED REMAINING
-----------------------------------------------------------------------------------------------------------------------------------------
anonymized.php FAILED TO FIX
-----------------------------------------------------------------------------------------------------------------------------------------
A TOTAL OF 0 ERRORS WERE FIXED IN 1 FILE
-----------------------------------------------------------------------------------------------------------------------------------------
PHPCBF FAILED TO FIX 1 FILE
-----------------------------------------------------------------------------------------------------------------------------------------
Time: 210ms; Memory: 8MB
It's just on one file, but I executed in on 359 files and the same result.
As you can see it says "Fixing file: 0/9 violations remaining [made 1 pass]... DONE in 62ms " and "File was overwritten", but I can't see any changes in my repository. And on end it says "PHPCBF FAILED TO FIX 1 FILE".
I think it's a bug, that's why I directly decided to open an issue here.
My Setup:
Mac OS Mojave 10.14.3,
PHP 7.1.25
Regards,
@slawkens Thanks for reporting this. This is an indication that there is a conflict between sniffs within the standard you use.
To see which sniffs are conflicting, run phpcbf over just one file with the -vv option. This will give very long output, but the relevant bit is at the bottom where it will show you which fixers are trying to make changes in each loop.
The Magento standard probably uses some of their own sniffs and some sniffs from PHPCS. If the sniffs mentioned in the verbose fixer report include Magento standard native sniffs, please report your issue there.
If there are only PHPCS native sniffs mentioned, this can be a configuration issue in the Magento ruleset or an issue with the actual sniffs. I think the initial investigation of which it is, should probably still be done in the Magento standard project.
If it turns out it is a conflict between PHPCS native sniffs which can't be fixed by configuring the ruleset better, please report back with a small code sample with which the conflict can be reproduced.
Closing due to no feedback. Please post again if this is still an issue and you have more debug output.
Thank you @jrfnl this saved our bacon! 馃
Most helpful comment
@slawkens Thanks for reporting this. This is an indication that there is a conflict between sniffs within the standard you use.
To see which sniffs are conflicting, run
phpcbfover just one file with the-vvoption. This will give very long output, but the relevant bit is at the bottom where it will show you which fixers are trying to make changes in each loop.The Magento standard probably uses some of their own sniffs and some sniffs from PHPCS. If the sniffs mentioned in the verbose fixer report include Magento standard native sniffs, please report your issue there.
If there are only PHPCS native sniffs mentioned, this can be a configuration issue in the Magento ruleset or an issue with the actual sniffs. I think the initial investigation of which it is, should probably still be done in the Magento standard project.
If it turns out it is a conflict between PHPCS native sniffs which can't be fixed by configuring the ruleset better, please report back with a small code sample with which the conflict can be reproduced.