Skip to content

Commit 0bcf8f0

Browse files
committed
SlevomatCodingStandard.Namespaces.UnusedUses: Fixed false positives
1 parent 3c40fc8 commit 0bcf8f0

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

SlevomatCodingStandard/Sniffs/Namespaces/UnusedUsesSniff.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ public function process(File $phpcsFile, $openTagPointer): void
157157
$contentsToCheck = [];
158158

159159
if ($annotation->getValue() instanceof GenericTagValueNode) {
160+
$contentsToCheck[] = $annotation->getName();
160161
$contentsToCheck[] = $annotation->getValue()->value;
161162
} else {
162163
/** @var list<IdentifierTypeNode> $identifierTypeNodes */

tests/Sniffs/Namespaces/UnusedUsesSniffTest.php

Lines changed: 10 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(81, $report->getErrorCount());
99+
self::assertSame(85, $report->getErrorCount());
100100

101101
self::assertSniffError($report, 5, UnusedUsesSniff::CODE_UNUSED_USE, 'Type Assert is not used in this file.');
102102
self::assertSniffError(
@@ -203,6 +203,15 @@ public function testUsedUseInAnnotationWithDisabledSearchAnnotations(): void
203203
self::assertSniffError($report, 84, UnusedUsesSniff::CODE_UNUSED_USE, 'Type Comma\After is not used in this file.');
204204
self::assertSniffError($report, 85, UnusedUsesSniff::CODE_UNUSED_USE, 'Type ObjectShapeItem1 is not used in this file.');
205205
self::assertSniffError($report, 86, UnusedUsesSniff::CODE_UNUSED_USE, 'Type ObjectShapeItem2 is not used in this file.');
206+
self::assertSniffError($report, 87, UnusedUsesSniff::CODE_UNUSED_USE, 'Type Doctrine\ORM\Mapping\Column is not used in this file.');
207+
self::assertSniffError($report, 88, UnusedUsesSniff::CODE_UNUSED_USE, 'Type Doctrine\ORM\Mapping\Entity is not used in this file.');
208+
self::assertSniffError(
209+
$report,
210+
89,
211+
UnusedUsesSniff::CODE_UNUSED_USE,
212+
'Type Doctrine\ORM\Mapping\GeneratedValue is not used in this file.'
213+
);
214+
self::assertSniffError($report, 90, UnusedUsesSniff::CODE_UNUSED_USE, 'Type Doctrine\ORM\Mapping\Id is not used in this file.');
206215
}
207216

208217
public function testUsedUseInAnnotationWithEnabledSearchAnnotations(): void

tests/Sniffs/Namespaces/data/unusedUsesInAnnotation.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@
8484
use Comma\After;
8585
use ObjectShapeItem1;
8686
use ObjectShapeItem2;
87+
use Doctrine\ORM\Mapping\Column;
88+
use Doctrine\ORM\Mapping\Entity;
89+
use Doctrine\ORM\Mapping\GeneratedValue;
90+
use Doctrine\ORM\Mapping\Id;
8791

8892
/**
8993
* @ORM\Entity()
@@ -329,3 +333,15 @@ class ObjectShape
329333
public object $object;
330334

331335
}
336+
337+
/** @Entity */
338+
class DDC1514EntityB
339+
{
340+
/**
341+
* @var int
342+
* @Id
343+
* @Column(type="integer")
344+
* @GeneratedValue
345+
*/
346+
public $id;
347+
}

0 commit comments

Comments
 (0)