Skip to content

Commit efcd173

Browse files
committed
Merge branch 'feature/3043/psr12-operatorspacing-bug-with-arrow-functions' of https://github.com/jrfnl/PHP_CodeSniffer
2 parents 9bcc961 + 1b768c5 commit efcd173

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

src/Standards/PSR12/Tests/Operators/OperatorSpacingUnitTest.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,5 @@ $a = [ 'a' => &$something ];
5959

6060
$fn = fn(array &$one) => 1;
6161
$fn = fn(array & $one) => 1;
62+
63+
$fn = static fn(DateTime $a, DateTime $b): int => -($a->getTimestamp() <=> $b->getTimestamp());

src/Standards/PSR12/Tests/Operators/OperatorSpacingUnitTest.inc.fixed

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,5 @@ $a = [ 'a' => &$something ];
5959

6060
$fn = fn(array &$one) => 1;
6161
$fn = fn(array & $one) => 1;
62+
63+
$fn = static fn(DateTime $a, DateTime $b): int => -($a->getTimestamp() <=> $b->getTimestamp());

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

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,12 @@ public function register()
7777

7878
// Returning/printing a negative value; eg. (return -1).
7979
$this->nonOperandTokens += [
80-
T_RETURN => T_RETURN,
81-
T_ECHO => T_ECHO,
82-
T_EXIT => T_EXIT,
83-
T_PRINT => T_PRINT,
84-
T_YIELD => T_YIELD,
80+
T_RETURN => T_RETURN,
81+
T_ECHO => T_ECHO,
82+
T_EXIT => T_EXIT,
83+
T_PRINT => T_PRINT,
84+
T_YIELD => T_YIELD,
85+
T_FN_ARROW => T_FN_ARROW,
8586
];
8687

8788
// Trying to use a negative value; eg. myFunction($var, -2).
@@ -90,7 +91,6 @@ public function register()
9091
T_OPEN_PARENTHESIS => T_OPEN_PARENTHESIS,
9192
T_OPEN_SQUARE_BRACKET => T_OPEN_SQUARE_BRACKET,
9293
T_OPEN_SHORT_ARRAY => T_OPEN_SHORT_ARRAY,
93-
T_DOUBLE_ARROW => T_DOUBLE_ARROW,
9494
T_COLON => T_COLON,
9595
T_INLINE_THEN => T_INLINE_THEN,
9696
T_INLINE_ELSE => T_INLINE_ELSE,
@@ -99,15 +99,7 @@ public function register()
9999
];
100100

101101
// Casting a negative value; eg. (array) -$a.
102-
$this->nonOperandTokens += [
103-
T_ARRAY_CAST => T_ARRAY_CAST,
104-
T_BOOL_CAST => T_BOOL_CAST,
105-
T_DOUBLE_CAST => T_DOUBLE_CAST,
106-
T_INT_CAST => T_INT_CAST,
107-
T_OBJECT_CAST => T_OBJECT_CAST,
108-
T_STRING_CAST => T_STRING_CAST,
109-
T_UNSET_CAST => T_UNSET_CAST,
110-
];
102+
$this->nonOperandTokens += Tokens::$castTokens;
111103

112104
/*
113105
These are the tokens the sniff is looking for.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,5 +470,7 @@ $cl = function ($boo =+1) {};
470470
$fn = fn ($boo =-1) => $boo;
471471
$fn = fn ($boo =+1) => $boo;
472472

473+
$fn = static fn(DateTime $a, DateTime $b): int => -($a->getTimestamp() <=> $b->getTimestamp());
474+
473475
/* Intentional parse error. This has to be the last test in the file. */
474476
$a = 10 +

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,5 +464,7 @@ $cl = function ($boo =+1) {};
464464
$fn = fn ($boo =-1) => $boo;
465465
$fn = fn ($boo =+1) => $boo;
466466

467+
$fn = static fn(DateTime $a, DateTime $b): int => -($a->getTimestamp() <=> $b->getTimestamp());
468+
467469
/* Intentional parse error. This has to be the last test in the file. */
468470
$a = 10 +

0 commit comments

Comments
 (0)