diff --git a/src/Standards/PEAR/Sniffs/Functions/FunctionCallSignatureSniff.php b/src/Standards/PEAR/Sniffs/Functions/FunctionCallSignatureSniff.php index 323dc3b306..b98186b146 100644 --- a/src/Standards/PEAR/Sniffs/Functions/FunctionCallSignatureSniff.php +++ b/src/Standards/PEAR/Sniffs/Functions/FunctionCallSignatureSniff.php @@ -110,7 +110,9 @@ public function process(File $phpcsFile, $stackPtr) $closeBracket = $tokens[$openBracket]['parenthesis_closer']; - if (($stackPtr + 1) !== $openBracket) { + if ($tokens[$stackPtr]['code'] !== T_ANON_CLASS + && ($stackPtr + 1) !== $openBracket + ) { // Checking this: $value = my_function[*](...). $error = 'Space before opening parenthesis of function call prohibited'; $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceBeforeOpenBracket'); diff --git a/src/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.inc b/src/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.inc index 8e35a96c8b..5c7823ce7c 100644 --- a/src/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.inc +++ b/src/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.inc @@ -587,3 +587,25 @@ content 'my_file.php' ); ?> + + 1, 586 => 1, 587 => 1, + 601 => 2, + 602 => 2, + 603 => 1, + 604 => 1, + 605 => 2, ]; }//end getErrorList() diff --git a/src/Standards/PSR2/Tests/Methods/FunctionCallSignatureUnitTest.inc b/src/Standards/PSR2/Tests/Methods/FunctionCallSignatureUnitTest.inc index 1ca477d054..57ed98c301 100644 --- a/src/Standards/PSR2/Tests/Methods/FunctionCallSignatureUnitTest.inc +++ b/src/Standards/PSR2/Tests/Methods/FunctionCallSignatureUnitTest.inc @@ -265,3 +265,24 @@ array_fill_keys( ), value: true, ); // phpcs:set PSR2.Methods.FunctionCallSignature allowMultipleArguments false + +// Anonymous object instantiations are treated the same as a normal call. +$anon = new class() {}; +$anon = new class($foo, true) {}; +$anon = new class( + $foo, + true, + 10 +) {}; + +$anon = new class( ) {}; +$anon = new class( $foo, true ) {}; +$anon = new class($foo, + + true, 10) {}; + +// ... though do not enforce no space between the class keyword and the open parenthesis. +$anon = new class () {}; + +// And anonymous object instantiations without parentheses are ignored. +$anon = new class {}; diff --git a/src/Standards/PSR2/Tests/Methods/FunctionCallSignatureUnitTest.inc.fixed b/src/Standards/PSR2/Tests/Methods/FunctionCallSignatureUnitTest.inc.fixed index dc383ed2a7..ef4630874b 100644 --- a/src/Standards/PSR2/Tests/Methods/FunctionCallSignatureUnitTest.inc.fixed +++ b/src/Standards/PSR2/Tests/Methods/FunctionCallSignatureUnitTest.inc.fixed @@ -281,3 +281,26 @@ array_fill_keys( ), value: true, ); // phpcs:set PSR2.Methods.FunctionCallSignature allowMultipleArguments false + +// Anonymous object instantiations are treated the same as a normal call. +$anon = new class() {}; +$anon = new class($foo, true) {}; +$anon = new class( + $foo, + true, + 10 +) {}; + +$anon = new class() {}; +$anon = new class($foo, true) {}; +$anon = new class( + $foo, + true, + 10 +) {}; + +// ... though do not enforce no space between the class keyword and the open parenthesis. +$anon = new class () {}; + +// And anonymous object instantiations without parentheses are ignored. +$anon = new class {}; diff --git a/src/Standards/PSR2/Tests/Methods/FunctionCallSignatureUnitTest.php b/src/Standards/PSR2/Tests/Methods/FunctionCallSignatureUnitTest.php index 7f6ce1f959..ee133d22bd 100644 --- a/src/Standards/PSR2/Tests/Methods/FunctionCallSignatureUnitTest.php +++ b/src/Standards/PSR2/Tests/Methods/FunctionCallSignatureUnitTest.php @@ -71,6 +71,11 @@ public function getErrorList() 258 => 1, 263 => 1, 264 => 1, + 278 => 2, + 279 => 2, + 280 => 1, + 281 => 1, + 282 => 3, ]; }//end getErrorList() diff --git a/src/Util/Tokens.php b/src/Util/Tokens.php index 4f0fb5ae86..fe544f96f8 100644 --- a/src/Util/Tokens.php +++ b/src/Util/Tokens.php @@ -632,6 +632,7 @@ final class Tokens T_SELF => T_SELF, T_PARENT => T_PARENT, T_STATIC => T_STATIC, + T_ANON_CLASS => T_ANON_CLASS, ]; /**