Skip to content

Commit 21ad196

Browse files
authored
[DeadCode] Early check GenericTypeNode is not dead code on DeadVar/ReturnParam Analyzer (#7118)
* [DeadCode] Early check GenericTypeNode is not dead code on DeadVar/ReturnParam Analyzer * Fix * Fix
1 parent ac4f09b commit 21ad196

File tree

6 files changed

+20
-1
lines changed

6 files changed

+20
-1
lines changed

ecs.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
declare(strict_types=1);
44

5+
use PhpCsFixer\Fixer\Casing\LowercaseKeywordsFixer;
56
use PhpCsFixer\Fixer\Phpdoc\GeneralPhpdocAnnotationRemoveFixer;
67
use PhpCsFixer\Fixer\Phpdoc\PhpdocTypesFixer;
78
use Symplify\EasyCodingStandard\Config\ECSConfig;
@@ -34,5 +35,7 @@
3435
// bug remove @author annotation
3536
__DIR__ . '/src/Util/ArrayParametersMerger.php',
3637
],
38+
39+
LowercaseKeywordsFixer::class => [__DIR__ . '/src/ValueObject/Visibility.php'],
3740
])
3841
->withRootFiles();

rules/CodeQuality/Rector/Class_/RemoveReadonlyPropertyVisibilityOnReadonlyClassRector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
namespace Rector\CodeQuality\Rector\Class_;
66

77
use PhpParser\Node;
8-
use PhpParser\Node\Stmt\ClassMethod;
98
use PhpParser\Node\Stmt\Class_;
9+
use PhpParser\Node\Stmt\ClassMethod;
1010
use Rector\Php81\NodeManipulator\AttributeGroupNewLiner;
1111
use Rector\Privatization\NodeManipulator\VisibilityManipulator;
1212
use Rector\Rector\AbstractRector;

rules/DeadCode/PhpDoc/DeadParamTagValueNodeAnalyzer.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PhpParser\Node\Name;
1010
use PhpParser\Node\Param;
1111
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
12+
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;
1213
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
1314
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
1415
use Rector\BetterPhpDocParser\ValueObject\Type\BracketsAwareUnionTypeNode;
@@ -51,6 +52,10 @@ public function isDead(ParamTagValueNode $paramTagValueNode, FunctionLike $funct
5152
return false;
5253
}
5354

55+
if ($paramTagValueNode->type instanceof GenericTypeNode) {
56+
return false;
57+
}
58+
5459
$docType = $this->staticTypeMapper->mapPHPStanPhpDocTypeNodeToPHPStanType(
5560
$paramTagValueNode->type,
5661
$functionLike

rules/DeadCode/PhpDoc/DeadReturnTagValueNodeAnalyzer.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use PhpParser\Node\Stmt\Function_;
1111
use PHPStan\Analyser\Scope;
1212
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
13+
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;
1314
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
1415
use PHPStan\PhpDocParser\Ast\Type\ThisTypeNode;
1516
use PHPStan\Type\TypeCombinator;
@@ -49,6 +50,10 @@ public function isDead(ReturnTagValueNode $returnTagValueNode, ClassMethod|Funct
4950
return false;
5051
}
5152

53+
if ($returnTagValueNode->type instanceof GenericTypeNode) {
54+
return false;
55+
}
56+
5257
$docType = $this->staticTypeMapper->mapPHPStanPhpDocTypeNodeToPHPStanType(
5358
$returnTagValueNode->type,
5459
$functionLike

rules/DeadCode/PhpDoc/DeadVarTagValueNodeAnalyzer.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use PhpParser\Node\Stmt\ClassConst;
99
use PhpParser\Node\Stmt\Property;
1010
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
11+
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;
1112
use PHPStan\Type\IntersectionType;
1213
use PHPStan\Type\ObjectType;
1314
use PHPStan\Type\TypeCombinator;
@@ -35,6 +36,10 @@ public function isDead(VarTagValueNode $varTagValueNode, Property|ClassConst $pr
3536
return false;
3637
}
3738

39+
if ($varTagValueNode->type instanceof GenericTypeNode) {
40+
return false;
41+
}
42+
3843
// is strict type superior to doc type? keep strict type only
3944
$propertyType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($property->type);
4045
$docType = $this->staticTypeMapper->mapPHPStanPhpDocTypeNodeToPHPStanType($varTagValueNode->type, $property);

rules/TypeDeclaration/Rector/FuncCall/AddArrayFunctionClosureParamTypeRector.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ public function refactor(Node $node): ?Node
106106
if (! $singlePassedExprType instanceof Type) {
107107
continue;
108108
}
109+
109110
if ($singlePassedExprType instanceof MixedType) {
110111
continue;
111112
}

0 commit comments

Comments
 (0)