Skip to content

Commit 6be09e4

Browse files
authored
Fix scoper Doctrine class in use statement prefixed with RectorPrefix (#393)
1 parent 1edeb03 commit 6be09e4

File tree

4 files changed

+10
-13
lines changed

4 files changed

+10
-13
lines changed

rules/TypedCollections/Rector/ClassMethod/NarrowArrayCollectionToCollectionRector.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

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

7-
use Doctrine\Common\Collections\ArrayCollection;
87
use PhpParser\Node;
98
use PhpParser\Node\Identifier;
109
use PhpParser\Node\Name;
@@ -155,7 +154,7 @@ private function refactorClassMethodNativeTypes(ClassMethod $classMethod): bool
155154
}
156155
}
157156

158-
if ($node instanceof Name && $this->isName($node, ArrayCollection::class)) {
157+
if ($node instanceof Name && $this->isName($node, DoctrineClass::ARRAY_COLLECTION)) {
159158
$hasChanged = true;
160159
if ($hasReturnCollectionType) {
161160
// we already have Collection, and can remove it
@@ -168,7 +167,7 @@ private function refactorClassMethodNativeTypes(ClassMethod $classMethod): bool
168167
return null;
169168
});
170169

171-
if ($this->isName($classMethod->returnType, ArrayCollection::class)) {
170+
if ($this->isName($classMethod->returnType, DoctrineClass::ARRAY_COLLECTION)) {
172171
$classMethod->returnType = new FullyQualified(DoctrineClass::COLLECTION);
173172
$hasChanged = true;
174173
}
@@ -217,7 +216,7 @@ private function processNativeType(Param|Property $paramOrProperty): bool
217216
$hasCollectionName = $this->hasCollectionName($paramOrProperty);
218217

219218
$hasChanged = false;
220-
if ($this->isName($paramOrProperty->type, ArrayCollection::class)) {
219+
if ($this->isName($paramOrProperty->type, DoctrineClass::ARRAY_COLLECTION)) {
221220
$paramOrProperty->type = new FullyQualified(DoctrineClass::COLLECTION);
222221
return true;
223222
}
@@ -230,7 +229,7 @@ private function processNativeType(Param|Property $paramOrProperty): bool
230229
return null;
231230
}
232231

233-
if (! $this->isName($node, ArrayCollection::class)) {
232+
if (! $this->isName($node, DoctrineClass::ARRAY_COLLECTION)) {
234233
return null;
235234
}
236235

rules/TypedCollections/Rector/ClassMethod/ReturnArrayToNewArrayCollectionRector.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

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

7-
use Doctrine\Common\Collections\ArrayCollection;
87
use PhpParser\Node;
98
use PhpParser\Node\Arg;
109
use PhpParser\Node\Expr;
@@ -100,7 +99,7 @@ public function refactor(Node $node): ?ClassMethod
10099
return null;
101100
}
102101

103-
$node->expr = new New_(new FullyQualified(ArrayCollection::class), [new Arg($node->expr)]);
102+
$node->expr = new New_(new FullyQualified(DoctrineClass::ARRAY_COLLECTION), [new Arg($node->expr)]);
104103
$hasChanged = true;
105104

106105
return $node;

rules/TypedCollections/Rector/Class_/DefaultNewArrayCollectionRector.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

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

7-
use Doctrine\Common\Collections\ArrayCollection;
8-
use Doctrine\Common\Collections\Collection;
97
use PhpParser\Modifiers;
108
use PhpParser\Node;
119
use PhpParser\Node\Expr\Assign;
@@ -17,6 +15,7 @@
1715
use PhpParser\Node\Stmt\ClassMethod;
1816
use PhpParser\Node\Stmt\Expression;
1917
use PHPStan\Type\ObjectType;
18+
use Rector\Doctrine\Enum\DoctrineClass;
2019
use Rector\NodeManipulator\ClassInsertManipulator;
2120
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
2221
use Rector\Rector\AbstractRector;
@@ -185,7 +184,7 @@ private function createDefaultPropertyAssigns(array $missingDefaultProperties):
185184
foreach ($missingDefaultProperties as $missingDefaultProperty) {
186185
$propertyFetch = new PropertyFetch(new Variable('this'), $missingDefaultProperty);
187186
$missingDefaultPropertyAssign = new Assign($propertyFetch, new New_(new FullyQualified(
188-
ArrayCollection::class
187+
DoctrineClass::ARRAY_COLLECTION
189188
)));
190189

191190
$propertyDefaultAssigns[] = new Expression($missingDefaultPropertyAssign);
@@ -207,7 +206,7 @@ private function resolveCollectionPropertyNames(Class_ $class): array
207206
continue;
208207
}
209208

210-
if ($propertyType->getClassName() !== Collection::class) {
209+
if ($propertyType->getClassName() !== DoctrineClass::COLLECTION) {
211210
continue;
212211
}
213212

rules/TypedCollections/Rector/New_/RemoveNewArrayCollectionWrapRector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

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

7-
use Doctrine\Common\Collections\ArrayCollection;
87
use PhpParser\Node;
98
use PhpParser\Node\Expr;
109
use PhpParser\Node\Expr\New_;
10+
use Rector\Doctrine\Enum\DoctrineClass;
1111
use Rector\Doctrine\TypedCollections\TypeAnalyzer\CollectionTypeDetector;
1212
use Rector\Rector\AbstractRector;
1313
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
@@ -77,7 +77,7 @@ public function refactor(Node $node): ?Expr
7777
return null;
7878
}
7979

80-
if (! $this->isName($node->class, ArrayCollection::class)) {
80+
if (! $this->isName($node->class, DoctrineClass::ARRAY_COLLECTION)) {
8181
return null;
8282
}
8383

0 commit comments

Comments
 (0)