Skip to content

Commit

Permalink
PSR12/Squiz/OperatorSpacing: bug fix with arrow functions
Browse files Browse the repository at this point in the history
The plus/minus in a default value of a function parameter declaration is ignored for normal functions and closures, but wasn't ignored yet for arrow functions.

Fixed now.

Includes unit test + test for the same for closures, which so far wasn't tested yet.

This also, by extension, fixes the same issue in the `PSR12.Operators.OperatorSpacing` sniff.
  • Loading branch information
jrfnl authored and gsherwood committed Sep 29, 2020
1 parent 4897e74 commit a20ff6d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ protected function isOperator(File $phpcsFile, $stackPtr)
$function = $tokens[$bracket]['parenthesis_owner'];
if ($tokens[$function]['code'] === T_FUNCTION
|| $tokens[$function]['code'] === T_CLOSURE
|| $tokens[$function]['code'] === T_FN
|| $tokens[$function]['code'] === T_DECLARE
) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,5 +465,10 @@ $a = $a ? - $b : - $b;

exit -1;

$cl = function ($boo =-1) {};
$cl = function ($boo =+1) {};
$fn = fn ($boo =-1) => $boo;
$fn = fn ($boo =+1) => $boo;

/* 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 @@ -459,5 +459,10 @@ $a = $a ? - $b : - $b;

exit -1;

$cl = function ($boo =-1) {};
$cl = function ($boo =+1) {};
$fn = fn ($boo =-1) => $boo;
$fn = fn ($boo =+1) => $boo;

/* Intentional parse error. This has to be the last test in the file. */
$a = 10 +

0 comments on commit a20ff6d

Please sign in to comment.