Skip to content

Commit 9936be6

Browse files
committed
Improved detection of annotation end
1 parent c0cf361 commit 9936be6

File tree

6 files changed

+196
-2
lines changed

6 files changed

+196
-2
lines changed

SlevomatCodingStandard/Helpers/AnnotationHelper.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
use function sprintf;
3131
use function strlen;
3232
use function strtolower;
33+
use const T_DOC_COMMENT_STAR;
34+
use const T_DOC_COMMENT_STRING;
35+
use const T_DOC_COMMENT_TAG;
36+
use const T_DOC_COMMENT_WHITESPACE;
3337

3438
/**
3539
* @internal
@@ -350,6 +354,39 @@ private static function getEndPointer(
350354
}
351355
}
352356

357+
$nextPointer = $searchPointer;
358+
while (true) {
359+
$nextPointer = TokenHelper::findNext(
360+
$phpcsFile,
361+
[T_DOC_COMMENT_TAG, T_DOC_COMMENT_STRING],
362+
$nextPointer + 1,
363+
$parsedDocComment->getClosePointer()
364+
);
365+
366+
if ($nextPointer === null) {
367+
break;
368+
}
369+
370+
if ($tokens[$nextPointer]['code'] === T_DOC_COMMENT_TAG) {
371+
break;
372+
}
373+
374+
if (
375+
$tokens[$searchPointer]['line'] + 1 !== $tokens[$nextPointer]['line']
376+
&& (
377+
$tokens[$nextPointer - 1]['code'] === T_DOC_COMMENT_STAR
378+
|| (
379+
$tokens[$nextPointer - 1]['code'] === T_DOC_COMMENT_WHITESPACE
380+
&& strlen($tokens[$nextPointer - 1]['content']) === 1
381+
)
382+
)
383+
) {
384+
break;
385+
}
386+
387+
$searchPointer = $nextPointer;
388+
}
389+
353390
return $searchPointer;
354391
}
355392

tests/Sniffs/Commenting/DocCommentSpacingSniffTest.php

Lines changed: 5 additions & 2 deletions
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(9, $report->getErrorCount());
49+
self::assertSame(10, $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);
@@ -61,6 +61,8 @@ public function testDefaultSettingsErrors(): void
6161
self::assertSniffError($report, 9, DocCommentSpacingSniff::CODE_INCORRECT_LINES_COUNT_AFTER_LAST_CONTENT);
6262
self::assertSniffError($report, 42, DocCommentSpacingSniff::CODE_INCORRECT_LINES_COUNT_AFTER_LAST_CONTENT);
6363

64+
self::assertSniffError($report, 77, DocCommentSpacingSniff::CODE_INCORRECT_LINES_COUNT_BETWEEN_DIFFERENT_ANNOTATIONS_TYPES);
65+
6466
self::assertAllFixedInFile($report);
6567
}
6668

@@ -149,7 +151,7 @@ public function testAnnotationsGroupsErrors(): void
149151
DocCommentSpacingSniff::CODE_INCORRECT_ORDER_OF_ANNOTATIONS_IN_GROUP,
150152
]);
151153

152-
self::assertSame(11, $report->getErrorCount());
154+
self::assertSame(12, $report->getErrorCount());
153155

154156
self::assertSniffError($report, 12, DocCommentSpacingSniff::CODE_INCORRECT_ORDER_OF_ANNOTATIONS_GROUPS);
155157
self::assertSniffError($report, 23, DocCommentSpacingSniff::CODE_INCORRECT_ANNOTATIONS_GROUP);
@@ -162,6 +164,7 @@ public function testAnnotationsGroupsErrors(): void
162164
self::assertSniffError($report, 95, DocCommentSpacingSniff::CODE_INCORRECT_ANNOTATIONS_GROUP);
163165
self::assertSniffError($report, 105, DocCommentSpacingSniff::CODE_INCORRECT_ANNOTATIONS_GROUP);
164166
self::assertSniffError($report, 118, DocCommentSpacingSniff::CODE_INCORRECT_ANNOTATIONS_GROUP);
167+
self::assertSniffError($report, 133, DocCommentSpacingSniff::CODE_INCORRECT_ANNOTATIONS_GROUP);
165168

166169
self::assertAllFixedInFile($report);
167170
}

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,42 @@ public function phpstanReturnAndReturnAnnotations()
127127
}
128128

129129
}
130+
131+
class Doctrine
132+
{
133+
134+
/**
135+
* Loads an ORM second level cache bundle mapping information.
136+
*
137+
* @param array<string, mixed> $entityManager A configured ORM entity manager
138+
* @param Definition $ormConfigDef A Definition instance
139+
* @param ContainerBuilder $container A ContainerBuilder instance
140+
*
141+
* @example
142+
* entity_managers:
143+
* default:
144+
* second_level_cache:
145+
* region_lifetime: 3600
146+
* region_lock_lifetime: 60
147+
* region_cache_driver: apc
148+
* log_enabled: true
149+
* regions:
150+
* my_service_region:
151+
* type: service
152+
* service : "my_service_region"
153+
*
154+
* my_query_region:
155+
* lifetime: 300
156+
* cache_driver: array
157+
* type: filelock
158+
*
159+
* my_entity_region:
160+
* lifetime: 600
161+
* cache_driver:
162+
* type: apc
163+
*/
164+
public function method()
165+
{
166+
}
167+
168+
}

