PSR2/ClassDeclaration: support namespace relative names / prevent fixer conflict #424
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
PSR2/ClassDeclaration: prevent fixer conflict with itself [1]
While the
PSR2.Classes.ClassDeclaration
sniff did take partially/fully qualified names into account for interfaces being extended, it did not take namespace relative interface name into account.This led to a fixer conflict within the sniff, where the sniff would first add a space between the
namespace
keyword and the namespace separator (SpaceBeforeName
fixer) and in a subsequent loop would remove that same space again as it would think it was a space before a comma (SpaceBeforeComma
fixer).Fixed now by adding support for namespace relative interface names in the
extends
checks.Includes unit test.
PSR2/ClassDeclaration: prevent fixer conflict with itself [2]
While the
PSR2.Classes.ClassDeclaration
sniff did take partially/fully qualified names into account for interfaces being implemented, it did not take namespace relative interface names into account.This led to a fixer conflict within the sniff, where the sniff would first add a newline between the
namespace
keyword and the namespace separator (InterfaceSameLine
fixer) and in a subsequent loop would remove that same new line again as it would think it was a space before a comma (SpaceBeforeComma
fixer).Fixed now by adding support for namespace relative interface names in the
implements
check.Includes unit test.
Note: at a glance, this sniff could probably do with a more thorough review and more defensive token walking/more precise checking, but that's outside the scope of this PR.
Suggested changelog entry
PSR2.Classes.ClassDeclaration: using namespace relative interface names in the extends/implements part of a class declaration would lead to a fixer conflict.
Related issues/external references
Related to #152
Types of changes