Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Rector\Doctrine\Collector\UuidMigrationDataCollector;
use Rector\Doctrine\PhpDocParser\Ast\PhpDoc\PhpDocTagNodeFactory;
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\Property_\JoinColumnTagValueNode;
use Rector\DoctrinePhpDocParser\Ast\PhpDoc\Property_\OneToOneTagValueNode;
use Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc\DoctrineRelationTagValueNodeInterface;
use Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc\ToManyTagNodeInterface;
use Rector\DoctrinePhpDocParser\Contract\Ast\PhpDoc\ToOneTagNodeInterface;
Expand Down Expand Up @@ -176,7 +177,6 @@ private function shouldSkipProperty(Class_ $class, Property $property): bool
}

$uuidPropertyName = $this->getName($property) . 'Uuid';

if ($this->hasClassPropertyName($class, $uuidPropertyName)) {
return true;
}
Expand All @@ -190,6 +190,20 @@ private function shouldSkipProperty(Class_ $class, Property $property): bool
return true;
}

/** @var PhpDocInfo|null $propertyPhpDocInfo */
$propertyPhpDocInfo = $this->getPhpDocInfo($property);
if ($propertyPhpDocInfo === null) {
return true;
}

$oneToOneTagValueNode = $propertyPhpDocInfo->getByType(OneToOneTagValueNode::class);
if ($oneToOneTagValueNode) {
// skip mappedBy oneToOne, as the column doesn't really exist
if ($oneToOneTagValueNode->getMappedBy()) {
return true;
}
}

return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ public function provideDataForTest(): iterable
{
yield [__DIR__ . '/Fixture/to_one.php.inc'];
yield [__DIR__ . '/Fixture/to_many.php.inc'];
// skip
yield [__DIR__ . '/Fixture/skip_already_added.php.inc'];
yield [__DIR__ . '/Fixture/skip_to_many_without_target_entity_uuid.php.inc'];
yield [__DIR__ . '/Fixture/skip_one_to_one_mapped_by.php.inc'];
}

protected function getRectorClass(): string
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Rector\Doctrine\Tests\Rector\Class_\AddUuidMirrorForRelationPropertyRector\Fixture;

use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
*/
class SkipOneToOne
{
/**
* @ORM\OneToOne(targetEntity="Rector\Doctrine\Tests\Rector\Class_\AddUuidMirrorForRelationPropertyRector\Fixture\EntityOneToOne", cascade={"persist", "merge"}, mappedBy="skip")
* @ORM\JoinColumn(nullable=false)
*/
private $amenity;
}

/**
* @ORM\Entity
*/
class EntityOneToOne
{
/**
* @var int
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;

private $uuid;

private $skip;
}