Skip to content

Commit 2a24b1b

Browse files
committed
UnusedUsesSniff: more tests and fixes
1 parent 8d05efb commit 2a24b1b

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

SlevomatCodingStandard/Sniffs/Namespaces/UnusedUsesSniff.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ public function process(\PHP_CodeSniffer\Files\File $phpcsFile, $openTagPointer)
112112
continue;
113113
}
114114

115-
if (!preg_match('~(?<=^|=|\{)(' . preg_quote($nameAsReferencedInFile, '~') . ')(?=::)~i', $annotation->getParameters(), $matches)) {
115+
if (
116+
!preg_match('~(?<=^|=|\{)(' . preg_quote($nameAsReferencedInFile, '~') . ')(?=::)~i', $annotation->getParameters(), $matches)
117+
&& !preg_match('~(?<=@)(' . preg_quote($nameAsReferencedInFile, '~') . ')(?=\\\\|\()~i', $annotation->getParameters(), $matches)
118+
) {
116119
continue;
117120
}
118121

tests/Sniffs/Namespaces/UnusedUsesSniffTest.php

Lines changed: 2 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(12, $report->getErrorCount());
111+
self::assertSame(13, $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.');
@@ -121,6 +121,7 @@ public function testUsedUseInAnnotationWithDisabledSearchAnnotations(): void
121121
self::assertSniffError($report, 14, UnusedUsesSniff::CODE_UNUSED_USE, 'Type InvalidArgumentException is not used in this file.');
122122
self::assertSniffError($report, 15, UnusedUsesSniff::CODE_UNUSED_USE, 'Type LengthException is not used in this file.');
123123
self::assertSniffError($report, 16, UnusedUsesSniff::CODE_UNUSED_USE, 'Type RuntimeException is not used in this file.');
124+
self::assertSniffError($report, 17, UnusedUsesSniff::CODE_UNUSED_USE, 'Type Symfony\Component\Validator\Constraints (as Assert2) is not used in this file.');
124125
}
125126

126127
public function testUsedUseInAnnotationWithEnabledSearchAnnotations(): void

tests/Sniffs/Namespaces/data/unusedUsesInAnnotation.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use InvalidArgumentException;
1515
use LengthException;
1616
use RuntimeException;
17+
use Symfony\Component\Validator\Constraints as Assert2;
1718

1819
/**
1920
* @ORM\Entity()
@@ -57,4 +58,12 @@ public function test()
5758
{
5859

5960
}
61+
6062
}
63+
64+
/**
65+
* @Validate(fields={
66+
* "widgetUuid" = @Assert2\Uuid(),
67+
* "clientAuthKey" = @Assert2\NotBlank()
68+
* })
69+
*/

0 commit comments

Comments
 (0)