Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.0 | PEAR/PSR2/FunctionCallSignature: support anonymous classes #47

Open
wants to merge 2 commits into
base: 4.0
Choose a base branch
from

Commits on Dec 7, 2023

  1. ComparisonOperatorUsage: add test with anonymous class

    .. to document that the sniff also handles comparisons passed in the instantiation of an anonymous class.
    jrfnl committed Dec 7, 2023
    Configuration menu
    Copy the full SHA
    659c6bf View commit details
    Browse the repository at this point in the history
  2. PEAR/PSR2/FunctionCallSignature: support anonymous classes

    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 .
    jrfnl committed Dec 7, 2023
    Configuration menu
    Copy the full SHA
    e0ff181 View commit details
    Browse the repository at this point in the history