diff --git a/src/Standards/PEAR/Sniffs/Functions/FunctionCallSignatureSniff.php b/src/Standards/PEAR/Sniffs/Functions/FunctionCallSignatureSniff.php index b5e8695c15..ba50ca9b34 100644 --- a/src/Standards/PEAR/Sniffs/Functions/FunctionCallSignatureSniff.php +++ b/src/Standards/PEAR/Sniffs/Functions/FunctionCallSignatureSniff.php @@ -120,7 +120,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 612748fedf..25bdc2886d 100644 --- a/src/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.inc +++ b/src/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.inc @@ -567,3 +567,25 @@ content
+ + 1, 567 => 1, 568 => 1, + 581 => 2, + 582 => 2, + 583 => 1, + 584 => 1, + 585 => 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 1d87825891..f2fee62b64 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/Standards/Squiz/Tests/Operators/ComparisonOperatorUsageUnitTest.inc b/src/Standards/Squiz/Tests/Operators/ComparisonOperatorUsageUnitTest.inc index 8522438dcf..b80db384c2 100644 --- a/src/Standards/Squiz/Tests/Operators/ComparisonOperatorUsageUnitTest.inc +++ b/src/Standards/Squiz/Tests/Operators/ComparisonOperatorUsageUnitTest.inc @@ -136,3 +136,10 @@ if (empty($argTags > 0)) { } myFunction($var1 === true ? "" : "foobar"); + +$anon = new class(!$foo ? 0 : 1, ($bar == true) ? 1 : 0) { + function __construct($a, $b) {} +}; +$anon = new class($foo === false ? 0 : 1, ($bar === true) ? 1 : 0) { + function __construct($a, $b) {} +}; diff --git a/src/Standards/Squiz/Tests/Operators/ComparisonOperatorUsageUnitTest.php b/src/Standards/Squiz/Tests/Operators/ComparisonOperatorUsageUnitTest.php index 5618a7fc0c..4b08b4578a 100644 --- a/src/Standards/Squiz/Tests/Operators/ComparisonOperatorUsageUnitTest.php +++ b/src/Standards/Squiz/Tests/Operators/ComparisonOperatorUsageUnitTest.php @@ -58,6 +58,7 @@ public function getErrorList($testFile='ComparisonOperatorUsageUnitTest.inc') 127 => 1, 131 => 1, 135 => 1, + 140 => 2, ]; break; case 'ComparisonOperatorUsageUnitTest.js': diff --git a/src/Util/Tokens.php b/src/Util/Tokens.php index bb1fb2ca99..c250d6edec 100644 --- a/src/Util/Tokens.php +++ b/src/Util/Tokens.php @@ -630,6 +630,7 @@ final class Tokens T_SELF => T_SELF, T_PARENT => T_PARENT, T_STATIC => T_STATIC, + T_ANON_CLASS => T_ANON_CLASS, ]; /**