diff --git a/src/Files/File.php b/src/Files/File.php index 2ccd834784..dd9a245178 100644 --- a/src/Files/File.php +++ b/src/Files/File.php @@ -2356,10 +2356,12 @@ public function findEndOfStatement($start, $ignore=null) && ($i === $this->tokens[$i]['scope_opener'] || $i === $this->tokens[$i]['scope_condition']) ) { - if ($i === $start - && (isset(Util\Tokens::$scopeOpeners[$this->tokens[$i]['code']]) === true - || $this->tokens[$i]['code'] === T_FN) - ) { + if ($this->tokens[$i]['code'] === T_FN) { + $i = ($this->tokens[$i]['scope_closer'] - 1); + continue; + } + + if ($i === $start && isset(Util\Tokens::$scopeOpeners[$this->tokens[$i]['code']]) === true) { return $this->tokens[$i]['scope_closer']; } diff --git a/tests/Core/Tokenizer/BackfillFnTokenTest.inc b/tests/Core/Tokenizer/BackfillFnTokenTest.inc index 0bff299369..6a274ed6d1 100644 --- a/tests/Core/Tokenizer/BackfillFnTokenTest.inc +++ b/tests/Core/Tokenizer/BackfillFnTokenTest.inc @@ -69,3 +69,8 @@ fn(callable $a) : callable => $a; /* testTernary */ $fn = fn($a) => $a ? /* testTernaryThen */ fn() : string => 'a' : /* testTernaryElse */ fn() : string => 'b'; + +/* testEndOfStatement */ +static fn ($a) => $a; + +return 0; diff --git a/tests/Core/Tokenizer/BackfillFnTokenTest.php b/tests/Core/Tokenizer/BackfillFnTokenTest.php index 4132335680..a96b3be2fa 100644 --- a/tests/Core/Tokenizer/BackfillFnTokenTest.php +++ b/tests/Core/Tokenizer/BackfillFnTokenTest.php @@ -594,4 +594,23 @@ private function backfillHelper($token) }//end backfillHelper() + /** + * Test end of statement for fn closure. + * + * @return void + */ + public function testEndOfStatement() + { + $token = $this->getTargetToken('/* testEndOfStatement */', T_FN); + $this->backfillHelper($token); + + $static = self::$phpcsFile->findPrevious(T_STATIC, ($token - 1)); + $endOfStatementStatic = self::$phpcsFile->findEndOfStatement($static); + $endOfStatementFn = self::$phpcsFile->findEndOfStatement($token); + + $this->assertSame($endOfStatementFn, $endOfStatementStatic); + + }//end testEndOfStatement() + + }//end class