Skip to content

Commit 4ac3165

Browse files
committed
SlevomatCodingStandard.Namespaces.UnusedUses: Improved detection of relative name in generic annotation
1 parent 79ae03a commit 4ac3165

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

SlevomatCodingStandard/Sniffs/Namespaces/UnusedUsesSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public function process(File $phpcsFile, $openTagPointer): void
203203

204204
if (
205205
preg_match(
206-
'~(?<=^|[^a-z\\\\])(' . preg_quote($nameAsReferencedInFile, '~') . ')(?=::)~i',
206+
'~(?<=^|[^a-z\\\\])(' . preg_quote($nameAsReferencedInFile, '~') . ')(\\\\\\w+)*(?=::)~i',
207207
$annotation->getParameters(),
208208
$matches
209209
) === 0

tests/Sniffs/Namespaces/UnusedUsesSniffTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function testUsedUseInAnnotationWithDisabledSearchAnnotations(): void
9696
'searchAnnotations' => false,
9797
]);
9898

99-
self::assertSame(68, $report->getErrorCount());
99+
self::assertSame(69, $report->getErrorCount());
100100

101101
self::assertSniffError($report, 5, UnusedUsesSniff::CODE_UNUSED_USE, 'Type Assert is not used in this file.');
102102
self::assertSniffError(
@@ -190,6 +190,7 @@ public function testUsedUseInAnnotationWithDisabledSearchAnnotations(): void
190190
self::assertSniffError($report, 70, UnusedUsesSniff::CODE_UNUSED_USE, 'Type SomeImportFrom2 is not used in this file.');
191191
self::assertSniffError($report, 71, UnusedUsesSniff::CODE_UNUSED_USE, 'Type ArrayValue is not used in this file.');
192192
self::assertSniffError($report, 72, UnusedUsesSniff::CODE_UNUSED_USE, 'Type TypeAliasWithConstant is not used in this file.');
193+
self::assertSniffError($report, 73, UnusedUsesSniff::CODE_UNUSED_USE, 'Type CustomAssert is not used in this file.');
193194
}
194195

195196
public function testUsedUseInAnnotationWithEnabledSearchAnnotations(): void

tests/Sniffs/Namespaces/data/unusedUsesInAnnotation.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
use SomeImportFrom2;
7171
use ArrayValue;
7272
use TypeAliasWithConstant;
73+
use CustomAssert;
7374

7475
/**
7576
* @ORM\Entity()
@@ -267,3 +268,10 @@ public function types($a, $b)
267268
}
268269

269270
}
271+
272+
/**
273+
* @CustomAssert\NotBlank(message=CustomAssert\AbstractConstraint::VIOLATION_IS_REQUIRED)
274+
*/
275+
class PartlyUsedAliasInGenericAnnotation
276+
{
277+
}

0 commit comments

Comments
 (0)