Skip to content

Commit

Permalink
Allow functions to be called fn for backwards compatibility (ref #2523)
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed Nov 7, 2019
1 parent 24b898c commit 37dda44
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Files/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,9 @@ public function getDeclarationName($stackPtr)

$content = null;
for ($i = $stackPtr; $i < $this->numTokens; $i++) {
if ($this->tokens[$i]['code'] === T_STRING) {
if ($this->tokens[$i]['code'] === T_STRING
|| $this->tokens[$i]['code'] === T_FN
) {
$content = $this->tokens[$i]['content'];
break;
}
Expand Down
4 changes: 3 additions & 1 deletion src/Sniffs/AbstractPatternSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,9 @@ protected function processPattern($patternInfo, File $phpcsFile, $stackPtr)
$stackPtr = ($tokens[$next][$pattern[$i]['to']] + 1);
}//end if
} else if ($pattern[$i]['type'] === 'string') {
if ($tokens[$stackPtr]['code'] !== T_STRING) {
if ($tokens[$stackPtr]['code'] !== T_STRING
&& $tokens[$stackPtr]['code'] !== T_FN
) {
$hasError = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,4 @@ function self() {}
function false() {}
function true() {}
function null() {}
function fn() {}

0 comments on commit 37dda44

Please sign in to comment.