diff --git a/src/Standards/PEAR/Sniffs/Functions/FunctionDeclarationSniff.php b/src/Standards/PEAR/Sniffs/Functions/FunctionDeclarationSniff.php index d5374882d1..1d0745b98b 100644 --- a/src/Standards/PEAR/Sniffs/Functions/FunctionDeclarationSniff.php +++ b/src/Standards/PEAR/Sniffs/Functions/FunctionDeclarationSniff.php @@ -128,23 +128,25 @@ public function process(File $phpcsFile, $stackPtr) // Must be no space before semicolon in abstract/interface methods. if ($methodProps['has_body'] === false) { $end = $phpcsFile->findNext(T_SEMICOLON, $closeBracket); - if ($tokens[($end - 1)]['content'] === $phpcsFile->eolChar) { - $spaces = 'newline'; - } else if ($tokens[($end - 1)]['code'] === T_WHITESPACE) { - $spaces = $tokens[($end - 1)]['length']; - } else { - $spaces = 0; - } + if ($end !== false) { + if ($tokens[($end - 1)]['content'] === $phpcsFile->eolChar) { + $spaces = 'newline'; + } else if ($tokens[($end - 1)]['code'] === T_WHITESPACE) { + $spaces = $tokens[($end - 1)]['length']; + } else { + $spaces = 0; + } - if ($spaces !== 0) { - $error = 'Expected 0 spaces before semicolon; %s found'; - $data = [$spaces]; - $fix = $phpcsFile->addFixableError($error, $end, 'SpaceBeforeSemicolon', $data); - if ($fix === true) { - $phpcsFile->fixer->replaceToken(($end - 1), ''); + if ($spaces !== 0) { + $error = 'Expected 0 spaces before semicolon; %s found'; + $data = [$spaces]; + $fix = $phpcsFile->addFixableError($error, $end, 'SpaceBeforeSemicolon', $data); + if ($fix === true) { + $phpcsFile->fixer->replaceToken(($end - 1), ''); + } } } - } + }//end if }//end if // Must be one space before and after USE keyword for closures. diff --git a/src/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.2.inc b/src/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.2.inc new file mode 100644 index 0000000000..719f703b0d --- /dev/null +++ b/src/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.2.inc @@ -0,0 +1,7 @@ +