Skip to content

Commit

Permalink
[DeadCode] Skip @param true on native bool type on RemoveUselessParam…
Browse files Browse the repository at this point in the history
…TagRector (#5798)

* [DeadCode] Skip @param true on native bool type on RemoveUselessParamTagRector

* Fix
  • Loading branch information
samsonasik authored Apr 3, 2024
1 parent 91ed251 commit 88648d1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector\Fixture;

class SkipParamTrueSubBool
{
/**
* @param true $param
*/
public function run(bool $param): void
{
echo 'test';
}
}

4 changes: 3 additions & 1 deletion rules/DeadCode/PhpDoc/DeadParamTagValueNodeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
use Rector\BetterPhpDocParser\ValueObject\Type\BracketsAwareUnionTypeNode;
use Rector\DeadCode\PhpDoc\Guard\StandaloneTypeRemovalGuard;
use Rector\DeadCode\TypeNodeAnalyzer\GenericTypeNodeAnalyzer;
use Rector\DeadCode\TypeNodeAnalyzer\MixedArrayTypeNodeAnalyzer;
use Rector\NodeNameResolver\NodeNameResolver;
Expand All @@ -26,6 +27,7 @@ public function __construct(
private MixedArrayTypeNodeAnalyzer $mixedArrayTypeNodeAnalyzer,
private ParamAnalyzer $paramAnalyzer,
private PhpDocTypeChanger $phpDocTypeChanger,
private StandaloneTypeRemovalGuard $standaloneTypeRemovalGuard
) {
}

Expand Down Expand Up @@ -61,7 +63,7 @@ public function isDead(ParamTagValueNode $paramTagValueNode, FunctionLike $funct
}

if (! $paramTagValueNode->type instanceof BracketsAwareUnionTypeNode) {
return true;
return $this->standaloneTypeRemovalGuard->isLegal($paramTagValueNode->type, $param->type);
}

return $this->isAllowedBracketAwareUnion($paramTagValueNode->type);
Expand Down

0 comments on commit 88648d1

Please sign in to comment.