Skip to content

Commit

Permalink
Merge branch 'feature/3043/psr12-operatorspacing-bug-with-arrow-funct…
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed Oct 13, 2020
2 parents 9bcc961 + 1b768c5 commit efcd173
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ $a = [ 'a' => &$something ];

$fn = fn(array &$one) => 1;
$fn = fn(array & $one) => 1;

$fn = static fn(DateTime $a, DateTime $b): int => -($a->getTimestamp() <=> $b->getTimestamp());
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ $a = [ 'a' => &$something ];

$fn = fn(array &$one) => 1;
$fn = fn(array & $one) => 1;

$fn = static fn(DateTime $a, DateTime $b): int => -($a->getTimestamp() <=> $b->getTimestamp());
22 changes: 7 additions & 15 deletions src/Standards/Squiz/Sniffs/WhiteSpace/OperatorSpacingSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@ public function register()

// Returning/printing a negative value; eg. (return -1).
$this->nonOperandTokens += [
T_RETURN => T_RETURN,
T_ECHO => T_ECHO,
T_EXIT => T_EXIT,
T_PRINT => T_PRINT,
T_YIELD => T_YIELD,
T_RETURN => T_RETURN,
T_ECHO => T_ECHO,
T_EXIT => T_EXIT,
T_PRINT => T_PRINT,
T_YIELD => T_YIELD,
T_FN_ARROW => T_FN_ARROW,
];

// Trying to use a negative value; eg. myFunction($var, -2).
Expand All @@ -90,7 +91,6 @@ public function register()
T_OPEN_PARENTHESIS => T_OPEN_PARENTHESIS,
T_OPEN_SQUARE_BRACKET => T_OPEN_SQUARE_BRACKET,
T_OPEN_SHORT_ARRAY => T_OPEN_SHORT_ARRAY,
T_DOUBLE_ARROW => T_DOUBLE_ARROW,
T_COLON => T_COLON,
T_INLINE_THEN => T_INLINE_THEN,
T_INLINE_ELSE => T_INLINE_ELSE,
Expand All @@ -99,15 +99,7 @@ public function register()
];

// Casting a negative value; eg. (array) -$a.
$this->nonOperandTokens += [
T_ARRAY_CAST => T_ARRAY_CAST,
T_BOOL_CAST => T_BOOL_CAST,
T_DOUBLE_CAST => T_DOUBLE_CAST,
T_INT_CAST => T_INT_CAST,
T_OBJECT_CAST => T_OBJECT_CAST,
T_STRING_CAST => T_STRING_CAST,
T_UNSET_CAST => T_UNSET_CAST,
];
$this->nonOperandTokens += Tokens::$castTokens;

/*
These are the tokens the sniff is looking for.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,5 +470,7 @@ $cl = function ($boo =+1) {};
$fn = fn ($boo =-1) => $boo;
$fn = fn ($boo =+1) => $boo;

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

/* 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 @@ -464,5 +464,7 @@ $cl = function ($boo =+1) {};
$fn = fn ($boo =-1) => $boo;
$fn = fn ($boo =+1) => $boo;

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

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

0 comments on commit efcd173

Please sign in to comment.