Skip to content

Commit

Permalink
Skip Columns from TypedPropertyFromAssignsRector, as handled better i…
Browse files Browse the repository at this point in the history
…n doctrine rules (#6254)
  • Loading branch information
TomasVotruba authored Aug 23, 2024
1 parent c9470e4 commit 1884cdd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector\Fixture\Doctrine;

use Doctrine\ORM\Mapping as ORM;

final class SkipColumn
{
/**
* @ORM\Column(name="userID", type="integer", nullable=false)
* @ORM\Id
*/
private $someId = '0';
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Rector\Contract\Rector\ConfigurableRectorInterface;
use Rector\DeadCode\PhpDoc\TagRemover\VarTagRemover;
use Rector\Doctrine\CodeQuality\Enum\CollectionMapping;
use Rector\Doctrine\Enum\MappingClass;
use Rector\Doctrine\NodeAnalyzer\AttrinationFinder;
use Rector\Php74\Guard\MakePropertyTypedGuard;
use Rector\PhpParser\Node\Value\ValueResolver;
Expand Down Expand Up @@ -135,8 +136,7 @@ public function refactor(Node $node): ?Node
continue;
}

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

Expand Down Expand Up @@ -217,4 +217,18 @@ private function decorateTypeWithNullableIfDefaultPropertyNull(Property $propert

return TypeCombinator::addNull($inferredType);
}

/**
* Doctrine properties are handled in doctrine rules
*/
private function isDoctrineMappedProperty(Property $property): bool
{
$mappingClasses = array_merge(
CollectionMapping::TO_MANY_CLASSES,
CollectionMapping::TO_ONE_CLASSES,
[MappingClass::COLUMN]
);

return $this->attrinationFinder->hasByMany($property, $mappingClasses);
}
}

0 comments on commit 1884cdd

Please sign in to comment.