diff --git a/package.xml b/package.xml index 8504e4697f..ec5302a08a 100644 --- a/package.xml +++ b/package.xml @@ -68,6 +68,8 @@ http://pear.php.net/dtd/package-2.0.xsd"> - Fixed bug #3157 : PSR2.ControlStructures.SwitchDeclaration.BreakIndent false positive when case keyword is not indented - Fixed bug #3165 : Squiz.PHP.DisallowComparisonAssignment false positive when comparison inside closure - Fixed bug #3167 : Generic.WhiteSpace.ScopeIndent false positive when using PHP 8.0 constructor property promotion + - Fixed bug #3170 : Squiz.WhiteSpace.OperatorSpacing false positive when using negation with string concat + -- This also fixes the same issue in the PSR12.Operators.OperatorSpacing sniff diff --git a/src/Standards/Squiz/Sniffs/WhiteSpace/OperatorSpacingSniff.php b/src/Standards/Squiz/Sniffs/WhiteSpace/OperatorSpacingSniff.php index ee44545aea..2627d10d98 100644 --- a/src/Standards/Squiz/Sniffs/WhiteSpace/OperatorSpacingSniff.php +++ b/src/Standards/Squiz/Sniffs/WhiteSpace/OperatorSpacingSniff.php @@ -87,15 +87,16 @@ public function register() // Trying to use a negative value; eg. myFunction($var, -2). $this->nonOperandTokens += [ - T_COMMA => T_COMMA, - T_OPEN_PARENTHESIS => T_OPEN_PARENTHESIS, - T_OPEN_SQUARE_BRACKET => T_OPEN_SQUARE_BRACKET, - T_OPEN_SHORT_ARRAY => T_OPEN_SHORT_ARRAY, + T_CASE => T_CASE, T_COLON => T_COLON, - T_INLINE_THEN => T_INLINE_THEN, + T_COMMA => T_COMMA, T_INLINE_ELSE => T_INLINE_ELSE, - T_CASE => T_CASE, + T_INLINE_THEN => T_INLINE_THEN, T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET, + T_OPEN_PARENTHESIS => T_OPEN_PARENTHESIS, + T_OPEN_SHORT_ARRAY => T_OPEN_SHORT_ARRAY, + T_OPEN_SQUARE_BRACKET => T_OPEN_SQUARE_BRACKET, + T_STRING_CONCAT => T_STRING_CONCAT, ]; // Casting a negative value; eg. (array) -$a. diff --git a/src/Standards/Squiz/Tests/WhiteSpace/OperatorSpacingUnitTest.inc b/src/Standards/Squiz/Tests/WhiteSpace/OperatorSpacingUnitTest.inc index 82d4af15be..f89cf08d5c 100644 --- a/src/Standards/Squiz/Tests/WhiteSpace/OperatorSpacingUnitTest.inc +++ b/src/Standards/Squiz/Tests/WhiteSpace/OperatorSpacingUnitTest.inc @@ -472,5 +472,10 @@ $fn = fn ($boo =+1) => $boo; $fn = static fn(DateTime $a, DateTime $b): int => -($a->getTimestamp() <=> $b->getTimestamp()); +$a = 'a '.-MY_CONSTANT; +$a = 'a '.-$b; +$a = 'a '.- MY_CONSTANT; +$a = 'a '.- $b; + /* Intentional parse error. This has to be the last test in the file. */ $a = 10 + diff --git a/src/Standards/Squiz/Tests/WhiteSpace/OperatorSpacingUnitTest.inc.fixed b/src/Standards/Squiz/Tests/WhiteSpace/OperatorSpacingUnitTest.inc.fixed index ee4060bc11..138616e752 100644 --- a/src/Standards/Squiz/Tests/WhiteSpace/OperatorSpacingUnitTest.inc.fixed +++ b/src/Standards/Squiz/Tests/WhiteSpace/OperatorSpacingUnitTest.inc.fixed @@ -466,5 +466,10 @@ $fn = fn ($boo =+1) => $boo; $fn = static fn(DateTime $a, DateTime $b): int => -($a->getTimestamp() <=> $b->getTimestamp()); +$a = 'a '.-MY_CONSTANT; +$a = 'a '.-$b; +$a = 'a '.- MY_CONSTANT; +$a = 'a '.- $b; + /* Intentional parse error. This has to be the last test in the file. */ $a = 10 +