Do not crash if comment is missing completely
All checks were successful
ci/woodpecker/push/code-style Pipeline was successful
ci/woodpecker/push/test Pipeline was successful

This commit is contained in:
Ferdinand Kuhl 2022-05-17 13:44:01 +02:00
parent 51ef90ecac
commit 2478c0f3ff
2 changed files with 13 additions and 2 deletions

View file

@ -22,8 +22,15 @@ class VariableCommentSniff extends \PHP_CodeSniffer\Standards\Squiz\Sniffs\Comme
]; ];
$commentEnd = $phpcsFile->findPrevious($ignore, ($stackPtr - 1), null, true); $commentEnd = $phpcsFile->findPrevious($ignore, ($stackPtr - 1), null, true);
// this error is copied from above, as it comes with a needed early return
if (
$commentEnd === false
|| ($tokens[$commentEnd]['code'] !== \T_DOC_COMMENT_CLOSE_TAG
&& $tokens[$commentEnd]['code'] !== \T_COMMENT)
) {
$phpcsFile->addError('Missing member variable doc comment', $stackPtr, 'Missing');
return;
}
$commentStart = $tokens[$commentEnd]['comment_opener']; $commentStart = $tokens[$commentEnd]['comment_opener'];
$foundVar = null; $foundVar = null;

View file

@ -20,3 +20,7 @@ class C extends A {
*/ */
protected $var; protected $var;
} }
class D extends a {
protected $var;
}