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/Squiz/[MultiLine]FunctionDeclaration: allow for PHP 8.1 new in initializers #3787

Closed jrfnl closed 1 year ago

jrfnl commented 1 year ago

Since PHP 8.1, new ClassName() expressions can be used as the default value of a parameter in a function declaration.

new ClassName() expressions should be treated as function calls, which have their own indentation rules, so the PEAR.Functions.FunctionDeclaration and the Squiz.Functions.MultiLineFunctionDeclaration sniffs should skip over these and not attempt to change the indentation of parameters in those function calls.

This commit implements this change.

Includes unit tests.

Refs:

Fixes #3786


Note:

jrfnl commented 1 year ago

Note: this PR will conflict with the already open PRs #3739 and #3661 and depending on the merge order, rebasing and conflict resolution will be needed....

jrfnl commented 9 months ago

FYI: this fix is included in today's PHP_CodeSniffer 3.8.0 release.

As per #3932, development on PHP_CodeSniffer will continue in the PHPCSStandards/PHP_CodeSniffer repository. If you want to stay informed, you may want to start "watching" that repo (or watching releases from that repo).