Skip to content

Commit 6200bab

Browse files
authored
[DeadCode] Allow remove useless @var on aliased object on RemoveUselessVarTagRector (#7967)
1 parent a6b5203 commit 6200bab

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Rector\Tests\DeadCode\Rector\Property\RemoveUselessVarTagRector\Fixture;
4+
5+
use stdClass as std;
6+
7+
final class WithAlias
8+
{
9+
function run()
10+
{
11+
/** @var std $std */
12+
$std = new std();
13+
}
14+
}
15+
16+
?>
17+
-----
18+
<?php
19+
20+
namespace Rector\Tests\DeadCode\Rector\Property\RemoveUselessVarTagRector\Fixture;
21+
22+
use stdClass as std;
23+
24+
final class WithAlias
25+
{
26+
function run()
27+
{
28+
$std = new std();
29+
}
30+
}
31+
32+
?>

rules/DeadCode/PhpDoc/DeadVarTagValueNodeAnalyzer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ public function isDead(VarTagValueNode $varTagValueNode, Property|ClassConst|Exp
8484
}
8585

8686
if ($propertyType instanceof ObjectType && $docType instanceof ObjectType) {
87+
if ($docType->equals($propertyType)) {
88+
return true;
89+
}
90+
8791
// more specific type is already in the property
8892
return $docType->isSuperTypeOf($propertyType)
8993
->yes();

0 commit comments

Comments
 (0)