Skip to content

Commit

Permalink
Fixed bug #3170 : Squiz.WhiteSpace.OperatorSpacing false positive whe…
Browse files Browse the repository at this point in the history
…n using negation with string concat
  • Loading branch information
gsherwood committed Nov 23, 2020
1 parent bbada4b commit cda358f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
2 changes: 2 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
</notes>
<contents>
<dir name="/">
Expand Down
13 changes: 7 additions & 6 deletions src/Standards/Squiz/Sniffs/WhiteSpace/OperatorSpacingSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 +
Original file line number Diff line number Diff line change
Expand Up @@ -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 +

0 comments on commit cda358f

Please sign in to comment.