Skip to content

Commit

Permalink
UnusedUsesSniff: fixed ugly inline doccomment format support
Browse files Browse the repository at this point in the history
  • Loading branch information
kukulich committed Feb 15, 2018
1 parent ca7b670 commit 861e7b5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function process(\PHP_CodeSniffer\Files\File $phpcsFile, $openTagPointer)
continue;
}

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

Expand Down
4 changes: 3 additions & 1 deletion tests/Sniffs/Namespaces/UnusedUsesSniffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function testUsedUseInAnnotationWithDisabledSearchAnnotations(): void
'searchAnnotations' => false,
]);

self::assertSame(17, $report->getErrorCount());
self::assertSame(18, $report->getErrorCount());

self::assertSniffError($report, 5, UnusedUsesSniff::CODE_UNUSED_USE, 'Type Assert is not used in this file.');
self::assertSniffError($report, 6, UnusedUsesSniff::CODE_UNUSED_USE, 'Type Doctrine\ORM\Mapping (as ORM) is not used in this file.');
Expand All @@ -126,6 +126,8 @@ public function testUsedUseInAnnotationWithDisabledSearchAnnotations(): void
self::assertSniffError($report, 19, UnusedUsesSniff::CODE_UNUSED_USE, 'Type Foo\Boo\B is not used in this file.');
self::assertSniffError($report, 20, UnusedUsesSniff::CODE_UNUSED_USE, 'Type Foo\Boo\C is not used in this file.');
self::assertSniffError($report, 21, UnusedUsesSniff::CODE_UNUSED_USE, 'Type Foo\Boo\D is not used in this file.');
self::assertSniffError($report, 21, UnusedUsesSniff::CODE_UNUSED_USE, 'Type Foo\Boo\D is not used in this file.');
self::assertSniffError($report, 22, UnusedUsesSniff::CODE_UNUSED_USE, 'Type UglyInlineAnnotation is not used in this file.');
}

public function testUsedUseInAnnotationWithEnabledSearchAnnotations(): void
Expand Down
3 changes: 3 additions & 0 deletions tests/Sniffs/Namespaces/data/unusedUsesInAnnotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Foo\Boo\B;
use Foo\Boo\C;
use Foo\Boo\D;
use UglyInlineAnnotation;

/**
* @ORM\Entity()
Expand Down Expand Up @@ -78,3 +79,5 @@ public function test()
* @CustomAnnotation(@AnotherCustomAnnotation(C::class))
* @CustomAnnotation(prop=@AnotherCustomAnnotation(D::class))
*/

/** @var $variable UglyInlineAnnotation */

0 comments on commit 861e7b5

Please sign in to comment.