Skip to content

Commit

Permalink
Merge branch 'hotfix/end-of-statement-fn-closure' of https://github.c…
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed Jan 6, 2020
2 parents 22b243a + 17f5e17 commit a922594
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Files/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}

Expand Down
5 changes: 5 additions & 0 deletions tests/Core/File/FindEndOfStatementTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ $a = [
'a' => fn() => return 1,
'b' => fn() => return 1,
];

/* testArrowFunctionEndOfStatement */
static fn ($a) => $a;

return 0;
18 changes: 18 additions & 0 deletions tests/Core/File/FindEndOfStatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,22 @@ public function testArrowFunctionArrayValue()
}//end testArrowFunctionArrayValue()


/**
* Test end of statement for fn closure.
*
* @return void
*/
public function testArrayFunctionEndOfStatement()
{
$static = (self::$phpcsFile->findNext(T_COMMENT, 0, null, false, '/* testArrowFunctionEndOfStatement */') + 2);
$fn = self::$phpcsFile->findNext(T_FN, ($static + 1));

$endOfStatementStatic = self::$phpcsFile->findEndOfStatement($static);
$endOfStatementFn = self::$phpcsFile->findEndOfStatement($fn);

$this->assertSame($endOfStatementFn, $endOfStatementStatic);

}//end testArrayFunctionEndOfStatement()


}//end class

0 comments on commit a922594

Please sign in to comment.