From daa7ae48cca0e19e320b02c3f3f1176538b6a5c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20Hansl=C3=ADk?= <kukulich@kukulich.cz> Date: Mon, 24 Jul 2023 17:24:58 +0200 Subject: [PATCH] SlevomatCodingStandard.Commenting.DocCommentSpacing: Fixed internal error for invalid doccomment --- .../Sniffs/Commenting/DocCommentSpacingSniff.php | 4 ++++ tests/Sniffs/Commenting/DocCommentSpacingSniffTest.php | 6 ++++++ .../Commenting/data/docCommentSpacingInvalidDocComment.php | 5 +++++ 3 files changed, 15 insertions(+) create mode 100644 tests/Sniffs/Commenting/data/docCommentSpacingInvalidDocComment.php 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 @@ +<?php + +/********* + * Invalid + */