diff --git a/src/Standards/Squiz/Sniffs/Commenting/ClosingDeclarationCommentSniff.php b/src/Standards/Squiz/Sniffs/Commenting/ClosingDeclarationCommentSniff.php index 85c39b3ce3..f059d05f93 100644 --- a/src/Standards/Squiz/Sniffs/Commenting/ClosingDeclarationCommentSniff.php +++ b/src/Standards/Squiz/Sniffs/Commenting/ClosingDeclarationCommentSniff.php @@ -88,7 +88,7 @@ public function process(File $phpcsFile, $stackPtr) $data = [$comment]; if (isset($tokens[($closingBracket + 1)]) === false || $tokens[($closingBracket + 1)]['code'] !== T_COMMENT) { $next = $phpcsFile->findNext(T_WHITESPACE, ($closingBracket + 1), null, true); - if (rtrim($tokens[$next]['content']) === $comment) { + if ($next !== false && rtrim($tokens[$next]['content']) === $comment) { // The comment isn't really missing; it is just in the wrong place. $fix = $phpcsFile->addFixableError('Expected %s directly after closing brace', $closingBracket, 'Misplaced', $data); if ($fix === true) { diff --git a/src/Standards/Squiz/Tests/Commenting/ClosingDeclarationCommentUnitTest.4.inc b/src/Standards/Squiz/Tests/Commenting/ClosingDeclarationCommentUnitTest.4.inc new file mode 100644 index 0000000000..194fd0b2bc --- /dev/null +++ b/src/Standards/Squiz/Tests/Commenting/ClosingDeclarationCommentUnitTest.4.inc @@ -0,0 +1,8 @@ + 1, ]; + case 'ClosingDeclarationCommentUnitTest.4.inc': + return [8 => 1]; + + case 'ClosingDeclarationCommentUnitTest.5.inc': + return [11 => 1]; + default: return []; - } + }//end switch }//end getErrorList()