squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.66k stars 1.48k forks source link

PEAR/PSR2/FunctionCallSignature: support anonymous classes #3636

Closed jrfnl closed 9 months ago

jrfnl commented 2 years ago

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:

Includes unit tests for both the PEAR.Functions.FunctionCallSignature and the PSR2.Methods.FunctionCallSignature sniffs .

jrfnl commented 2 years ago

Note: this does cause some overlap with the PSR12.Classes.AnonClassDeclaration sniff in the PSR12 standard. Not sure what to do about this, though it shouldn't be a cause for fixer conflicts (as the sniffs expect the same thing).

jrfnl commented 2 years ago

Rebased without any real changes to solve the merge conflicts.

jrfnl commented 9 months ago

Closing as replaced by https://github.com/PHPCSStandards/PHP_CodeSniffer/pull/47