From e8c7623a1e3fe6c0c8ea488bce94c459011a5235 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 8 Apr 2024 12:13:39 +0200 Subject: [PATCH] Refactor Relationship entity to use traits The Relationship entity in ChillPersonBundle has been refactored to use TrackCreationTrait and TrackUpdateTrait. As a result, the redundant code for handling creation and update tracking has been removed. This change will simplify future development by reusing core functionality from the trait instead of manually controlling the process in each entity. --- .../Entity/Relationships/Relationship.php | 65 ++----------------- 1 file changed, 4 insertions(+), 61 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Entity/Relationships/Relationship.php b/src/Bundle/ChillPersonBundle/Entity/Relationships/Relationship.php index 4e658575b..2325f4221 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Relationships/Relationship.php +++ b/src/Bundle/ChillPersonBundle/Entity/Relationships/Relationship.php @@ -12,8 +12,9 @@ declare(strict_types=1); namespace Chill\PersonBundle\Entity\Relationships; use Chill\MainBundle\Doctrine\Model\TrackCreationInterface; +use Chill\MainBundle\Doctrine\Model\TrackCreationTrait; use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface; -use Chill\MainBundle\Entity\User; +use Chill\MainBundle\Doctrine\Model\TrackUpdateTrait; use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Validator\Constraints\Relationship\RelationshipNoDuplicate; use Doctrine\ORM\Mapping as ORM; @@ -30,12 +31,8 @@ use Symfony\Component\Validator\Constraints as Assert; #[RelationshipNoDuplicate] class Relationship implements TrackCreationInterface, TrackUpdateInterface { - #[ORM\Column(type: \Doctrine\DBAL\Types\Types::DATETIME_IMMUTABLE)] - private ?\DateTimeImmutable $createdAt = null; - - #[ORM\ManyToOne(targetEntity: User::class)] - #[ORM\JoinColumn(nullable: false)] - private ?User $createdBy = null; + use TrackCreationTrait; + use TrackUpdateTrait; #[Assert\NotNull] #[Serializer\Groups(['read', 'write'])] @@ -66,22 +63,6 @@ class Relationship implements TrackCreationInterface, TrackUpdateInterface #[ORM\JoinColumn(nullable: false)] private ?Person $toPerson = null; - #[ORM\Column(type: \Doctrine\DBAL\Types\Types::DATETIME_IMMUTABLE, nullable: true)] - private ?\DateTimeImmutable $updatedAt = null; - - #[ORM\ManyToOne(targetEntity: User::class)] - private ?User $updatedBy = null; - - public function getCreatedAt(): ?\DateTimeImmutable - { - return $this->createdAt; - } - - public function getCreatedBy(): ?User - { - return $this->createdBy; - } - public function getFromPerson(): ?Person { return $this->fromPerson; @@ -134,30 +115,6 @@ class Relationship implements TrackCreationInterface, TrackUpdateInterface return $this->toPerson; } - public function getUpdatedAt(): ?\DateTimeImmutable - { - return $this->updatedAt; - } - - public function getUpdatedBy(): ?User - { - return $this->updatedBy; - } - - public function setCreatedAt(\DateTimeInterface $createdAt): self - { - $this->createdAt = $createdAt; - - return $this; - } - - public function setCreatedBy(?User $user): self - { - $this->createdBy = $user; - - return $this; - } - public function setFromPerson(?Person $fromPerson): self { $this->fromPerson = $fromPerson; @@ -185,18 +142,4 @@ class Relationship implements TrackCreationInterface, TrackUpdateInterface return $this; } - - public function setUpdatedAt(?\DateTimeInterface $updatedAt): self - { - $this->updatedAt = $updatedAt; - - return $this; - } - - public function setUpdatedBy(?User $updatedBy): self - { - $this->updatedBy = $updatedBy; - - return $this; - } }