Skip to content

Commit 61ebcc5

Browse files
[DeadCode] Support multiple templates in RemoveUselessVarTagRector (#6402)
1 parent 61a787e commit 61ebcc5

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Rector\Tests\DeadCode\Rector\Property\RemoveUselessVarTagRector\Fixture;
4+
5+
use Rector\Tests\DeadCode\Rector\Property\RemoveUselessVarTagRector\Source\Properties;
6+
7+
/**
8+
* @template TProperties of Properties|null
9+
* @template TCategories of object
10+
*/
11+
final class SkipTemplateTagWithMultipleTemplates
12+
{
13+
/** @var TCategories */
14+
private object $categories;
15+
16+
/** @var TProperties */
17+
private Properties|null $properties;
18+
}

rules/TypeDeclaration/PHPStan/ObjectTypeSpecifier.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use PhpParser\Node\Stmt\Use_;
1212
use PhpParser\Node\Stmt\UseUse;
1313
use PHPStan\Analyser\Scope;
14-
use PHPStan\PhpDoc\Tag\TemplateTag;
1514
use PHPStan\Reflection\ClassReflection;
1615
use PHPStan\Reflection\ReflectionProvider;
1716
use PHPStan\Type\Generic\GenericObjectType;
@@ -85,14 +84,13 @@ public function narrowToFullyQualifiedOrAliasedObjectType(
8584
return new NonExistingObjectType($className);
8685
}
8786

88-
// only support single @template for now
89-
if (count($templateTags) !== 1) {
87+
$currentTemplateTag = $templateTags[$className] ?? null;
88+
89+
if ($currentTemplateTag === null) {
9090
// invalid type
9191
return new NonExistingObjectType($className);
9292
}
9393

94-
/** @var TemplateTag $currentTemplateTag */
95-
$currentTemplateTag = current($templateTags);
9694
return TemplateTypeFactory::create(
9795
$templateTypeScope,
9896
$currentTemplateTag->getName(),

0 commit comments

Comments
 (0)