Declared function hasIdentity public

This commit is contained in:
Kevin Frantz 2019-02-03 13:57:49 +01:00
parent 4ac7b3a19b
commit c3b8e1a92d
3 changed files with 27 additions and 32 deletions

View File

@ -1,4 +1,5 @@
<?php <?php
namespace App\Domain\RequestManagement\Entity; namespace App\Domain\RequestManagement\Entity;
use App\Entity\AbstractEntity; use App\Entity\AbstractEntity;
@ -17,10 +18,8 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use App\Attribut\ClassAttribut; use App\Attribut\ClassAttribut;
use App\Exception\AllreadyDefinedException; use App\Exception\AllreadyDefinedException;
use App\Domain\RequestManagement\Right\RequestedRightInterface; use App\Domain\RequestManagement\Right\RequestedRightInterface;
use App\Exception\NotDefinedException;
/** /**
*
* @author kevinfrantz * @author kevinfrantz
*/ */
class RequestedEntity extends AbstractEntity implements RequestedEntityInterface class RequestedEntity extends AbstractEntity implements RequestedEntityInterface
@ -30,22 +29,11 @@ class RequestedEntity extends AbstractEntity implements RequestedEntityInterface
ClassAttribut{ setClass as private setClassTrait; getClass as private getClassTrait; } ClassAttribut{ setClass as private setClassTrait; getClass as private getClassTrait; }
/** /**
*
* @var LayerRepositoryFactoryServiceInterface * @var LayerRepositoryFactoryServiceInterface
*/ */
private $layerRepositoryFactoryService; private $layerRepositoryFactoryService;
/** /**
*
* @return bool True if an identity attribut is defined
*/
private function hasIdentity(): bool
{
return $this->hasId() || $this->hasSlug();
}
/**
*
* @throws NotSetException * @throws NotSetException
*/ */
private function validateHasIdentity(): void private function validateHasIdentity(): void
@ -56,7 +44,6 @@ class RequestedEntity extends AbstractEntity implements RequestedEntityInterface
} }
/** /**
*
* @param EntityInterface|null $entity * @param EntityInterface|null $entity
* *
* @throws NotFoundHttpException * @throws NotFoundHttpException
@ -69,7 +56,6 @@ class RequestedEntity extends AbstractEntity implements RequestedEntityInterface
} }
/** /**
*
* @return EntityInterface|SourceInterface|null * @return EntityInterface|SourceInterface|null
*/ */
private function loadEntityBySlugOrId(): ?EntityInterface private function loadEntityBySlugOrId(): ?EntityInterface
@ -77,11 +63,11 @@ class RequestedEntity extends AbstractEntity implements RequestedEntityInterface
if ($this->hasSlug()) { if ($this->hasSlug()) {
return $this->loadBySlug(); return $this->loadBySlug();
} }
return $this->loadById(); return $this->loadById();
} }
/** /**
*
* @throws NotCorrectInstanceException * @throws NotCorrectInstanceException
* *
* @return SourceInterface|null * @return SourceInterface|null
@ -96,7 +82,6 @@ class RequestedEntity extends AbstractEntity implements RequestedEntityInterface
} }
/** /**
*
* @return EntityInterface|null * @return EntityInterface|null
*/ */
private function loadById(): ?EntityInterface private function loadById(): ?EntityInterface
@ -107,7 +92,6 @@ class RequestedEntity extends AbstractEntity implements RequestedEntityInterface
} }
/** /**
*
* @return RepositoryInterface * @return RepositoryInterface
*/ */
private function getEntityRepository(): RepositoryInterface private function getEntityRepository(): RepositoryInterface
@ -119,7 +103,6 @@ class RequestedEntity extends AbstractEntity implements RequestedEntityInterface
} }
/** /**
*
* @param EntityManagerInterface $entityManager * @param EntityManagerInterface $entityManager
*/ */
public function __construct(LayerRepositoryFactoryServiceInterface $layerRepositoryFactoryService) public function __construct(LayerRepositoryFactoryServiceInterface $layerRepositoryFactoryService)
@ -128,7 +111,16 @@ class RequestedEntity extends AbstractEntity implements RequestedEntityInterface
} }
/** /**
* {@inheritdoc}
* *
* @see \App\Domain\RequestManagement\Entity\RequestedEntityInterface::hasIdentity()
*/
public function hasIdentity(): bool
{
return $this->hasId() || $this->hasSlug();
}
/**
* {@inheritdoc} * {@inheritdoc}
* *
* @see \App\Domain\RequestManagement\Entity\RequestedEntityInterface::setIdentity() * @see \App\Domain\RequestManagement\Entity\RequestedEntityInterface::setIdentity()
@ -149,7 +141,6 @@ class RequestedEntity extends AbstractEntity implements RequestedEntityInterface
} }
/** /**
*
* {@inheritdoc} * {@inheritdoc}
* *
* @see \App\Attribut\ClassAttributInterface::setClass() * @see \App\Attribut\ClassAttributInterface::setClass()
@ -163,7 +154,6 @@ class RequestedEntity extends AbstractEntity implements RequestedEntityInterface
} }
/** /**
*
* {@inheritdoc} * {@inheritdoc}
* *
* @see \App\Domain\RequestManagement\Entity\RequestedEntityInterface::getEntity() * @see \App\Domain\RequestManagement\Entity\RequestedEntityInterface::getEntity()
@ -178,7 +168,7 @@ class RequestedEntity extends AbstractEntity implements RequestedEntityInterface
} }
/** /**
* Overriding is neccessary to declare the correct relation * Overriding is neccessary to declare the correct relation.
* *
* {@inheritdoc} * {@inheritdoc}
* *
@ -193,7 +183,6 @@ class RequestedEntity extends AbstractEntity implements RequestedEntityInterface
} }
/** /**
*
* {@inheritdoc} * {@inheritdoc}
* *
* @see \App\Attribut\ClassAttributInterface::getClass() * @see \App\Attribut\ClassAttributInterface::getClass()

View File

@ -21,6 +21,11 @@ interface RequestedEntityInterface extends EntityInterface, SlugAttributInterfac
*/ */
public function setIdentity($identity): void; public function setIdentity($identity): void;
/**
* @return bool True if an identity attribut is defined
*/
public function hasIdentity(): bool;
/** /**
* @return EntityInterface * @return EntityInterface
*/ */

View File

@ -73,7 +73,8 @@ class RequestedEntityTest extends TestCase
$requestedEntity->setClass(AbstractSource::class); $requestedEntity->setClass(AbstractSource::class);
} }
public function testSetClass():void{ public function testSetClass(): void
{
$class = AbstractSource::class; $class = AbstractSource::class;
$entityMock = $this->createMock(EntityInterface::class); $entityMock = $this->createMock(EntityInterface::class);
$repository = $this->createMock(RepositoryInterface::class); $repository = $this->createMock(RepositoryInterface::class);