diff --git a/src/Standards/PEAR/Sniffs/Functions/FunctionDeclarationSniff.php b/src/Standards/PEAR/Sniffs/Functions/FunctionDeclarationSniff.php index 1d0745b98b..93ccd89a2c 100644 --- a/src/Standards/PEAR/Sniffs/Functions/FunctionDeclarationSniff.php +++ b/src/Standards/PEAR/Sniffs/Functions/FunctionDeclarationSniff.php @@ -103,11 +103,10 @@ public function process(File $phpcsFile, $stackPtr) // enforced by the previous check because there is no content between the keywords // and the opening parenthesis. // Unfinished closures are tokenized as T_FUNCTION however, and can be excluded - // by checking for the scope_opener. + // by checking if the function has a name. $methodProps = $phpcsFile->getMethodProperties($stackPtr); - if ($tokens[$stackPtr]['code'] === T_FUNCTION - && (isset($tokens[$stackPtr]['scope_opener']) === true || $methodProps['has_body'] === false) - ) { + $methodName = $phpcsFile->getDeclarationName($stackPtr); + if ($tokens[$stackPtr]['code'] === T_FUNCTION && $methodName !== null) { if ($tokens[($openBracket - 1)]['content'] === $phpcsFile->eolChar) { $spaces = 'newline'; } else if ($tokens[($openBracket - 1)]['code'] === T_WHITESPACE) { diff --git a/src/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.3.inc b/src/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.3.inc new file mode 100644 index 0000000000..f0253bbb3e --- /dev/null +++ b/src/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.3.inc @@ -0,0 +1,7 @@ + 1, ]; + case 'FunctionDeclarationUnitTest.4.inc': + return [ + 7 => 1, + ]; + default: return []; }//end switch