Repository navigation
Description
Premise
A standard should be able to be used without leading to fixer conflicts.
Now, as code can be written in lots of different ways, it is not always straight forward to anticipate potential conflicts, however, PHPCS contains a wealth of test code, so by running the fixers for a standard over all test case files, we should be able to detect a lot of potential fixer conflicts.
Current status
While I have the workflow and the set up for this check ready, it cannot currently be turned on as all standards, except PSR1, lead to fixer conflicts.
Note: as CSS/JS support will be dropped in v 4.0, I've not included the CSS/JS test case files in the set up for the fixer conflict check.
Also note that
Genericis not a standard but a sniff collection containing conflicting rules by design. For that reason, the fixer conflict check is not relevant.
Last update date for the "current status": 2025-02-19 (including some prepped, but not yet pulled PRs)
Please feel free to ping @jrfnl for an update if the list is outdated.
Details of current fixer conflicts for the PEAR standard
Command:
phpcbf -p . --standard=PEAR --ignore=*/build/*,*/vendor/* --basepath=. --extensions=inc --suffix=.conflictcheckTest case files leading to fixer conflicts
PHPCBF RESULT SUMMARY
------------------------------------------------------------------------------------------------------------------
FILE FIXED REMAINING
------------------------------------------------------------------------------------------------------------------
src\Standards\Generic\Tests\ControlStructures\DisallowYodaConditionsUnitTest.inc FAILED TO FIX
src\Standards\Generic\Tests\ControlStructures\InlineControlStructureUnitTest.1.inc FAILED TO FIX **NEW 2025-02
src\Standards\Generic\Tests\WhiteSpace\ScopeIndentUnitTest.1.inc FAILED TO FIX
src\Standards\Generic\Tests\WhiteSpace\ScopeIndentUnitTest.2.inc FAILED TO FIX
src\Standards\PEAR\Tests\NamingConventions\ValidVariableNameUnitTest.inc FAILED TO FIX
src\Standards\PEAR\Tests\WhiteSpace\ScopeClosingBraceUnitTest.inc FAILED TO FIX
src\Standards\PSR12\Tests\Functions\ReturnTypeDeclarationUnitTest.inc FAILED TO FIX
src\Standards\PSR2\Tests\ControlStructures\SwitchDeclarationUnitTest.inc FAILED TO FIX
src\Standards\Squiz\Tests\Commenting\LongConditionClosingCommentUnitTest.inc FAILED TO FIX
src\Standards\Squiz\Tests\PHP\NonExecutableCodeUnitTest.1.inc FAILED TO FIX
tests\Core\File\FindEndOfStatementTest.inc FAILED TO FIX
tests\Core\File\FindStartOfStatementTest.inc FAILED TO FIX
tests\Core\File\GetMethodPropertiesTest.inc FAILED TO FIX **NEW 2024-03
tests\Core\Tokenizers\PHP\DefaultKeywordTest.inc FAILED TO FIX
tests\Core\Tokenizers\PHP\DNFTypesParseError1Test.inc FAILED TO FIX **NEW 2024-07
tests\Core\Tokenizers\PHP\EnumCaseTest.inc FAILED TO FIX
tests\Core\Tokenizers\Tokenizer\RecurseScopeMapCaseKeywordConditionsTest.inc FAILED TO FIX **NEW 2024-07
tests\Core\Tokenizers\Tokenizer\RecurseScopeMapDefaultKeywordConditionsTest.inc FAILED TO FIX **NEW 2024-07
------------------------------------------------------------------------------------------------------------------
A TOTAL OF 10153 ERRORS WERE FIXED IN 321 FILES
------------------------------------------------------------------------------------------------------------------
PHPCBF FAILED TO FIX 18 FILES
------------------------------------------------------------------------------------------------------------------
Details of current fixer conflicts for the PSR2 standard
Command:
phpcbf -p . --standard=PSR2 --ignore=*/build/*,*/vendor/* --basepath=. --extensions=inc --suffix=.conflictcheckTest case files leading to fixer conflicts
PHPCBF RESULT SUMMARY
------------------------------------------------------------------------------------------------------------------
FILE FIXED REMAINING
------------------------------------------------------------------------------------------------------------------
src\Standards\Generic\Tests\CodeAnalysis\JumbledIncrementerUnitTest.4.inc FAILED TO FIX **NEW 2024-07
src\Standards\PEAR\Tests\Functions\FunctionCallSignatureUnitTest.inc FAILED TO FIX
src\Standards\PSR12\Tests\Functions\ReturnTypeDeclarationUnitTest.inc FAILED TO FIX
tests\Core\File\GetMethodPropertiesTest.inc FAILED TO FIX **NEW 2024-03
tests\Core\Tokenizers\PHP\DNFTypesParseError1Test.inc FAILED TO FIX **NEW 2024-07
------------------------------------------------------------------------------------------------------------------
A TOTAL OF 10020 ERRORS WERE FIXED IN 373 FILES
------------------------------------------------------------------------------------------------------------------
PHPCBF FAILED TO FIX 5 FILES
------------------------------------------------------------------------------------------------------------------
Details of current fixer conflicts for the PSR12 standard
Command:
phpcbf -p . --standard=PSR12 --ignore=*/build/*,*/vendor/* --basepath=. --extensions=inc --suffix=.conflictcheckTest case files leading to fixer conflicts
PHPCBF RESULT SUMMARY
------------------------------------------------------------------------------------------------------------------
FILE FIXED REMAINING
------------------------------------------------------------------------------------------------------------------
src\Standards\Generic\Tests\CodeAnalysis\JumbledIncrementerUnitTest.4.inc FAILED TO FIX **NEW 2024-07
src\Standards\Generic\Tests\PHP\RequireStrictTypesUnitTest.5.inc FAILED TO FIX
src\Standards\PEAR\Tests\Functions\FunctionCallSignatureUnitTest.inc FAILED TO FIX
src\Standards\PSR12\Tests\Functions\ReturnTypeDeclarationUnitTest.inc FAILED TO FIX
tests\Core\File\GetMethodPropertiesTest.inc FAILED TO FIX **NEW 2024-03
tests\Core\Tokenizers\PHP\DNFTypesParseError1Test.inc FAILED TO FIX **NEW 2024-07
tests\Core\Tokenizers\PHP\DNFTypesParseError2Test.inc FAILED TO FIX **NEW 2024-07
------------------------------------------------------------------------------------------------------------------
A TOTAL OF 11962 ERRORS WERE FIXED IN 441 FILES
------------------------------------------------------------------------------------------------------------------
PHPCBF FAILED TO FIX 7 FILES
------------------------------------------------------------------------------------------------------------------
Details of current fixer conflicts for the Squiz standard
Command:
phpcbf -p . --standard=Squiz --ignore=*/build/*,*/vendor/* --basepath=. --extensions=inc --suffix=.conflictcheckTest case files leading to fixer conflicts
PHPCBF RESULT SUMMARY
------------------------------------------------------------------------------------------------------------------
FILE FIXED REMAINING
------------------------------------------------------------------------------------------------------------------
src\Standards\Generic\Tests\Arrays\ArrayIndentUnitTest.inc FAILED TO FIX
src\Standards\Generic\Tests\Classes\DuplicateClassNameUnitTest.3.inc FAILED TO FIX
src\Standards\Generic\Tests\Classes\DuplicateClassNameUnitTest.9.inc FAILED TO FIX **NEW 2025-02
src\Standards\Generic\Tests\CodeAnalysis\EmptyPHPStatementUnitTest.1.inc FAILED TO FIX
src\Standards\Generic\Tests\CodeAnalysis\JumbledIncrementerUnitTest.4.inc FAILED TO FIX **NEW 2024-07
src\Standards\Generic\Tests\ControlStructures\DisallowYodaConditionsUnitTest.inc FAILED TO FIX
src\Standards\Generic\Tests\ControlStructures\InlineControlStructureUnitTest.1.inc FAILED TO FIX **NEW 2024-07
src\Standards\Generic\Tests\Functions\FunctionCallArgumentSpacingUnitTest.1.inc FAILED TO FIX **NEW 2024-07
src\Standards\Generic\Tests\NamingConventions\AbstractClassNamePrefixUnitTest.1.inc FAILED TO FIX
src\Standards\Generic\Tests\NamingConventions\ConstructorNameUnitTest.1.inc FAILED TO FIX **NEW 2025-02
src\Standards\Generic\Tests\NamingConventions\TraitNameSuffixUnitTest.1.inc FAILED TO FIX **NEW 2025-02
src\Standards\Generic\Tests\PHP\CharacterBeforePHPOpeningTagUnitTest.1.inc FAILED TO FIX
src\Standards\Generic\Tests\WhiteSpace\ScopeIndentUnitTest.1.inc FAILED TO FIX
src\Standards\Generic\Tests\WhiteSpace\ScopeIndentUnitTest.2.inc FAILED TO FIX
src\Standards\PEAR\Tests\Classes\ClassDeclarationUnitTest.1.inc FAILED TO FIX
src\Standards\PEAR\Tests\Classes\ClassDeclarationUnitTest.2.inc FAILED TO FIX
src\Standards\PEAR\Tests\Commenting\ClassCommentUnitTest.inc FAILED TO FIX
src\Standards\PEAR\Tests\Functions\FunctionCallSignatureUnitTest.inc FAILED TO FIX
src\Standards\PEAR\Tests\Functions\FunctionDeclarationUnitTest.1.inc FAILED TO FIX
src\Standards\PEAR\Tests\NamingConventions\ValidVariableNameUnitTest.inc FAILED TO FIX
src\Standards\PSR1\Tests\Files\SideEffectsUnitTest.1.inc FAILED TO FIX
src\Standards\PSR12\Tests\ControlStructures\BooleanOperatorPlacementUnitTest.inc FAILED TO FIX
src\Standards\PSR12\Tests\Functions\ReturnTypeDeclarationUnitTest.inc FAILED TO FIX
src\Standards\PSR12\Tests\Operators\OperatorSpacingUnitTest.1.inc FAILED TO FIX
src\Standards\PSR2\Tests\Classes\ClassDeclarationUnitTest.inc FAILED TO FIX
src\Standards\PSR2\Tests\ControlStructures\ControlStructureSpacingUnitTest.inc FAILED TO FIX
src\Standards\PSR2\Tests\Methods\FunctionCallSignatureUnitTest.inc FAILED TO FIX
src\Standards\Squiz\Tests\Arrays\ArrayDeclarationUnitTest.1.inc FAILED TO FIX
src\Standards\Squiz\Tests\Arrays\ArrayDeclarationUnitTest.2.inc FAILED TO FIX
src\Standards\Squiz\Tests\Classes\SelfMemberReferenceUnitTest.inc FAILED TO FIX
src\Standards\Squiz\Tests\Classes\ValidClassNameUnitTest.inc FAILED TO FIX **NEW 2025-02
src\Standards\Squiz\Tests\Commenting\ClassCommentUnitTest.inc FAILED TO FIX
src\Standards\Squiz\Tests\Commenting\FunctionCommentThrowTagUnitTest.inc FAILED TO FIX
src\Standards\Squiz\Tests\Commenting\FunctionCommentUnitTest.inc FAILED TO FIX **NEW 2025-02
src\Standards\Squiz\Tests\ControlStructures\ControlSignatureUnitTest.1.inc FAILED TO FIX
src\Standards\Squiz\Tests\ControlStructures\ForEachLoopDeclarationUnitTest.inc FAILED TO FIX
src\Standards\Squiz\Tests\ControlStructures\ForLoopDeclarationUnitTest.1.inc FAILED TO FIX
src\Standards\Squiz\Tests\Functions\FunctionDeclarationArgumentSpacingUnitTest.1.inc FAILED TO FIX **NEW 2025-02
src\Standards\Squiz\Tests\Objects\ObjectInstantiationUnitTest.inc FAILED TO FIX **NEW 2024-03
src\Standards\Squiz\Tests\PHP\InnerFunctionsUnitTest.inc FAILED TO FIX
src\Standards\Squiz\Tests\WhiteSpace\ControlStructureSpacingUnitTest.inc FAILED TO FIX
src\Standards\Squiz\Tests\WhiteSpace\FunctionSpacingUnitTest.1.inc FAILED TO FIX
src\Standards\Squiz\Tests\WhiteSpace\ScopeClosingBraceUnitTest.inc FAILED TO FIX
src\Standards\Squiz\Tests\WhiteSpace\ScopeKeywordSpacingUnitTest.3.inc FAILED TO FIX
tests\Core\File\FindExtendedClassNameTest.inc FAILED TO FIX **NEW 2024-03
tests\Core\File\FindStartOfStatementTest.inc FAILED TO FIX
tests\Core\File\GetClassPropertiesTest.inc FAILED TO FIX **NEW 2025-02
tests\Core\File\GetConditionTest.inc FAILED TO FIX **NEW 2024-03
tests\Core\File\GetDeclarationNameTest.inc FAILED TO FIX **NEW 2024-03
tests\Core\File\GetMemberPropertiesTest.inc FAILED TO FIX
tests\Core\File\GetMethodParametersTest.inc FAILED TO FIX
tests\Core\File\GetMethodPropertiesTest.inc FAILED TO FIX **NEW 2024-03
tests\Core\Tokenizers\PHP\AttributesTest.inc FAILED TO FIX
tests\Core\Tokenizers\PHP\BackfillMatchTokenTest.inc FAILED TO FIX
tests\Core\Tokenizers\PHP\BackfillReadonlyTest.inc FAILED TO FIX **NEW 2024-03
tests\Core\Tokenizers\PHP\BitwiseOrTest.inc FAILED TO FIX
tests\Core\Tokenizers\PHP\ContextSensitiveKeywordsTest.inc FAILED TO FIX
tests\Core\Tokenizers\PHP\DefaultKeywordTest.inc FAILED TO FIX
tests\Core\Tokenizers\PHP\DNFTypesParseError1Test.inc FAILED TO FIX **NEW 2024-07
tests\Core\Tokenizers\PHP\DNFTypesTest.inc FAILED TO FIX **NEW 2024-07
tests\Core\Tokenizers\PHP\DoubleArrowTest.inc FAILED TO FIX
tests\Core\Tokenizers\PHP\EnumCaseTest.inc FAILED TO FIX
tests\Core\Tokenizers\PHP\TypeIntersectionTest.inc FAILED TO FIX
tests\Core\Tokenizers\Tokenizer\CreateParenthesisNestingMapDNFTypesTest.inc FAILED TO FIX **NEW 2024-07
tests\Core\Tokenizers\Tokenizer\RecurseScopeMapCaseKeywordConditionsTest.inc FAILED TO FIX **NEW 2024-07
tests\Core\Tokenizers\Tokenizer\RecurseScopeMapDefaultKeywordConditionsTest.inc FAILED TO FIX **NEW 2024-07
------------------------------------------------------------------------------------------------------------------
A TOTAL OF 27638 ERRORS WERE FIXED IN 506 FILES
------------------------------------------------------------------------------------------------------------------
PHPCBF FAILED TO FIX 66 FILES
------------------------------------------------------------------------------------------------------------------
Details of current fixer conflicts for the Zend standard
Command:
phpcbf -p . --standard=Zend --ignore=*/build/*,*/vendor/* --basepath=. --extensions=inc --suffix=.conflictcheckTest case files leading to fixer conflicts
PHPCBF RESULT SUMMARY
------------------------------------------------------------------------------------------------------------------
FILE FIXED REMAINING
------------------------------------------------------------------------------------------------------------------
src\Standards\Generic\Tests\Functions\FunctionCallArgumentSpacingUnitTest.1.inc FAILED TO FIX
src\Standards\Generic\Tests\NamingConventions\ConstructorNameUnitTest.1.inc FAILED TO FIX
------------------------------------------------------------------------------------------------------------------
A TOTAL OF 6580 ERRORS WERE FIXED IN 331 FILES
-------------------------------------------------------------------------------------------------------------
PHPCBF FAILED TO FIX 2 FILES
------------------------------------------------------------------------------------------------------------------
Caveat
There are some files which should probably be excluded from a fixer conflict check like this ticket proposes. Most notably test case files which contain git merge conflict markers.
For the above lists in the fold-outs, this was already done.
What needs to be done
For each of the files listed above leading to a fixer conflict, it needs to be determined whether:
- The file should be excluded from the fixer conflict check; or
- The fixer conflict is a realistic situation which should be handled.
How to go about this
- Add
*.conflictcheckto your.git/info/exclude(will be added to.gitignorewhen the fixer conflict check will be added for real). - Run the command listed against one particular file from the conflict list with the
-vvvflag. - The output will be long, but at the bottom you will find information about the conflicting sniffs.
- Identify the piece of code in the test case file which is causing the conflict.
- Look critically at the piece of code causing the conflict to determine whether this is a situation which:
- should be handled by the sniffs;
- whether the code snippet is an unintentional parse error, which should be fixed. This applies to unintentional typos in a test case in contrast to a test case specifically created as a parse error to test the handling within the sniff.
- whether the code snippet is an intentional parse error and that particular piece of code should be moved to its own test case file and that file should be excluded (also see Tests: parse error tests for sniffs should be in their own file #143);
- whether the existing test case file should be excluded.
- If the sniffs should handle this gracefully, add the piece of code to the test case files for all sniffs involved.
- Decide for each sniff how the issue should be handled. Oftentimes, the answer is adding more defensive coding and bowing out in certain circumstances, meaning one sniff takes precedence over another.
When in doubt, share your findings and discuss the options for the conflict you are working on in a comment on this ticket or create a separate ticket to discuss solution directions if the conflict is a complex one (and link that ticket to this one).
PRs for this task should only contain the solution for one fixer conflict per PR and if the conflict can be isolated enough, the PR should be limited to fixing the issue for only one of the sniffs involved, with, if necessary, separate PRs for the other sniff(s) involved.
Activity
jrfnl commentedon Dec 13, 2023
To prevent confusion/wasting people's time I reiterate that the task is not to get the conflict check running. I have the set up for that ready already.
Also note that if you would try to run the mentioned command without limiting them to an individual conflict which you want to investigate, there are three PHP notices which will crash the runs.
fredden commentedon Dec 13, 2023
For the
PSR2standard, the conflict forsrc/Standards/PSR12/Tests/Functions/ReturnTypeDeclarationUnitTest.incseems to be betweenSquiz.Functions.MultiLineFunctionDeclaration.BraceIndentandGeneric.WhiteSpace.ScopeIndent.Incorrecton (new) line 79. From what I can tell, it looks likeSquiz.Functions.MultiLineFunctionDeclaration.BraceIndentshould win in this case. This feels related to (but is not fixed by) #38.fredden commentedon Jul 14, 2024
I've looked into the PSR12 conflict with
src/Standards/Squiz/Tests/ControlStructures/ForEachLoopDeclarationUnitTest.inc. This is a conflict betweenSquiz.ControlStructures.ForEachLoopDeclarationandPSR2.ControlStructures.ControlStructureSpacingwhen certain configuration options are set on the Squiz sniff. Looking at theruleset.xmlfor PSR12, I can see that the intention is to ignore parts of the Squiz sniff by marking the error codes as severity=0.PHP_CodeSniffer/src/Standards/PSR12/ruleset.xml
Lines 294 to 300 in 071344b
However, there's an inconsistency within
Squiz.ControlStructures.ForEachLoopDeclarationwhich I believe is the cause of this conflict. The sniff can be configured with properties, and there's an if/else block to handle the two options (no space / some number of spaces).For "space before close", the two branches report the same error code:
SpaceBeforeClose. This is what's listed in theruleset.xmlabove. See lines 107 and 123.For "space after open", the two branches report different error codes:
SpaceAfterOpenandSpacingAfterOpen. Only one of these is listed inruleset.xmlabove. See lines 77 (space) and 93 (spacing).PHP_CodeSniffer/src/Standards/Squiz/Sniffs/ControlStructures/ForEachLoopDeclarationSniff.php
Lines 75 to 133 in 071344b
To fix this, I can see several options. I'd like an opinion about what is the "best" way forward here.
ruleset.xmlfor PSR12 to exclude all three error codes. Ignore the inconsistency within the sniff.SpacingAfterOpentoSpaceAfterOpen. No change to PSR12 ruleset required.SpaceBeforeClosetoSpacingBeforeClose. Update the PSR12 ruleset to exclude all four codes.I'd like to proceed with option 2 (or maybe 4), but recognise that this can be seen as a backwards-incompatible change.
For reference, these are all the codes reported by this sniff:
AsNotLower,MissingAs,MissingCloseParenthesis,MissingOpenParenthesis,NoSpaceAfterArrow,NoSpaceAfterAs,NoSpaceBeforeArrow,NoSpaceBeforeAs,SpaceAfterOpen,SpacingAfterOpen,SpaceBeforeClose,SpaceBeforeClose,SpacingAfterArrow,SpacingAfterAs,SpacingBeforeArrow,SpacingBeforeAs@jrfnl what are your thoughts on this?
jrfnl commentedon Jul 29, 2024
@fredden We've looked at this together today and in my opinion, option 2 is the way to go.
If I look at both the Squiz
ForLoopandForeachLoopsniffs, it looks like the intention was for those errors to have the same error code anyway (no space/too much space, still bothSpaceAfterOpenissue).If I then look at the
ForeachLoopsniff, the "after open"/"before close" error codes have 3 xSpace...and 1 xSpacing..., so I thinkSpaceAfterOpenshould prevail.While this removes an error code, I would not consider this a breaking change which needs to be in a major, though I would put it in a minor.
PSR12, the chances are that more rulesets only excluded two of the three error codes and fixing the error code will (in most cases) fix the ruleset for those projects, so should be seen as a bug fix.PEAR/FunctionDeclaration: prevent fixer conflict for unfinished closu…
PEAR/FunctionDeclaration: prevent fixer conflict for unfinished closu…