From 1d62cf77f5bd8f75242b2f2c2c2598310435c3c6 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 1 Oct 2025 09:54:24 +0700 Subject: [PATCH] [TypeDeclarationDocblocks] Use existing NodeDocblockTypeDecorator service on DocblockGetterReturnArrayFromPropertyDocblockVarRector --- ...turnArrayFromPropertyDocblockVarRector.php | 26 +++++++------------ 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/rules/TypeDeclarationDocblocks/Rector/ClassMethod/DocblockGetterReturnArrayFromPropertyDocblockVarRector.php b/rules/TypeDeclarationDocblocks/Rector/ClassMethod/DocblockGetterReturnArrayFromPropertyDocblockVarRector.php index 753aca29bab..195b15ab5c7 100644 --- a/rules/TypeDeclarationDocblocks/Rector/ClassMethod/DocblockGetterReturnArrayFromPropertyDocblockVarRector.php +++ b/rules/TypeDeclarationDocblocks/Rector/ClassMethod/DocblockGetterReturnArrayFromPropertyDocblockVarRector.php @@ -12,9 +12,8 @@ use PHPStan\Type\MixedType; use PHPStan\Type\UnionType; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; -use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger; use Rector\Rector\AbstractRector; -use Rector\StaticTypeMapper\StaticTypeMapper; +use Rector\TypeDeclarationDocblocks\NodeDocblockTypeDecorator; use Rector\TypeDeclarationDocblocks\TagNodeAnalyzer\UsefulArrayTagNodeAnalyzer; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -26,9 +25,8 @@ final class DocblockGetterReturnArrayFromPropertyDocblockVarRector extends Abstr { public function __construct( private readonly PhpDocInfoFactory $phpDocInfoFactory, - private readonly StaticTypeMapper $staticTypeMapper, private readonly UsefulArrayTagNodeAnalyzer $usefulArrayTagNodeAnalyzer, - private readonly PhpDocTypeChanger $phpDocTypeChanger + private readonly NodeDocblockTypeDecorator $nodeDocblockTypeDecorator ) { } @@ -96,11 +94,6 @@ public function refactor(Node $node): ?Node return null; } - // // return tag is already given - // if ($phpDocInfo->getReturnTagValue() instanceof ReturnTagValueNode) { - // return null; - // } - $propertyFetch = $this->matchReturnLocalPropertyFetch($node); if (! $propertyFetch instanceof PropertyFetch) { return null; @@ -118,14 +111,13 @@ public function refactor(Node $node): ?Node return null; } - $propertyFetchDocTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPHPStanPhpDocTypeNode($propertyFetchType); - - $this->phpDocTypeChanger->changeReturnTypeNode($node, $phpDocInfo, $propertyFetchDocTypeNode); - - // $returnTagValueNode = new ReturnTagValueNode($propertyFetchDocTypeNode, ''); - // $phpDocInfo->addTagValueNode($returnTagValueNode); - // - // $this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($node); + if (! $this->nodeDocblockTypeDecorator->decorateGenericIterableReturnType( + $propertyFetchType, + $phpDocInfo, + $node + )) { + return null; + } return $node; }