Skip to content

Commit 1884cdd

Browse files
authored
Skip Columns from TypedPropertyFromAssignsRector, as handled better in doctrine rules (#6254)
1 parent c9470e4 commit 1884cdd

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector\Fixture\Doctrine;
4+
5+
use Doctrine\ORM\Mapping as ORM;
6+
7+
final class SkipColumn
8+
{
9+
/**
10+
* @ORM\Column(name="userID", type="integer", nullable=false)
11+
* @ORM\Id
12+
*/
13+
private $someId = '0';
14+
}

rules/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Rector\Contract\Rector\ConfigurableRectorInterface;
2020
use Rector\DeadCode\PhpDoc\TagRemover\VarTagRemover;
2121
use Rector\Doctrine\CodeQuality\Enum\CollectionMapping;
22+
use Rector\Doctrine\Enum\MappingClass;
2223
use Rector\Doctrine\NodeAnalyzer\AttrinationFinder;
2324
use Rector\Php74\Guard\MakePropertyTypedGuard;
2425
use Rector\PhpParser\Node\Value\ValueResolver;
@@ -135,8 +136,7 @@ public function refactor(Node $node): ?Node
135136
continue;
136137
}
137138

138-
// doctrine colleciton is handled in doctrine rules
139-
if ($this->attrinationFinder->hasByMany($property, CollectionMapping::TO_MANY_CLASSES)) {
139+
if ($this->isDoctrineMappedProperty($property)) {
140140
continue;
141141
}
142142

@@ -217,4 +217,18 @@ private function decorateTypeWithNullableIfDefaultPropertyNull(Property $propert
217217

218218
return TypeCombinator::addNull($inferredType);
219219
}
220+
221+
/**
222+
* Doctrine properties are handled in doctrine rules
223+
*/
224+
private function isDoctrineMappedProperty(Property $property): bool
225+
{
226+
$mappingClasses = array_merge(
227+
CollectionMapping::TO_MANY_CLASSES,
228+
CollectionMapping::TO_ONE_CLASSES,
229+
[MappingClass::COLUMN]
230+
);
231+
232+
return $this->attrinationFinder->hasByMany($property, $mappingClasses);
233+
}
220234
}

0 commit comments

Comments
 (0)