Skip to content

Commit a922594

Browse files
committed
Merge branch 'hotfix/end-of-statement-fn-closure' of https://github.com/michalbundyra/PHP_CodeSniffer
2 parents 22b243a + 17f5e17 commit a922594

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

src/Files/File.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2356,10 +2356,12 @@ public function findEndOfStatement($start, $ignore=null)
23562356
&& ($i === $this->tokens[$i]['scope_opener']
23572357
|| $i === $this->tokens[$i]['scope_condition'])
23582358
) {
2359-
if ($i === $start
2360-
&& (isset(Util\Tokens::$scopeOpeners[$this->tokens[$i]['code']]) === true
2361-
|| $this->tokens[$i]['code'] === T_FN)
2362-
) {
2359+
if ($this->tokens[$i]['code'] === T_FN) {
2360+
$i = ($this->tokens[$i]['scope_closer'] - 1);
2361+
continue;
2362+
}
2363+
2364+
if ($i === $start && isset(Util\Tokens::$scopeOpeners[$this->tokens[$i]['code']]) === true) {
23632365
return $this->tokens[$i]['scope_closer'];
23642366
}
23652367

tests/Core/File/FindEndOfStatementTest.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,8 @@ $a = [
3535
'a' => fn() => return 1,
3636
'b' => fn() => return 1,
3737
];
38+
39+
/* testArrowFunctionEndOfStatement */
40+
static fn ($a) => $a;
41+
42+
return 0;

tests/Core/File/FindEndOfStatementTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,22 @@ public function testArrowFunctionArrayValue()
188188
}//end testArrowFunctionArrayValue()
189189

190190

191+
/**
192+
* Test end of statement for fn closure.
193+
*
194+
* @return void
195+
*/
196+
public function testArrayFunctionEndOfStatement()
197+
{
198+
$static = (self::$phpcsFile->findNext(T_COMMENT, 0, null, false, '/* testArrowFunctionEndOfStatement */') + 2);
199+
$fn = self::$phpcsFile->findNext(T_FN, ($static + 1));
200+
201+
$endOfStatementStatic = self::$phpcsFile->findEndOfStatement($static);
202+
$endOfStatementFn = self::$phpcsFile->findEndOfStatement($fn);
203+
204+
$this->assertSame($endOfStatementFn, $endOfStatementStatic);
205+
206+
}//end testArrayFunctionEndOfStatement()
207+
208+
191209
}//end class

0 commit comments

Comments
 (0)