From 3b1330c40f67b31083c07a9fa707af480293ba6c Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Tue, 20 Nov 2018 22:04:29 +0100 Subject: [PATCH] Optimized entity mapping --- application/src/Entity/Meta/Law.php | 2 +- application/src/Entity/Meta/Relation.php | 2 +- application/src/Entity/Meta/Right.php | 2 +- .../Combination/FullPersonNameSource.php | 18 ++++++++++++++++++ .../Source/Data/Name/AbstractNameSource.php | 2 +- .../Source/Data/Name/FirstNameSource.php | 8 +++++++- .../Entity/Source/Data/Name/NicknameSource.php | 3 +-- .../Entity/Source/Data/Name/SurnameSource.php | 3 +-- .../Entity/Source/Operation/AndOperation.php | 2 +- .../Unit/Repository/UserRepositoryTest.php | 2 ++ 10 files changed, 34 insertions(+), 10 deletions(-) diff --git a/application/src/Entity/Meta/Law.php b/application/src/Entity/Meta/Law.php index 24710a6..7077621 100644 --- a/application/src/Entity/Meta/Law.php +++ b/application/src/Entity/Meta/Law.php @@ -12,7 +12,7 @@ use App\Entity\Attribut\RelationAttribut; * @ORM\Table(name="meta_law") * @ORM\Entity(repositoryClass="App\Repository\LawRepository") */ -final class Law extends AbstractMeta implements LawInterface +class Law extends AbstractMeta implements LawInterface { use RightsAttribute, RelationAttribut; diff --git a/application/src/Entity/Meta/Relation.php b/application/src/Entity/Meta/Relation.php index 054cd28..17b3b36 100644 --- a/application/src/Entity/Meta/Relation.php +++ b/application/src/Entity/Meta/Relation.php @@ -22,7 +22,7 @@ use Doctrine\Common\Collections\Collection; * @ORM\Table(name="meta_relation") * @ORM\Entity() */ -final class Relation extends AbstractMeta implements RelationInterface +class Relation extends AbstractMeta implements RelationInterface { use IdAttribut, SourceAttribut, diff --git a/application/src/Entity/Meta/Right.php b/application/src/Entity/Meta/Right.php index 4da8fdf..2a3263e 100644 --- a/application/src/Entity/Meta/Right.php +++ b/application/src/Entity/Meta/Right.php @@ -20,7 +20,7 @@ use App\Entity\Attribut\RelationAttribut; * @ORM\Table(name="meta_right") * @ORM\Entity(repositoryClass="App\Repository\RightRepository") */ -final class Right extends AbstractMeta implements RightInterface +class Right extends AbstractMeta implements RightInterface { use TypeAttribut,LawAttribut, RelationAttribut, GrantAttribut,ConditionAttribut,RecieverAttribut,LayerAttribut; diff --git a/application/src/Entity/Source/Combination/FullPersonNameSource.php b/application/src/Entity/Source/Combination/FullPersonNameSource.php index a3d3a85..6f3daac 100644 --- a/application/src/Entity/Source/Combination/FullPersonNameSource.php +++ b/application/src/Entity/Source/Combination/FullPersonNameSource.php @@ -7,6 +7,8 @@ use App\Entity\Attribut\SurnameSourceAttribut; use App\Entity\Source\Data\Name\SurnameSource; use App\Entity\Source\Data\Name\FirstNameSource; use Doctrine\ORM\Mapping as ORM; +use App\Entity\Source\Data\Name\SurnameSourceInterface; +use App\Entity\Source\Data\Name\FirstNameSourceInterface; /** * @author kevinfrantz @@ -17,6 +19,22 @@ class FullPersonNameSource extends AbstractCombinationSource implements FullPers { use FirstNameSourceAttribut,SurnameSourceAttribut; + /** + * @ORM\OneToOne(targetEntity="App\Entity\Source\Data\Name\SurnameSource",cascade={"persist", "remove"}) + * @ORM\JoinColumn(name="surname_id", referencedColumnName="id",onDelete="CASCADE") + * + * @var SurnameSourceInterface + */ + protected $surnameSource; + + /** + * @ORM\OneToOne(targetEntity="App\Entity\Source\Data\Name\FirstNameSource",cascade={"persist", "remove"}) + * @ORM\JoinColumn(name="firstname_id", referencedColumnName="id",onDelete="CASCADE") + * + * @var FirstNameSourceInterface + */ + protected $firstnNameSource; + public function __construct() { parent::__construct(); diff --git a/application/src/Entity/Source/Data/Name/AbstractNameSource.php b/application/src/Entity/Source/Data/Name/AbstractNameSource.php index 8559f3f..b025bcf 100644 --- a/application/src/Entity/Source/Data/Name/AbstractNameSource.php +++ b/application/src/Entity/Source/Data/Name/AbstractNameSource.php @@ -16,7 +16,7 @@ use Symfony\Component\Validator\Constraints as Assert; * @ORM\DiscriminatorColumn(name="discr", type="string") * @ORM\DiscriminatorMap({"nickname" = "NicknameSource","firstname" = "FirstNameSource", "surname" = "SurnameSource"}) */ -abstract class AbstractNameSource extends AbstractDataSource implements NameSourceInterface +class AbstractNameSource extends AbstractDataSource implements NameSourceInterface { use NameAttribut; diff --git a/application/src/Entity/Source/Data/Name/FirstNameSource.php b/application/src/Entity/Source/Data/Name/FirstNameSource.php index 6f252c3..27756b0 100644 --- a/application/src/Entity/Source/Data/Name/FirstNameSource.php +++ b/application/src/Entity/Source/Data/Name/FirstNameSource.php @@ -2,6 +2,12 @@ namespace App\Entity\Source\Data\Name; -final class FirstNameSource extends AbstractNameSource implements FirstNameSourceInterface +use Doctrine\ORM\Mapping as ORM; + +/** + * @author kevinfrantz + * @ORM\Entity() + */ +class FirstNameSource extends AbstractNameSource implements FirstNameSourceInterface { } diff --git a/application/src/Entity/Source/Data/Name/NicknameSource.php b/application/src/Entity/Source/Data/Name/NicknameSource.php index 7cbdf70..5cddb4b 100644 --- a/application/src/Entity/Source/Data/Name/NicknameSource.php +++ b/application/src/Entity/Source/Data/Name/NicknameSource.php @@ -6,9 +6,8 @@ use Doctrine\ORM\Mapping as ORM; /** * @author kevinfrantz - * @ORM\Table(name="source_data_name_nickname") * @ORM\Entity() */ -final class NicknameSource extends AbstractNameSource implements NicknameSourceInterface +class NicknameSource extends AbstractNameSource implements NicknameSourceInterface { } diff --git a/application/src/Entity/Source/Data/Name/SurnameSource.php b/application/src/Entity/Source/Data/Name/SurnameSource.php index 5733e45..6155c28 100644 --- a/application/src/Entity/Source/Data/Name/SurnameSource.php +++ b/application/src/Entity/Source/Data/Name/SurnameSource.php @@ -6,9 +6,8 @@ use Doctrine\ORM\Mapping as ORM; /** * @author kevinfrantz - * @ORM\Table(name="source_data_name_surname") * @ORM\Entity() */ -final class SurnameSource extends AbstractNameSource implements SurnameSourceInterface +class SurnameSource extends AbstractNameSource implements SurnameSourceInterface { } diff --git a/application/src/Entity/Source/Operation/AndOperation.php b/application/src/Entity/Source/Operation/AndOperation.php index f24efd2..523d7dd 100644 --- a/application/src/Entity/Source/Operation/AndOperation.php +++ b/application/src/Entity/Source/Operation/AndOperation.php @@ -14,7 +14,7 @@ use App\Exception\NotDefinedException; * * @todo move to the logic level! */ -final class AndOperation extends AbstractOperation +class AndOperation extends AbstractOperation { public function process(): void { diff --git a/application/tests/Unit/Repository/UserRepositoryTest.php b/application/tests/Unit/Repository/UserRepositoryTest.php index 15ad890..ccc8a7d 100644 --- a/application/tests/Unit/Repository/UserRepositoryTest.php +++ b/application/tests/Unit/Repository/UserRepositoryTest.php @@ -53,6 +53,8 @@ class UserRepositoryTest extends KernelTestCase $this->assertGreaterThan(0, $this->loadedUser->getSource()->getId()); $this->assertGreaterThan(0, $this->loadedUser->getSource()->getPersonIdentitySource()->getId()); $this->assertGreaterThan(0, $this->loadedUser->getSource()->getPersonIdentitySource()->getFullPersonNameSource()->getId()); + $this->assertGreaterThan(0, $this->loadedUser->getSource()->getPersonIdentitySource()->getFullPersonNameSource()->getFirstNameSource()->getId()); + $this->assertGreaterThan(0, $this->loadedUser->getSource()->getPersonIdentitySource()->getFullPersonNameSource()->getSurnameSource()->getId()); $this->deleteUser(); $this->assertNull($this->userRepository->find($userId)); $this->loadedUser = null;