Skip to content

Commit e519710

Browse files
committed
Squiz/OperatorBracket: bug fix - improve recognition of unary minus
The new test was giving _three_ instead of _two_ errors on line 194 for this snippet `$padding * -1 + 3`, with the errors being thrown on the `*`, `-` and the `+` operators. The `-` operator, however, is a unary operator and should not trigger this error. Fixed now.
1 parent 94c9448 commit e519710

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/Standards/Squiz/Sniffs/Formatting/OperatorBracketSniff.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ public function process(File $phpcsFile, $stackPtr)
8080
$isAssignment = isset(Tokens::$assignmentTokens[$tokens[$previous]['code']]);
8181
$isEquality = isset(Tokens::$equalityTokens[$tokens[$previous]['code']]);
8282
$isComparison = isset(Tokens::$comparisonTokens[$tokens[$previous]['code']]);
83-
if ($isAssignment === true || $isEquality === true || $isComparison === true) {
83+
$isUnary = isset(Tokens::$operators[$tokens[$previous]['code']]);
84+
if ($isAssignment === true || $isEquality === true || $isComparison === true || $isUnary === true) {
8485
// This is a negative assignment or comparison.
8586
// We need to check that the minus and the number are
8687
// adjacent.

src/Standards/Squiz/Tests/Formatting/OperatorBracketUnitTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function getErrorList($testFile='OperatorBracketUnitTest.inc')
7171
185 => 1,
7272
189 => 1,
7373
193 => 1,
74-
194 => 3,
74+
194 => 2,
7575
];
7676
break;
7777
case 'OperatorBracketUnitTest.js':

0 commit comments

Comments
 (0)