From e35eb8b6be627804dc99c010d48227487c3f76bf Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Tue, 8 Feb 2022 20:59:20 +0100 Subject: [PATCH] Add support for fn --- src/Fixer/Operator/BinaryOperatorSpacesFixer.php | 7 ++++++- tests/Fixer/Operator/BinaryOperatorSpacesFixerTest.php | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Fixer/Operator/BinaryOperatorSpacesFixer.php b/src/Fixer/Operator/BinaryOperatorSpacesFixer.php index 13ab68487dc..1da5fa8ad07 100644 --- a/src/Fixer/Operator/BinaryOperatorSpacesFixer.php +++ b/src/Fixer/Operator/BinaryOperatorSpacesFixer.php @@ -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]; @@ -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); diff --git a/tests/Fixer/Operator/BinaryOperatorSpacesFixerTest.php b/tests/Fixer/Operator/BinaryOperatorSpacesFixerTest.php index c8326c0fe0b..0a200041147 100644 --- a/tests/Fixer/Operator/BinaryOperatorSpacesFixerTest.php +++ b/tests/Fixer/Operator/BinaryOperatorSpacesFixerTest.php @@ -1419,6 +1419,12 @@ function () $d["abc"] = 2; } ); +', + ], + [ + ' $x + 3; +$f = 123; ', ], ];