mirror of
https://github.com/rectorphp/rector.git
synced 2024-07-22 17:30:23 +00:00
add relation property only when target entity has uuid
This commit is contained in:
parent
c040e15fb5
commit
62655ea194
@ -96,7 +96,7 @@ final class AddUuidMirrorForRelationPropertyRector extends AbstractRector
|
||||
*/
|
||||
private function createMirrorNullable(Property $property): Property
|
||||
{
|
||||
$oldProperytName = $this->getName($property);
|
||||
$oldPropertyName = $this->getName($property);
|
||||
|
||||
$propertyWithUuid = clone $property;
|
||||
|
||||
@ -105,11 +105,11 @@ final class AddUuidMirrorForRelationPropertyRector extends AbstractRector
|
||||
|
||||
// name must be changed after the doc comment update, because the reflection annotation needed for update of doc comment
|
||||
// would miss non existing *Uuid property
|
||||
$uuidPropertyName = $oldProperytName . 'Uuid';
|
||||
$uuidPropertyName = $oldPropertyName . 'Uuid';
|
||||
$newPropertyProperty = new PropertyProperty(new VarLikeIdentifier($uuidPropertyName));
|
||||
$propertyWithUuid->props = [$newPropertyProperty];
|
||||
|
||||
$this->addNewPropertyToCollector($property, $oldProperytName, $uuidPropertyName);
|
||||
$this->addNewPropertyToCollector($property, $oldPropertyName, $uuidPropertyName);
|
||||
|
||||
return $propertyWithUuid;
|
||||
}
|
||||
@ -186,6 +186,10 @@ final class AddUuidMirrorForRelationPropertyRector extends AbstractRector
|
||||
return true;
|
||||
}
|
||||
|
||||
if (! property_exists($targetEntity, 'uuid')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@ final class AddUuidMirrorForRelationPropertyRectorTest extends AbstractRectorTes
|
||||
yield [__DIR__ . '/Fixture/to_one.php.inc'];
|
||||
yield [__DIR__ . '/Fixture/to_many.php.inc'];
|
||||
yield [__DIR__ . '/Fixture/skip_already_added.php.inc'];
|
||||
yield [__DIR__ . '/Fixture/skip_to_many_without_target_entity_uuid.php.inc'];
|
||||
}
|
||||
|
||||
protected function getRectorClass(): string
|
||||
|
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Doctrine\Tests\Rector\Class_\AddUuidMirrorForRelationPropertyRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="wohoo")
|
||||
*/
|
||||
class SkipTooManyWithoutTargetEntityUuid
|
||||
{
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity="Rector\Doctrine\Tests\Rector\Class_\AddUuidMirrorForRelationPropertyRector\Fixture\FooEntityWithoutUuid", cascade={"persist", "merge"})
|
||||
*/
|
||||
private $amenity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class FooEntityWithoutUuid
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
}
|
@ -28,6 +28,8 @@ class FooEntity
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
private $uuid;
|
||||
}
|
||||
|
||||
?>
|
||||
@ -67,6 +69,8 @@ class FooEntity
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
private $uuid;
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -28,6 +28,8 @@ class AnotherEntity
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
private $uuid;
|
||||
}
|
||||
|
||||
?>
|
||||
@ -67,6 +69,8 @@ class AnotherEntity
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
private $uuid;
|
||||
}
|
||||
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user