Skip to content

Commit bb39d91

Browse files
committed
Resolve class references in any PHPDoc tag containing "::"
1 parent 730c316 commit bb39d91

File tree

5 files changed

+62
-6
lines changed

5 files changed

+62
-6
lines changed

src/BetterPhpDocParser/PhpDocParser/PhpDocTagGenericUsesDecorator.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
use Rector\StaticTypeMapper\Naming\NameScopeFactory;
1616

1717
/**
18-
* Decorate node with fully qualified class name for generic annotations for @uses, @used-by, and @see
19-
* e.g. @uses Direction::*
18+
* Decorate node with fully qualified class name for any PHPDoc tag that references a class via "::".
2019
*
2120
* @see https://docs.phpdoc.org/guide/references/phpdoc/tags/uses.html
2221
*/
@@ -46,10 +45,6 @@ public function decorate(PhpDocNode $phpDocNode, PhpNode $phpNode): void
4645
return null;
4746
}
4847

49-
if (! in_array($node->name, ['@uses', '@used-by', '@see'], true)) {
50-
return null;
51-
}
52-
5348
$reference = $node->value->value;
5449
if (! str_contains($reference, '::')) {
5550
return null;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\Issues\CustomPhpDocTagClassReference;
6+
7+
use Iterator;
8+
use PHPUnit\Framework\Attributes\DataProvider;
9+
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
10+
11+
final class CustomPhpDocTagClassReferenceTest extends AbstractRectorTestCase
12+
{
13+
#[DataProvider('provideData')]
14+
public function test(string $filePath): void
15+
{
16+
$this->doTestFile($filePath);
17+
}
18+
19+
public static function provideData(): Iterator
20+
{
21+
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
22+
}
23+
24+
public function provideConfigFilePath(): string
25+
{
26+
return __DIR__ . '/config/configured_rule.php';
27+
}
28+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Rector\Tests\Issues\CustomPhpDocTagClassReference\Fixture;
4+
5+
use Rector\Tests\Issues\CustomPhpDocTagClassReference\Source\NotificationHandler;
6+
7+
/**
8+
* @throwable-from NotificationHandler::createPayload
9+
*/
10+
final class SkipCustomTagWithClassReference extends \Exception
11+
{
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\Issues\CustomPhpDocTagClassReference\Source;
6+
7+
final class NotificationHandler
8+
{
9+
public function createPayload(): void
10+
{
11+
}
12+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
7+
return static function (RectorConfig $rectorConfig): void {
8+
$rectorConfig->removeUnusedImports();
9+
};

0 commit comments

Comments
 (0)