Skip to content

Commit cda358f

Browse files
committed
Fixed bug #3170 : Squiz.WhiteSpace.OperatorSpacing false positive when using negation with string concat
1 parent bbada4b commit cda358f

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

package.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
6868
- Fixed bug #3157 : PSR2.ControlStructures.SwitchDeclaration.BreakIndent false positive when case keyword is not indented
6969
- Fixed bug #3165 : Squiz.PHP.DisallowComparisonAssignment false positive when comparison inside closure
7070
- Fixed bug #3167 : Generic.WhiteSpace.ScopeIndent false positive when using PHP 8.0 constructor property promotion
71+
- Fixed bug #3170 : Squiz.WhiteSpace.OperatorSpacing false positive when using negation with string concat
72+
-- This also fixes the same issue in the PSR12.Operators.OperatorSpacing sniff
7173
</notes>
7274
<contents>
7375
<dir name="/">

src/Standards/Squiz/Sniffs/WhiteSpace/OperatorSpacingSniff.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,16 @@ public function register()
8787

8888
// Trying to use a negative value; eg. myFunction($var, -2).
8989
$this->nonOperandTokens += [
90-
T_COMMA => T_COMMA,
91-
T_OPEN_PARENTHESIS => T_OPEN_PARENTHESIS,
92-
T_OPEN_SQUARE_BRACKET => T_OPEN_SQUARE_BRACKET,
93-
T_OPEN_SHORT_ARRAY => T_OPEN_SHORT_ARRAY,
90+
T_CASE => T_CASE,
9491
T_COLON => T_COLON,
95-
T_INLINE_THEN => T_INLINE_THEN,
92+
T_COMMA => T_COMMA,
9693
T_INLINE_ELSE => T_INLINE_ELSE,
97-
T_CASE => T_CASE,
94+
T_INLINE_THEN => T_INLINE_THEN,
9895
T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET,
96+
T_OPEN_PARENTHESIS => T_OPEN_PARENTHESIS,
97+
T_OPEN_SHORT_ARRAY => T_OPEN_SHORT_ARRAY,
98+
T_OPEN_SQUARE_BRACKET => T_OPEN_SQUARE_BRACKET,
99+
T_STRING_CONCAT => T_STRING_CONCAT,
99100
];
100101

101102
// Casting a negative value; eg. (array) -$a.

src/Standards/Squiz/Tests/WhiteSpace/OperatorSpacingUnitTest.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,5 +472,10 @@ $fn = fn ($boo =+1) => $boo;
472472

473473
$fn = static fn(DateTime $a, DateTime $b): int => -($a->getTimestamp() <=> $b->getTimestamp());
474474

475+
$a = 'a '.-MY_CONSTANT;
476+
$a = 'a '.-$b;
477+
$a = 'a '.- MY_CONSTANT;
478+
$a = 'a '.- $b;
479+
475480
/* Intentional parse error. This has to be the last test in the file. */
476481
$a = 10 +

src/Standards/Squiz/Tests/WhiteSpace/OperatorSpacingUnitTest.inc.fixed

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,5 +466,10 @@ $fn = fn ($boo =+1) => $boo;
466466

467467
$fn = static fn(DateTime $a, DateTime $b): int => -($a->getTimestamp() <=> $b->getTimestamp());
468468

469+
$a = 'a '.-MY_CONSTANT;
470+
$a = 'a '.-$b;
471+
$a = 'a '.- MY_CONSTANT;
472+
$a = 'a '.- $b;
473+
469474
/* Intentional parse error. This has to be the last test in the file. */
470475
$a = 10 +

0 commit comments

Comments
 (0)