Skip to content

Commit 49de503

Browse files
committed
PSR12/Squiz/OperatorSpacing: bug fix with arrow functions
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.
1 parent 9cce685 commit 49de503

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

src/Standards/Squiz/Sniffs/WhiteSpace/OperatorSpacingSniff.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ protected function isOperator(File $phpcsFile, $stackPtr)
345345
$function = $tokens[$bracket]['parenthesis_owner'];
346346
if ($tokens[$function]['code'] === T_FUNCTION
347347
|| $tokens[$function]['code'] === T_CLOSURE
348+
|| $tokens[$function]['code'] === T_FN
348349
|| $tokens[$function]['code'] === T_DECLARE
349350
) {
350351
return false;

src/Standards/Squiz/Tests/WhiteSpace/OperatorSpacingUnitTest.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,5 +465,10 @@ $a = $a ? - $b : - $b;
465465

466466
exit -1;
467467

468+
$cl = function ($boo =-1) {};
469+
$cl = function ($boo =+1) {};
470+
$fn = fn ($boo =-1) => $boo;
471+
$fn = fn ($boo =+1) => $boo;
472+
468473
/* Intentional parse error. This has to be the last test in the file. */
469474
$a = 10 +

src/Standards/Squiz/Tests/WhiteSpace/OperatorSpacingUnitTest.inc.fixed

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,5 +459,10 @@ $a = $a ? - $b : - $b;
459459

460460
exit -1;
461461

462+
$cl = function ($boo =-1) {};
463+
$cl = function ($boo =+1) {};
464+
$fn = fn ($boo =-1) => $boo;
465+
$fn = fn ($boo =+1) => $boo;
466+
462467
/* Intentional parse error. This has to be the last test in the file. */
463468
$a = 10 +

0 commit comments

Comments
 (0)