Skip to content

Commit 37dda44

Browse files
committed
Allow functions to be called fn for backwards compatibility (ref #2523)
1 parent 24b898c commit 37dda44

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

src/Files/File.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,9 @@ public function getDeclarationName($stackPtr)
12541254

12551255
$content = null;
12561256
for ($i = $stackPtr; $i < $this->numTokens; $i++) {
1257-
if ($this->tokens[$i]['code'] === T_STRING) {
1257+
if ($this->tokens[$i]['code'] === T_STRING
1258+
|| $this->tokens[$i]['code'] === T_FN
1259+
) {
12581260
$content = $this->tokens[$i]['content'];
12591261
break;
12601262
}

src/Sniffs/AbstractPatternSniff.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,9 @@ protected function processPattern($patternInfo, File $phpcsFile, $stackPtr)
614614
$stackPtr = ($tokens[$next][$pattern[$i]['to']] + 1);
615615
}//end if
616616
} else if ($pattern[$i]['type'] === 'string') {
617-
if ($tokens[$stackPtr]['code'] !== T_STRING) {
617+
if ($tokens[$stackPtr]['code'] !== T_STRING
618+
&& $tokens[$stackPtr]['code'] !== T_FN
619+
) {
618620
$hasError = true;
619621
}
620622

src/Standards/Squiz/Tests/Functions/FunctionDeclarationUnitTest.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,4 @@ function self() {}
7272
function false() {}
7373
function true() {}
7474
function null() {}
75+
function fn() {}

0 commit comments

Comments
 (0)