Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Squiz/PSR12/OperatorSpacing: bug fix - unary plus/minus in arrow function return #3129

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 +