tests/Sniffs/Commenting/data/docCommentSpacingAnnotationsGroupsErrors.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,41 @@ public function phpstanReturnAndReturnAnnotations()
123123
}
124124

125125
}
126+
127+
class Doctrine
128+
{
129+
130+
/**
131+
* Loads an ORM second level cache bundle mapping information.
132+
*
133+
* @param array<string, mixed> $entityManager A configured ORM entity manager
134+
* @example
135+
* entity_managers:
136+
* default:
137+
* second_level_cache:
138+
* region_lifetime: 3600
139+
* region_lock_lifetime: 60
140+
* region_cache_driver: apc
141+
* log_enabled: true
142+
* regions:
143+
* my_service_region:
144+
* type: service
145+
* service : "my_service_region"
146+
*
147+
* my_query_region:
148+
* lifetime: 300
149+
* cache_driver: array
150+
* type: filelock
151+
*
152+
* my_entity_region:
153+
* lifetime: 600
154+
* cache_driver:
155+
* type: apc
156+
* @param Definition $ormConfigDef A Definition instance
157+
* @param ContainerBuilder $container A ContainerBuilder instance
158+
*/
159+
public function method()
160+
{
161+
}
162+
163+
}

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,41 @@ public function anotherMethod()
5252
}
5353

5454
}
55+
56+
class Doctrine
57+
{
58+
59+
/**
60+
* Loads an ORM second level cache bundle mapping information.
61+
*
62+
* @param array<string, mixed> $entityManager A configured ORM entity manager
63+
* @param Definition $ormConfigDef A Definition instance
64+
* @param ContainerBuilder $container A ContainerBuilder instance
65+
* @example
66+
* entity_managers:
67+
* default:
68+
* second_level_cache:
69+
* region_lifetime: 3600
70+
* region_lock_lifetime: 60
71+
* region_cache_driver: apc
72+
* log_enabled: true
73+
* regions:
74+
* my_service_region:
75+
* type: service
76+
* service : "my_service_region"
77+
*
78+
* my_query_region:
79+
* lifetime: 300
80+
* cache_driver: array
81+
* type: filelock
82+
*
83+
* my_entity_region:
84+
* lifetime: 600
85+
* cache_driver:
86+
* type: apc
87+
*/
88+
public function method()
89+
{
90+
}
91+
92+
}

tests/Sniffs/Commenting/data/docCommentSpacingDefaultSettingsErrors.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,42 @@ public function anotherMethod()
6363
}
6464

6565
}
66+
67+
class Doctrine
68+
{
69+
70+
/**
71+
* Loads an ORM second level cache bundle mapping information.
72+
*
73+
* @param array<string, mixed> $entityManager A configured ORM entity manager
74+
* @param Definition $ormConfigDef A Definition instance
75+
* @param ContainerBuilder $container A ContainerBuilder instance
76+
*
77+
* @example
78+
* entity_managers:
79+
* default:
80+
* second_level_cache:
81+
* region_lifetime: 3600
82+
* region_lock_lifetime: 60
83+
* region_cache_driver: apc
84+
* log_enabled: true
85+
* regions:
86+
* my_service_region:
87+
* type: service
88+
* service : "my_service_region"
89+
*
90+
* my_query_region:
91+
* lifetime: 300
92+
* cache_driver: array
93+
* type: filelock
94+
*
95+
* my_entity_region:
96+
* lifetime: 600
97+
* cache_driver:
98+
* type: apc
99+
*/
100+
public function method()
101+
{
102+
}
103+
104+
}

0 commit comments

Comments
 (0)