PEAR/PSR2/FunctionCallSignature: support anonymous classes#3636
Closed
jrfnl wants to merge 2 commits intosquizlabs:masterfrom
Closed
PEAR/PSR2/FunctionCallSignature: support anonymous classes#3636jrfnl wants to merge 2 commits intosquizlabs:masterfrom
jrfnl wants to merge 2 commits intosquizlabs:masterfrom
Conversation
1 task
Contributor
Author
|
Note: this does cause some overlap with the |
.. to document that the sniff also handles comparisons passed in the instantiation of an anonymous class.
The function call spacing for anonymous class instantiations was so far not checked by these or any other PHPCS native sniffs.
In my opinion, object instantiations of anonymous classes should be treated the same an object instantiations of non-anonymous classes.
The `PEAR.Functions.FunctionCallSignature` and the `PSR2.Methods.FunctionCallSignature` sniffs check the object instantiation spacing for non-anonymous classes, so seem like the logical place to also check the spacing for anonymous class object instantiations.
To add this support, the `T_ANON_CLASS` token has been added to the `Tokens::$functionNameTokens` array.
Notes:
* As PSR12 does not specify the spacing between the `class` keyword and the open parenthesis (or rather is unclear about it), I am explicitly excluding anonymous classes from the "space before open parenthesis" check.
Related: squizlabs/PHP_CodeSniffer 3200
* I have verified all other uses of the `Tokens::$functionNameTokens` array within PHPCS.
- The `Generic.WhiteSpace.ArbitraryParenthesesSpacing` sniff is not affected by the change and already contains a test to verify this.
- The `Squiz.Operators.ComparisonOperatorUsage` sniff also is not affected by the change. I have added tests to confirm this in a separate commit.
* Obviously external standards using the token array _may_ be affected by the change, but a scan of the most popular external standards showed me that the token array is rarely used and when it is used, is mostly used incorrectly.
The only sniff using the array, which looks to be using it correctly and which may be affected, is the `WebImpressCodingStandard.WhiteSpace.ScopeIndent` sniff. Whether this is positive or negative is up to michalbundyra to determine.
Includes unit tests for both the `PEAR.Functions.FunctionCallSignature` and the `PSR2.Methods.FunctionCallSignature` sniffs .
90dd786 to
62d473d
Compare
Contributor
Author
|
Rebased without any real changes to solve the merge conflicts. |
DannyvdSluijs
approved these changes
Aug 28, 2023
DannyvdSluijs
left a comment
There was a problem hiding this comment.
The tests in this PR function as a proof the added functionality works as expected including the undefined number of spaces between the class keyword and opening parenthesis.
Contributor
Author
|
Closing as replaced by PHPCSStandards/PHP_CodeSniffer#47 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The function call spacing for anonymous class instantiations was so far not checked by these
or any other PHPCS nativesniffs.In my opinion, object instantiations of anonymous classes should be treated the same an object instantiations of non-anonymous classes.
The
PEAR.Functions.FunctionCallSignatureand thePSR2.Methods.FunctionCallSignaturesniffs check the object instantiation spacing for non-anonymous classes, so seem like the logical place to also check the spacing for anonymous class object instantiations.To add this support, the
T_ANON_CLASStoken has been added to theTokens::$functionNameTokensarray.Notes:
classkeyword and the open parenthesis (or rather is unclear about it), I am explicitly excluding anonymous classes from the "space before open parenthesis" check.Related: Unexpected spacing for anonymous classes with constructor arguments #3200
Tokens::$functionNameTokensarray within PHPCS.Generic.WhiteSpace.ArbitraryParenthesesSpacingsniff is not affected by the change and already contains a test to verify this.Squiz.Operators.ComparisonOperatorUsagesniff also is not affected by the change. I have added tests to confirm this in a separate commit.The only sniff using the array, which looks to be using it correctly and which may be affected, is the
WebImpressCodingStandard.WhiteSpace.ScopeIndentsniff. Whether this is positive or negative is up to @michalbundyra to determine.Includes unit tests for both the
PEAR.Functions.FunctionCallSignatureand thePSR2.Methods.FunctionCallSignaturesniffs .