Skip to content

Commit d6f9d59

Browse files
committed
Fix
1 parent cea94d1 commit d6f9d59

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

rules/TypeDeclarationDocblocks/NodeDocblockTypeDecorator.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,14 @@ public function decorateGenericIterableParamType(
4646
return false;
4747
}
4848

49-
$normalizedType = $this->typeNormalizer->generalizeConstantTypes($type);
50-
$typeNode = $this->createTypeNode($normalizedType);
49+
$typeNode = $this->createTypeNode($type);
5150

5251
// no value iterable type
5352
if ($typeNode instanceof IdentifierTypeNode) {
5453
return false;
5554
}
5655

57-
$this->phpDocTypeChanger->changeParamType($classMethod, $phpDocInfo, $normalizedType, $param, $parameterName);
56+
$this->phpDocTypeChanger->changeParamTypeNode($classMethod, $phpDocInfo, $param, $parameterName, $typeNode);
5857

5958
return true;
6059
}
@@ -76,9 +75,7 @@ public function decorateGenericIterableReturnType(
7675
return false;
7776
}
7877

79-
$returnTagValueNode = new ReturnTagValueNode($typeNode, '');
80-
81-
$this->addTagValueNodeAndUpdatePhpDocInfo($classMethodPhpDocInfo, $returnTagValueNode, $classMethod);
78+
$this->phpDocTypeChanger->changeReturnTypeNode($classMethod, $classMethodPhpDocInfo, $typeNode);
8279

8380
return true;
8481
}

rules/TypeDeclarationDocblocks/Rector/ClassMethod/AddParamArrayDocblockFromAssignsParamToParamReferenceRector.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,7 @@ public function refactor(Node $node): ?Node
102102
$paramTagValueNode = $phpDocInfo->getParamTagValueByName($paramName);
103103

104104
// already defined, lets skip it
105-
if ($this->usefulArrayTagNodeAnalyzer->isUsefulArrayTag(
106-
$paramTagValueNode
107-
)) {
105+
if ($this->usefulArrayTagNodeAnalyzer->isUsefulArrayTag($paramTagValueNode)) {
108106
continue;
109107
}
110108

rules/TypeDeclarationDocblocks/Rector/Class_/AddReturnDocblockDataProviderRector.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use PhpParser\Node\Expr;
99
use PhpParser\Node\Stmt\Class_;
1010
use PhpParser\Node\Stmt\Return_;
11-
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
1211
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
1312
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
1413
use Rector\Rector\AbstractRector;
@@ -17,6 +16,7 @@
1716
use Rector\TypeDeclarationDocblocks\NodeFinder\DataProviderMethodsFinder;
1817
use Rector\TypeDeclarationDocblocks\NodeFinder\ReturnNodeFinder;
1918
use Rector\TypeDeclarationDocblocks\NodeFinder\YieldNodeFinder;
19+
use Rector\TypeDeclarationDocblocks\TagNodeAnalyzer\UsefulArrayTagNodeAnalyzer;
2020
use Rector\TypeDeclarationDocblocks\TypeResolver\YieldTypeResolver;
2121
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
2222
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@@ -33,6 +33,7 @@ public function __construct(
3333
private readonly ReturnNodeFinder $returnNodeFinder,
3434
private readonly YieldTypeResolver $yieldTypeResolver,
3535
private readonly YieldNodeFinder $yieldNodeFinder,
36+
private readonly UsefulArrayTagNodeAnalyzer $usefulArrayTagNodeAnalyzer,
3637
private readonly NodeDocblockTypeDecorator $nodeDocblockTypeDecorator,
3738
) {
3839
}
@@ -118,7 +119,7 @@ public function refactor(Node $node): ?Node
118119
$returnTagValueNode = $classMethodPhpDocInfo->getReturnTagValue();
119120

120121
// already set
121-
if ($returnTagValueNode instanceof ReturnTagValueNode) {
122+
if ($this->usefulArrayTagNodeAnalyzer->isUsefulArrayTag($returnTagValueNode)) {
122123
continue;
123124
}
124125

src/BetterPhpDocParser/PhpDocManipulator/PhpDocTypeChanger.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,24 @@ public function changeReturnTypeNode(
113113
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($functionLike);
114114
}
115115

116+
public function changeParamTypeNode(
117+
FunctionLike $functionLike,
118+
PhpDocInfo $phpDocInfo,
119+
Param $param,
120+
string $paramName,
121+
TypeNode $newTypeNode
122+
): void {
123+
$existingParamTagValueNode = $phpDocInfo->getParamTagValueByName($paramName);
124+
if ($existingParamTagValueNode instanceof ParamTagValueNode) {
125+
$existingParamTagValueNode->type = $newTypeNode;
126+
} else {
127+
$paramTagValueNode = $this->paramPhpDocNodeFactory->create($newTypeNode, $param);
128+
$phpDocInfo->addTagValueNode($paramTagValueNode);
129+
}
130+
131+
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($functionLike);
132+
}
133+
116134
public function changeReturnType(FunctionLike $functionLike, PhpDocInfo $phpDocInfo, Type $newType): bool
117135
{
118136
// better not touch this, can crash

0 commit comments

Comments
 (0)