-
-
Notifications
You must be signed in to change notification settings - Fork 94
Description
Unexpected Exit Code from PHPCBF
Let's say I have a rule to enforce every file starting with declare(strict_types=1); like:
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
<exclude-pattern>tests/*</exclude-pattern>
<properties>
<property name="linesCountBeforeDeclare" value="1" />
<property name="linesCountAfterDeclare" value="1" />
<property name="spacesCountAroundEqualsSign" value="0" />
</properties>
</rule>
I then deliberately remove declare(strict_types=1); from one file and run ./vendor/bin/phpcbf.
This is the output I see:
.........................................F.................. 60 / 125 (48%)
............................................................ 120 / 125 (96%)
..... 125 / 125 (100%)
PHPCBF RESULT SUMMARY
----------------------------------------------------------------------------------------------------------------------------------
FILE FIXED REMAINING
----------------------------------------------------------------------------------------------------------------------------------
.../home/Library/Project/app/View/Components/PersonLayout.php 1 0
----------------------------------------------------------------------------------------------------------------------------------
A TOTAL OF 1 ERROR WERE FIXED IN 1 FILE
----------------------------------------------------------------------------------------------------------------------------------
Time: 4.83 secs; Memory: 32MB
My understand is that, according to the documentation, the Exit Code should be 0: "clean code base / auto-fixed with no issues remaining".
However in this instance, I'm getting the Exit Code 2: "issues found/remaining, non-auto-fixable"
This is very confusing to me because the number of remaining issues is zero.
UPDATE:
I was suppressing any warnings with -n. This seems to be related to the issue. If there are non-fixable warnings and they are suppressed with -n then the exit code reflects the existence of those unfixable warnings, rather than the suppressed output.
Code sample (updated)
#!/bin/bash
# Run PHP_CODESNIFFER fixer
./vendor/bin/phpcbf -n
result=$?
printf "Exit Code: %s\n" "$result"Custom ruleset (updated)
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
<exclude-pattern>tests/*</exclude-pattern>
<properties>
<property name="linesCountBeforeDeclare" value="1" />
<property name="linesCountAfterDeclare" value="1" />
<property name="spacesCountAroundEqualsSign" value="0" />
</properties>
</rule>
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="120"/>
<property name="absoluteLineLimit" value="0"/>
</properties>
</rule>To reproduce (updated)
Steps to reproduce the behavior:
- Create a file called
test.phpopening <?php withoutdeclare(strict_types=1);and with a line exceeding 120 chars - Add custom ruleset above
- Create a file called
check.shthat will display the Exit Code for you (use code above) - Run
bash check.sh - See Exit Code is returned as
2
Expected behavior
Exit Code should be 0.
Versions (please complete the following information)
| Operating System | MacOS 26.2 |
| PHP version | 8.4 |
| PHP_CodeSniffer version | 4.0.1 (stable) |
| Standard | PSR12 |
| Install type | Composer (global) |
Please confirm
- I have searched the issue list and am not opening a duplicate issue.
- I have read the Contribution Guidelines and this is not a support question.
- I confirm that this bug is a bug in PHP_CodeSniffer and not in one of the external standards.
- I have verified the issue still exists in the
4.xbranch of PHP_CodeSniffer.