Skip to content

Commit 646a732

Browse files
authored
[TypeDeclarationDocblocks] Use existing NodeDocblockTypeDecorator service on DocblockGetterReturnArrayFromPropertyDocblockVarRector (#7387)
1 parent f0e38bb commit 646a732

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

rules/TypeDeclarationDocblocks/Rector/ClassMethod/DocblockGetterReturnArrayFromPropertyDocblockVarRector.php

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
use PHPStan\Type\MixedType;
1313
use PHPStan\Type\UnionType;
1414
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
15-
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
1615
use Rector\Rector\AbstractRector;
17-
use Rector\StaticTypeMapper\StaticTypeMapper;
16+
use Rector\TypeDeclarationDocblocks\NodeDocblockTypeDecorator;
1817
use Rector\TypeDeclarationDocblocks\TagNodeAnalyzer\UsefulArrayTagNodeAnalyzer;
1918
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
2019
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@@ -26,9 +25,8 @@ final class DocblockGetterReturnArrayFromPropertyDocblockVarRector extends Abstr
2625
{
2726
public function __construct(
2827
private readonly PhpDocInfoFactory $phpDocInfoFactory,
29-
private readonly StaticTypeMapper $staticTypeMapper,
3028
private readonly UsefulArrayTagNodeAnalyzer $usefulArrayTagNodeAnalyzer,
31-
private readonly PhpDocTypeChanger $phpDocTypeChanger
29+
private readonly NodeDocblockTypeDecorator $nodeDocblockTypeDecorator
3230
) {
3331
}
3432

@@ -96,11 +94,6 @@ public function refactor(Node $node): ?Node
9694
return null;
9795
}
9896

99-
// // return tag is already given
100-
// if ($phpDocInfo->getReturnTagValue() instanceof ReturnTagValueNode) {
101-
// return null;
102-
// }
103-
10497
$propertyFetch = $this->matchReturnLocalPropertyFetch($node);
10598
if (! $propertyFetch instanceof PropertyFetch) {
10699
return null;
@@ -118,14 +111,13 @@ public function refactor(Node $node): ?Node
118111
return null;
119112
}
120113

121-
$propertyFetchDocTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPHPStanPhpDocTypeNode($propertyFetchType);
122-
123-
$this->phpDocTypeChanger->changeReturnTypeNode($node, $phpDocInfo, $propertyFetchDocTypeNode);
124-
125-
// $returnTagValueNode = new ReturnTagValueNode($propertyFetchDocTypeNode, '');
126-
// $phpDocInfo->addTagValueNode($returnTagValueNode);
127-
//
128-
// $this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($node);
114+
if (! $this->nodeDocblockTypeDecorator->decorateGenericIterableReturnType(
115+
$propertyFetchType,
116+
$phpDocInfo,
117+
$node
118+
)) {
119+
return null;
120+
}
129121

130122
return $node;
131123
}

0 commit comments

Comments
 (0)