44
55namespace Rector \Doctrine \TypedCollections \Rector \ClassMethod ;
66
7+ use PhpParser \Node \Expr \MethodCall ;
78use PhpParser \Node ;
89use PhpParser \Node \Stmt \ClassMethod ;
910use PHPStan \PhpDocParser \Ast \PhpDoc \ReturnTagValueNode ;
1011use PHPStan \PhpDocParser \Ast \Type \GenericTypeNode ;
11- use PHPStan \PhpDocParser \Ast \Type \IdentifierTypeNode ;
1212use PHPStan \Type \ObjectType ;
1313use Rector \BetterPhpDocParser \PhpDocInfo \PhpDocInfoFactory ;
14- use Rector \BetterPhpDocParser \ValueObject \Type \FullyQualifiedIdentifierTypeNode ;
15- use Rector \Comments \NodeDocBlock \DocBlockUpdater ;
1614use Rector \Doctrine \Enum \DoctrineClass ;
1715use Rector \Doctrine \TypedCollections \NodeAnalyzer \FreshArrayCollectionAnalyzer ;
1816use Rector \PhpParser \Node \BetterNodeFinder ;
@@ -28,8 +26,7 @@ final class CollectionDocblockGenericTypeRector extends AbstractRector
2826 public function __construct (
2927 private readonly BetterNodeFinder $ betterNodeFinder ,
3028 private readonly FreshArrayCollectionAnalyzer $ freshArrayCollectionAnalyzer ,
31- private readonly PhpDocInfoFactory $ phpDocInfoFactory ,
32- private readonly DocBlockUpdater $ docBlockUpdater
29+ private readonly PhpDocInfoFactory $ phpDocInfoFactory
3330 ) {
3431 }
3532
@@ -117,9 +114,9 @@ public function refactor(Node $node): ?ClassMethod
117114
118115 // resolve type added to collection
119116
120- $ methodCalls = $ this ->betterNodeFinder ->findInstancesOfScoped ([$ node ], Node \ Expr \ MethodCall::class);
117+ $ methodCalls = $ this ->betterNodeFinder ->findInstancesOfScoped ([$ node ], MethodCall::class);
121118
122- $ collectionAddMethodCalls = array_filter ($ methodCalls , function (Node \ Expr \ MethodCall $ methodCall ): bool {
119+ $ collectionAddMethodCalls = array_filter ($ methodCalls , function (MethodCall $ methodCall ): bool {
123120 if (! $ this ->isName ($ methodCall ->name , 'add ' )) {
124121 return false ;
125122 }
@@ -134,21 +131,5 @@ public function refactor(Node $node): ?ClassMethod
134131
135132 dump ($ collectionAddMethodCalls );
136133 die;
137-
138- // add a new one with generic type
139- // find return
140- // find new ArrayCollection()
141- // improve return type
142- $ genericTypeNode = new GenericTypeNode (
143- new FullyQualifiedIdentifierTypeNode (DoctrineClass::COLLECTION ),
144- [new IdentifierTypeNode ('int ' ), new IdentifierTypeNode ('SomeClass ' )] // @todo resolve the class name
145- );
146- $ returnTagValueNode = new ReturnTagValueNode ($ genericTypeNode , '' );
147-
148- $ phpDocInfo ->addTagValueNode ($ returnTagValueNode );
149-
150- $ this ->docBlockUpdater ->updateRefactoredNodeWithPhpDocInfo ($ node );
151-
152- return null ;
153134 }
154135}
0 commit comments