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 committed Sep 5, 2020
1 parent 1371c59 commit 285fff5
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 @@ -344,6 +344,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 @@ -463,5 +463,10 @@ $a = [$a, - $b];
$a = $a[- $b];
$a = $a ? - $b : - $b;

$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 @@ -457,5 +457,10 @@ $a = [$a, - $b];
$a = $a[- $b];
$a = $a ? - $b : - $b;

$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 285fff5

Please sign in to comment.