Skip to content

Commit 62438e1

Browse files
committed
[rector] Rector fixes
1 parent bbedd5b commit 62438e1

2 files changed

Lines changed: 6 additions & 24 deletions

File tree

rules-tests/TypedCollections/Rector/ClassMethod/CollectionDocblockGenericTypeRector/config/configured_rule.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
declare(strict_types=1);
44

5+
use Rector\Doctrine\TypedCollections\Rector\ClassMethod\CollectionDocblockGenericTypeRector;
56
use Rector\Config\RectorConfig;
67

78
return static function (RectorConfig $rectorConfig): void {
89
$rectorConfig->rule(
9-
\Rector\Doctrine\TypedCollections\Rector\ClassMethod\CollectionDocblockGenericTypeRector::class
10+
CollectionDocblockGenericTypeRector::class
1011
);
1112
};

rules/TypedCollections/Rector/ClassMethod/CollectionDocblockGenericTypeRector.php

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44

55
namespace Rector\Doctrine\TypedCollections\Rector\ClassMethod;
66

7+
use PhpParser\Node\Expr\MethodCall;
78
use PhpParser\Node;
89
use PhpParser\Node\Stmt\ClassMethod;
910
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
1011
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;
11-
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
1212
use PHPStan\Type\ObjectType;
1313
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
14-
use Rector\BetterPhpDocParser\ValueObject\Type\FullyQualifiedIdentifierTypeNode;
15-
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
1614
use Rector\Doctrine\Enum\DoctrineClass;
1715
use Rector\Doctrine\TypedCollections\NodeAnalyzer\FreshArrayCollectionAnalyzer;
1816
use 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

Comments
 (0)