Skip to content

Commit b8e7f59

Browse files
committed
SlevomatCodingStandard.Commenting.DocCommentSpacing: Some more fixes
1 parent 9936be6 commit b8e7f59

File tree

6 files changed

+31
-5
lines changed

6 files changed

+31
-5
lines changed

SlevomatCodingStandard/Helpers/AnnotationHelper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
use PHPStan\PhpDocParser\Ast\Type\ObjectShapeItemNode;
2626
use PHPStan\PhpDocParser\Ast\Type\ObjectShapeNode;
2727
use PHPStan\PhpDocParser\Ast\Type\UnionTypeNode;
28+
use function array_merge;
2829
use function count;
2930
use function in_array;
3031
use function sprintf;
3132
use function strlen;
3233
use function strtolower;
3334
use const T_DOC_COMMENT_STAR;
3435
use const T_DOC_COMMENT_STRING;
35-
use const T_DOC_COMMENT_TAG;
3636
use const T_DOC_COMMENT_WHITESPACE;
3737

3838
/**
@@ -358,7 +358,7 @@ private static function getEndPointer(
358358
while (true) {
359359
$nextPointer = TokenHelper::findNext(
360360
$phpcsFile,
361-
[T_DOC_COMMENT_TAG, T_DOC_COMMENT_STRING],
361+
array_merge(TokenHelper::$annotationTokenCodes, [T_DOC_COMMENT_STRING]),
362362
$nextPointer + 1,
363363
$parsedDocComment->getClosePointer()
364364
);
@@ -367,7 +367,7 @@ private static function getEndPointer(
367367
break;
368368
}
369369

370-
if ($tokens[$nextPointer]['code'] === T_DOC_COMMENT_TAG) {
370+
if (in_array($tokens[$nextPointer]['code'], TokenHelper::$annotationTokenCodes, true)) {
371371
break;
372372
}
373373

SlevomatCodingStandard/Sniffs/Commenting/DocCommentSpacingSniff.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use function array_key_exists;
1818
use function array_keys;
1919
use function array_map;
20+
use function array_merge;
2021
use function array_values;
2122
use function asort;
2223
use function count;
@@ -139,7 +140,14 @@ public function process(File $phpcsFile, $docCommentOpenerPointer): void
139140

140141
$firstAnnotationPointer = $annotationsCount > 0 ? $annotations[0]->getStartPointer() : null;
141142

142-
$lastContentEndPointer = $annotationsCount > 0 ? $annotations[$annotationsCount - 1]->getEndPointer() : $firstContentEndPointer;
143+
/** @var int $lastContentEndPointer */
144+
$lastContentEndPointer = $annotationsCount > 0
145+
? TokenHelper::findPrevious(
146+
$phpcsFile,
147+
array_merge(TokenHelper::$annotationTokenCodes, [T_DOC_COMMENT_STRING]),
148+
$tokens[$docCommentOpenerPointer]['comment_closer'] - 1
149+
)
150+
: $firstContentEndPointer;
143151

144152
$this->checkLinesBeforeFirstContent($phpcsFile, $docCommentOpenerPointer, $firstContentStartPointer);
145153
$this->checkLinesBetweenDescriptionAndFirstAnnotation(

tests/Sniffs/Commenting/DocCommentSpacingSniffTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function testDefaultSettingsErrors(): void
4646
{
4747
$report = self::checkFile(__DIR__ . '/data/docCommentSpacingDefaultSettingsErrors.php');
4848

49-
self::assertSame(10, $report->getErrorCount());
49+
self::assertSame(11, $report->getErrorCount());
5050

5151
self::assertSniffError($report, 5, DocCommentSpacingSniff::CODE_INCORRECT_LINES_COUNT_BEFORE_FIRST_CONTENT);
5252
self::assertSniffError($report, 26, DocCommentSpacingSniff::CODE_INCORRECT_LINES_COUNT_BEFORE_FIRST_CONTENT);
@@ -62,6 +62,7 @@ public function testDefaultSettingsErrors(): void
6262
self::assertSniffError($report, 42, DocCommentSpacingSniff::CODE_INCORRECT_LINES_COUNT_AFTER_LAST_CONTENT);
6363

6464
self::assertSniffError($report, 77, DocCommentSpacingSniff::CODE_INCORRECT_LINES_COUNT_BETWEEN_DIFFERENT_ANNOTATIONS_TYPES);
65+
self::assertSniffError($report, 101, DocCommentSpacingSniff::CODE_INCORRECT_LINES_COUNT_BETWEEN_DIFFERENT_ANNOTATIONS_TYPES);
6566

6667
self::assertAllFixedInFile($report);
6768
}

tests/Sniffs/Commenting/data/docCommentSpacingDefaultSettingsErrors.fixed.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class Doctrine
8484
* lifetime: 600
8585
* cache_driver:
8686
* type: apc
87+
* @phpcs:enable
8788
*/
8889
public function method()
8990
{

tests/Sniffs/Commenting/data/docCommentSpacingDefaultSettingsErrors.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ class Doctrine
9696
* lifetime: 600
9797
* cache_driver:
9898
* type: apc
99+
*
100+
*
101+
* @phpcs:enable
99102
*/
100103
public function method()
101104
{

tests/Sniffs/Commenting/data/docCommentSpacingDefaultSettingsNoErrors.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,17 @@ public function method()
3131

3232
}
3333

34+
/**
35+
* @group GH-6362
36+
*
37+
* SELECT a as base, b, c, d
38+
* FROM Start a
39+
* LEFT JOIN a.bases b
40+
* LEFT JOIN Child c WITH b.id = c.id
41+
* LEFT JOIN c.joins d
42+
*/
43+
public function descriptionAfterAnnotation()
44+
{
45+
}
46+
3447
}

0 commit comments

Comments
 (0)