2
.../vendor/squizlabs/php_codesniffer/phpcs --standard=PSR2 myfile.php

The report is

FOUND 10 ERRORS AND 5 WARNINGS AFFECTING 15 LINES

... 236 | ERROR | [x] Line indented incorrectly; expected 4 spaces, ...

PHPCBF CAN FIX THE 10 MARKED SNIFF VIOLATIONS AUTOMATICALLY

Then I run

.../vendor/squizlabs/php_codesniffer/phpcbf --standard=PSR2 myfile.php

Processing myfile.php [PHP => 3001 tokens in 437 lines]... DONE in 77ms (10 fixable violations)

    => Fixing file: 1/10 violations remaining [made 50 passes]... ERROR in 4.43 secs

No fixable errors were found

Time: 4.68 secs; Memory: 26.75Mb

I am running php_codesniffer locally from Laravel vendors folder.

Thanks

searain
  • 3,143
  • 6
  • 28
  • 60
  • I manually removed some codes in my file. phpcs still reported a few errors. But suddenly this time, phpcbf works now. phpcbf can clean up the errors phpcs reported. Still don't know why phpcbf did not work before. Are there any chances like that for some reasons, some errors (phpcs reported) block the phpcbf, In the codes I deleted manually, these error lines were removed and the phpcbf is unblocked? – searain Mar 20 '17 at 18:42
  • The PHPCBF output shows there was an error. This is almost always due to it not being able to handle the code provided, possible due to two sniffs conflicting during the fixing process. If you are able to share the code that caused the problem, opening an issue on Github would allow me to diagnose and fix the problem. You could also try and download the latest versions of PHPCS and PHPCBF directly (the PHAR files might be easiest) and see if the problem is still there if you aren't already using version 2.8.1 (phpcs --version to check). – Greg Sherwood Mar 21 '17 at 07:24
  • Thanks Greg, I did do the the component update on my laravel project, which include the phpcbf and phpcs. So that might be the reason the errors were corrected. – searain Mar 21 '17 at 19:03
  • Greg, also do you mean "the error phpcbf can not fix possibly blocked it to fix the fixable errors"? so if I manually fix the error phpcbf cannot fix, then it will unblock phpcbf to fix the fixable errors? I don't remember that I saw phpcs reported some errors that phpcbf cannot fix in my case. But I will keep my eyes open for this. – searain Mar 21 '17 at 22:13
  • What I meant was: PHPCBF loops over a file, fixing errors on each loop. Sometimes a very specific block of code will cause one of the sniffs to change the code in a way that causes another sniff to report an error with the fixed code. That second sniff might then revert that fix on the next loop, causing the first sniff to try and fix it again. If the same file loops 50 times, PHPCBF will decide that there are sniffs in conflict and will ERROR the file instead of fixing it. This might be what is happening. – Greg Sherwood Mar 21 '17 at 22:23

0 Answers0