Skip to content

Commit b032783

Browse files
committed
UnusedUsesSniff: fixed false positives
1 parent f8bc493 commit b032783

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

SlevomatCodingStandard/Sniffs/Namespaces/UnusedUsesSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public function process(\PHP_CodeSniffer\Files\File $phpcsFile, $openTagPointer)
162162
}
163163

164164
if (
165-
!preg_match('~(?<=^|[^a-z\s\\\\])(' . preg_quote($nameAsReferencedInFile, '~') . ')(?=::)~i', $annotation->getParameters(), $matches)
165+
!preg_match('~(?<=^|[^a-z\\\\])(' . preg_quote($nameAsReferencedInFile, '~') . ')(?=::)~i', $annotation->getParameters(), $matches)
166166
&& !preg_match('~(?<=@)(' . preg_quote($nameAsReferencedInFile, '~') . ')(?=\\\\|\()~i', $annotation->getParameters(), $matches)
167167
) {
168168
continue;

tests/Sniffs/Namespaces/UnusedUsesSniffTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function testUsedUseInAnnotationWithDisabledSearchAnnotations(): void
108108
'searchAnnotations' => false,
109109
]);
110110

111-
self::assertSame(30, $report->getErrorCount());
111+
self::assertSame(32, $report->getErrorCount());
112112

113113
self::assertSniffError($report, 5, UnusedUsesSniff::CODE_UNUSED_USE, 'Type Assert is not used in this file.');
114114
self::assertSniffError($report, 6, UnusedUsesSniff::CODE_UNUSED_USE, 'Type Doctrine\ORM\Mapping (as ORM) is not used in this file.');
@@ -139,6 +139,8 @@ public function testUsedUseInAnnotationWithDisabledSearchAnnotations(): void
139139
self::assertSniffError($report, 32, UnusedUsesSniff::CODE_UNUSED_USE, 'Type MethodParameter2 is not used in this file.');
140140
self::assertSniffError($report, 33, UnusedUsesSniff::CODE_UNUSED_USE, 'Type MethodParameter3 is not used in this file.');
141141
self::assertSniffError($report, 34, UnusedUsesSniff::CODE_UNUSED_USE, 'Type MethodParameter4 is not used in this file.');
142+
self::assertSniffError($report, 35, UnusedUsesSniff::CODE_UNUSED_USE, 'Type Discriminator\Lorem is not used in this file.');
143+
self::assertSniffError($report, 36, UnusedUsesSniff::CODE_UNUSED_USE, 'Type Discriminator\Ipsum is not used in this file.');
142144
}
143145

144146
public function testUsedUseInAnnotationWithEnabledSearchAnnotations(): void

tests/Sniffs/Namespaces/data/unusedUsesInAnnotation.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,15 @@
3232
use MethodParameter2;
3333
use MethodParameter3;
3434
use MethodParameter4;
35+
use Discriminator\Lorem;
36+
use Discriminator\Ipsum;
3537

3638
/**
3739
* @ORM\Entity()
40+
* @ORM\DiscriminatorMap({
41+
* "lorem" = Lorem::class,
42+
* "ipsum" = Ipsum::class,
43+
* })
3844
*/
3945
class Boo
4046
{

0 commit comments

Comments
 (0)