Skip to content

Commit

Permalink
Merge pull request #197 from PHPCSStandards/feature/operators-isunary…
Browse files Browse the repository at this point in the history
…plusminus-bug-with-arrow-functions

Operators::isUnaryPlusMinus(): bug fix - unary after arrow in arrow function
  • Loading branch information
jrfnl committed Sep 8, 2020
2 parents a9e6ce5 + d3535eb commit 70ea51d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions PHPCSUtils/Utils/Operators.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ public static function isUnaryPlusMinus(File $phpcsFile, $stackPtr)
|| isset(BCTokens::assignmentTokens()[$tokens[$prev]['code']]) === true
|| isset(Tokens::$castTokens[$tokens[$prev]['code']]) === true
|| isset(self::$extraUnaryIndicators[$tokens[$prev]['code']]) === true
|| $tokens[$prev]['type'] === 'T_FN_ARROW'
) {
return true;
}
Expand Down
3 changes: 3 additions & 0 deletions Tests/Utils/Operators/IsUnaryPlusMinusTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ switch ($a) {
break +1;
}

/* testUnaryMinusArrowFunction */
$fn = static fn(DateTime $a, DateTime $b): int => -($a->getTimestamp() <=> $b->getTimestamp());

// Testing `$a = -+-+10`;
$a =
/* testSequenceNonUnary1 */
Expand Down
6 changes: 5 additions & 1 deletion Tests/Utils/Operators/IsUnaryPlusMinusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,14 @@ public function dataIsUnaryPlusMinus()
'/* testUnaryMinusCase */',
true,
],
'unary-minus-break' => [
'unary-plus-break' => [
'/* testUnaryPlusBreak */',
true,
],
'unary-minus-arrow-function' => [
'/* testUnaryMinusArrowFunction */',
true,
],
'operator-sequence-non-unary-1' => [
'/* testSequenceNonUnary1 */',
false,
Expand Down

0 comments on commit 70ea51d

Please sign in to comment.