Skip to content

Commit

Permalink
Add support for fn
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Feb 8, 2022
1 parent fe824f5 commit a033d82
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Fixer/Operator/BinaryOperatorSpacesFixer.php
Expand Up @@ -531,6 +531,11 @@ private function fixAlignment(Tokens $tokens, array $toAlign): void

private function injectAlignmentPlaceholders(Tokens $tokens, int $startAt, int $endAt, string $tokenContent): void
{
$functionKind = [T_FUNCTION];
if (\PHP_VERSION_ID >= 70400) {
$functionKind[] = T_FN;
}

for ($index = $startAt; $index < $endAt; ++$index) {
$token = $tokens[$index];

Expand All @@ -545,7 +550,7 @@ private function injectAlignmentPlaceholders(Tokens $tokens, int $startAt, int $
continue;
}

if ($token->isGivenKind(T_FUNCTION)) {
if ($token->isGivenKind($functionKind)) {
++$this->deepestLevel;
$index = $tokens->getNextTokenOfKind($index, ['(']);
$index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index);
Expand Down
6 changes: 6 additions & 0 deletions tests/Fixer/Operator/BinaryOperatorSpacesFixerTest.php
Expand Up @@ -1421,6 +1421,12 @@ function ()
);
',
],
[
'<?php
fn ($x = 1) => $x + 3;
$f = 123;
'
],
];
}

Expand Down

0 comments on commit a033d82

Please sign in to comment.