Skip to content

Commit b0738f9

Browse files
committed
implemented 🎉
1 parent 219dfbc commit b0738f9

2 files changed

Lines changed: 16 additions & 16 deletions

File tree

rules/TypeDeclarationDocblocks/Rector/ClassMethod/AddParamArrayDocblockFromAssignsParamToParamReferenceRector.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
use PHPStan\Type\ArrayType;
1212
use PHPStan\Type\MixedType;
1313
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
14+
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
15+
use Rector\Privatization\TypeManipulator\TypeNormalizer;
1416
use Rector\Rector\AbstractRector;
15-
use Rector\TypeDeclarationDocblocks\NodeDocblockTypeDecorator;
1617
use Rector\TypeDeclarationDocblocks\NodeFinder\ArrayDimFetchFinder;
18+
use Rector\TypeDeclarationDocblocks\TagNodeAnalyzer\UsefulArrayTagNodeAnalyzer;
1719
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
1820
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
1921

@@ -25,7 +27,9 @@ final class AddParamArrayDocblockFromAssignsParamToParamReferenceRector extends
2527
public function __construct(
2628
private readonly PhpDocInfoFactory $phpDocInfoFactory,
2729
private readonly ArrayDimFetchFinder $arrayDimFetchFinder,
28-
private readonly NodeDocblockTypeDecorator $nodeDocblockTypeDecorator,
30+
private readonly UsefulArrayTagNodeAnalyzer $usefulArrayTagNodeAnalyzer,
31+
private readonly TypeNormalizer $typeNormalizer,
32+
private readonly PhpDocTypeChanger $phpDocTypeChanger
2933
) {
3034
}
3135

@@ -101,7 +105,9 @@ public function refactor(Node $node): ?Node
101105
$paramTagValueNode = $phpDocInfo->getParamTagValueByName($paramName);
102106

103107
// already defined, lets skip it
104-
if ($paramTagValueNode instanceof ParamTagValueNode) {
108+
if ($paramTagValueNode instanceof ParamTagValueNode && $this->usefulArrayTagNodeAnalyzer->isUsefulArrayTag(
109+
$paramTagValueNode
110+
)) {
105111
continue;
106112
}
107113

@@ -113,18 +119,11 @@ public function refactor(Node $node): ?Node
113119
}
114120

115121
$assignedExprType = $this->getType($exprs[0]);
116-
$iterableType = new ArrayType(new MixedType(), $assignedExprType);
117-
118-
$hasParamTypeChanged = $this->nodeDocblockTypeDecorator->decorateGenericIterableParamType(
119-
$iterableType,
120-
$phpDocInfo,
121-
$node,
122-
$paramName
122+
$iterableType = $this->typeNormalizer->generalizeConstantTypes(
123+
new ArrayType(new MixedType(), $assignedExprType)
123124
);
124125

125-
if (! $hasParamTypeChanged) {
126-
continue;
127-
}
126+
$this->phpDocTypeChanger->changeParamType($node, $phpDocInfo, $iterableType, $param, $paramName);
128127

129128
$hasChanged = true;
130129
}

rules/TypeDeclarationDocblocks/TagNodeAnalyzer/UsefulArrayTagNodeAnalyzer.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@
44

55
namespace Rector\TypeDeclarationDocblocks\TagNodeAnalyzer;
66

7+
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
78
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
89
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
910

1011
final class UsefulArrayTagNodeAnalyzer
1112
{
12-
public function isUsefulArrayTag(?ReturnTagValueNode $returnTagValueNode): bool
13+
public function isUsefulArrayTag(null|ReturnTagValueNode|ParamTagValueNode $tagValueNode): bool
1314
{
14-
if (! $returnTagValueNode instanceof ReturnTagValueNode) {
15+
if (! $tagValueNode instanceof ReturnTagValueNode && ! $tagValueNode instanceof ParamTagValueNode) {
1516
return false;
1617
}
1718

18-
$type = $returnTagValueNode->type;
19+
$type = $tagValueNode->type;
1920
if (! $type instanceof IdentifierTypeNode) {
2021
return true;
2122
}

0 commit comments

Comments
 (0)