Skip to content

Commit 861e7b5

Browse files
committed
UnusedUsesSniff: fixed ugly inline doccomment format support
1 parent ca7b670 commit 861e7b5

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

SlevomatCodingStandard/Sniffs/Namespaces/UnusedUsesSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function process(\PHP_CodeSniffer\Files\File $phpcsFile, $openTagPointer)
138138
continue;
139139
}
140140

141-
if (!preg_match('~(?<=^|\|)(' . preg_quote($nameAsReferencedInFile, '~') . ')(?=\\s|\\\\|\||\[|$)~i', $annotation->getContent(), $matches)) {
141+
if (!preg_match('~(?:^|\||\$\\w+\\s+)(' . preg_quote($nameAsReferencedInFile, '~') . ')(?=\\s|\\\\|\||\[|$)~i', $annotation->getContent(), $matches)) {
142142
continue;
143143
}
144144

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(17, $report->getErrorCount());
111+
self::assertSame(18, $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.');
@@ -126,6 +126,8 @@ public function testUsedUseInAnnotationWithDisabledSearchAnnotations(): void
126126
self::assertSniffError($report, 19, UnusedUsesSniff::CODE_UNUSED_USE, 'Type Foo\Boo\B is not used in this file.');
127127
self::assertSniffError($report, 20, UnusedUsesSniff::CODE_UNUSED_USE, 'Type Foo\Boo\C is not used in this file.');
128128
self::assertSniffError($report, 21, UnusedUsesSniff::CODE_UNUSED_USE, 'Type Foo\Boo\D is not used in this file.');
129+
self::assertSniffError($report, 21, UnusedUsesSniff::CODE_UNUSED_USE, 'Type Foo\Boo\D is not used in this file.');
130+
self::assertSniffError($report, 22, UnusedUsesSniff::CODE_UNUSED_USE, 'Type UglyInlineAnnotation is not used in this file.');
129131
}
130132

131133
public function testUsedUseInAnnotationWithEnabledSearchAnnotations(): void

tests/Sniffs/Namespaces/data/unusedUsesInAnnotation.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Foo\Boo\B;
2020
use Foo\Boo\C;
2121
use Foo\Boo\D;
22+
use UglyInlineAnnotation;
2223

2324
/**
2425
* @ORM\Entity()
@@ -78,3 +79,5 @@ public function test()
7879
* @CustomAnnotation(@AnotherCustomAnnotation(C::class))
7980
* @CustomAnnotation(prop=@AnotherCustomAnnotation(D::class))
8081
*/
82+
83+
/** @var $variable UglyInlineAnnotation */

0 commit comments

Comments
 (0)