diff --git a/SlevomatCodingStandard/Sniffs/Commenting/DocCommentSpacingSniff.php b/SlevomatCodingStandard/Sniffs/Commenting/DocCommentSpacingSniff.php index 7cee53eda..f2ac58b73 100644 --- a/SlevomatCodingStandard/Sniffs/Commenting/DocCommentSpacingSniff.php +++ b/SlevomatCodingStandard/Sniffs/Commenting/DocCommentSpacingSniff.php @@ -112,6 +112,10 @@ public function process(File $phpcsFile, $docCommentOpenerPointer): void $parsedDocComment = DocCommentHelper::parseDocComment($phpcsFile, $docCommentOpenerPointer); + if ($parsedDocComment === null) { + return; + } + $firstContentStartPointer = $parsedDocComment->getNodeStartPointer($phpcsFile, $parsedDocComment->getNode()->children[0]); $firstContentEndPointer = $parsedDocComment->getNodeEndPointer( $phpcsFile, diff --git a/tests/Sniffs/Commenting/DocCommentSpacingSniffTest.php b/tests/Sniffs/Commenting/DocCommentSpacingSniffTest.php index 64a4ecc42..ec9022ba8 100644 --- a/tests/Sniffs/Commenting/DocCommentSpacingSniffTest.php +++ b/tests/Sniffs/Commenting/DocCommentSpacingSniffTest.php @@ -13,6 +13,12 @@ public function testEmptyDocComment(): void self::assertNoSniffErrorInFile($report); } + public function testInvalidDocComment(): void + { + $report = self::checkFile(__DIR__ . '/data/docCommentSpacingInvalidDocComment.php'); + self::assertNoSniffErrorInFile($report); + } + public function testInlineDocComment(): void { $report = self::checkFile(__DIR__ . '/data/docCommentSpacingInlineDocComment.php'); diff --git a/tests/Sniffs/Commenting/data/docCommentSpacingInvalidDocComment.php b/tests/Sniffs/Commenting/data/docCommentSpacingInvalidDocComment.php new file mode 100644 index 000000000..7f9e18883 --- /dev/null +++ b/tests/Sniffs/Commenting/data/docCommentSpacingInvalidDocComment.php @@ -0,0 +1,5 @@ +