mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-11-04 03:07:58 +00:00 
			
		
		
		
	Optimized RequestManagement and tests
This commit is contained in:
		@@ -6,6 +6,8 @@ use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 *
 | 
			
		||||
 * @see RequestedEntityAttributInterface
 | 
			
		||||
 */
 | 
			
		||||
trait RequestedEntityAttribut
 | 
			
		||||
{
 | 
			
		||||
@@ -29,4 +31,12 @@ trait RequestedEntityAttribut
 | 
			
		||||
    {
 | 
			
		||||
        $this->requestedEntity = $requestedEntity;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return bool
 | 
			
		||||
     */
 | 
			
		||||
    public function hasRequestedEntity(): bool
 | 
			
		||||
    {
 | 
			
		||||
        return isset($this->requestedEntity);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -9,6 +9,11 @@ use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
 | 
			
		||||
 */
 | 
			
		||||
interface RequestedEntityAttributInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @return bool
 | 
			
		||||
     */
 | 
			
		||||
    public function hasRequestedEntity(): bool;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return RequestedEntityInterface
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
@@ -24,6 +24,14 @@ trait RequestedRightAttribut
 | 
			
		||||
        $this->requestedRight = $requestedRight;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return bool
 | 
			
		||||
     */
 | 
			
		||||
    public function hasRequestedRight(): bool
 | 
			
		||||
    {
 | 
			
		||||
        return isset($this->requestedRight);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return RequestedRightInterface
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
@@ -9,6 +9,11 @@ use App\Domain\RequestManagement\Right\RequestedRightInterface;
 | 
			
		||||
 */
 | 
			
		||||
interface RequestedRightAttributInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @return bool
 | 
			
		||||
     */
 | 
			
		||||
    public function hasRequestedRight(): bool;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param RequestedRightInterface $requestedRight
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
@@ -14,6 +14,7 @@ use App\Entity\Source\AbstractSource;
 | 
			
		||||
use App\Exception\NotSetException;
 | 
			
		||||
use App\Repository\RepositoryInterface;
 | 
			
		||||
use App\Entity\Source\SourceInterface;
 | 
			
		||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
@@ -53,19 +54,44 @@ class RequestedEntity extends AbstractEntity implements RequestedEntityInterface
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @throws NotSetException
 | 
			
		||||
     */
 | 
			
		||||
    private function validateHasIdentity(): void
 | 
			
		||||
    {
 | 
			
		||||
        if (!($this->hasId() || $this->hasSlug())) {
 | 
			
		||||
            throw new NotSetException('No identity attribut like id or slug was set!');
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param EntityInterface|null $entity
 | 
			
		||||
     *
 | 
			
		||||
     * @throws NotFoundHttpException
 | 
			
		||||
     */
 | 
			
		||||
    private function validateLoadedEntity(?EntityInterface $entity): void
 | 
			
		||||
    {
 | 
			
		||||
        if (!$entity) {
 | 
			
		||||
            throw new NotFoundHttpException('Entity with {id:"'.$this->id.'",slug:"'.$this->slug.'"} not found');
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Sorry for the messed function, but should work ;)
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     *
 | 
			
		||||
     * @see \App\Domain\RequestManagement\Entity\RequestedEntityInterface::getEntity()
 | 
			
		||||
     */
 | 
			
		||||
    public function getEntity(): EntityInterface
 | 
			
		||||
    {
 | 
			
		||||
        $this->validateHasIdentity();
 | 
			
		||||
        if ($this->hasSlug()) {
 | 
			
		||||
            return $this->loadBySlug();
 | 
			
		||||
            $entity = $this->loadBySlug();
 | 
			
		||||
        } elseif ($this->hasId()) {
 | 
			
		||||
            $entity = $this->loadById();
 | 
			
		||||
        }
 | 
			
		||||
        if ($this->hasId()) {
 | 
			
		||||
            return $this->loadById();
 | 
			
		||||
        }
 | 
			
		||||
        throw new NotSetException('No identity attribut like id or slug was set!');
 | 
			
		||||
        $this->validateLoadedEntity($entity);
 | 
			
		||||
 | 
			
		||||
        return $entity;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -82,9 +108,9 @@ class RequestedEntity extends AbstractEntity implements RequestedEntityInterface
 | 
			
		||||
    /**
 | 
			
		||||
     * @throws NotCorrectInstanceException
 | 
			
		||||
     *
 | 
			
		||||
     * @return SourceInterface
 | 
			
		||||
     * @return SourceInterface|null
 | 
			
		||||
     */
 | 
			
		||||
    private function loadBySlug(): SourceInterface
 | 
			
		||||
    private function loadBySlug(): ?SourceInterface
 | 
			
		||||
    {
 | 
			
		||||
        $repository = $this->getEntityRepository();
 | 
			
		||||
        if ($repository instanceof SourceRepositoryInterface) {
 | 
			
		||||
@@ -94,9 +120,9 @@ class RequestedEntity extends AbstractEntity implements RequestedEntityInterface
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return EntityInterface
 | 
			
		||||
     * @return EntityInterface|null
 | 
			
		||||
     */
 | 
			
		||||
    private function loadById(): EntityInterface
 | 
			
		||||
    private function loadById(): ?EntityInterface
 | 
			
		||||
    {
 | 
			
		||||
        $repository = $this->getEntityRepository();
 | 
			
		||||
 | 
			
		||||
@@ -112,7 +138,7 @@ class RequestedEntity extends AbstractEntity implements RequestedEntityInterface
 | 
			
		||||
    public function setRequestedRight($requestedRight): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->requestedRight = $requestedRight;
 | 
			
		||||
        if ($this->requestedRight !== $this) {
 | 
			
		||||
        if (!$this->requestedRight->hasRequestedEntity()) {
 | 
			
		||||
            $this->requestedRight->setRequestedEntity($this);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -114,4 +114,14 @@ abstract class AbstractRequestedRightFacade implements RequestedRightInterface
 | 
			
		||||
    {
 | 
			
		||||
        $this->requestedRight->setReciever($reciever);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     *
 | 
			
		||||
     * @see \App\Attribut\RequestedEntityAttributInterface::hasRequestedEntity()
 | 
			
		||||
     */
 | 
			
		||||
    public function hasRequestedEntity(): bool
 | 
			
		||||
    {
 | 
			
		||||
        $this->requestedRight->hasRequestedEntity();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -27,11 +27,6 @@ class RequestedRight implements RequestedRightInterface
 | 
			
		||||
     */
 | 
			
		||||
    private $source;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var RequestedEntityInterface
 | 
			
		||||
     */
 | 
			
		||||
    private $requestedEntity;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @throws NotCorrectInstanceException
 | 
			
		||||
     */
 | 
			
		||||
@@ -40,11 +35,15 @@ class RequestedRight implements RequestedRightInterface
 | 
			
		||||
        $entity = $this->requestedEntity->getEntity();
 | 
			
		||||
        if ($entity instanceof SourceInterface) {
 | 
			
		||||
            $this->source = $entity;
 | 
			
		||||
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        if ($entity instanceof MetaInterface) {
 | 
			
		||||
            $this->source = $entity->getSource();
 | 
			
		||||
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        throw new NotCorrectInstanceException('The entity instance can\'t be processed');
 | 
			
		||||
        throw new NotCorrectInstanceException('The entity instance '.get_class($entity).' can\'t be processed');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -92,7 +91,7 @@ class RequestedRight implements RequestedRightInterface
 | 
			
		||||
    final public function setRequestedEntity(RequestedEntityInterface $requestedEntity): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->requestedEntity = $requestedEntity;
 | 
			
		||||
        if ($requestedEntity->getRequestedRight() !== $this) {
 | 
			
		||||
        if (!$requestedEntity->hasRequestedRight()) {
 | 
			
		||||
            $this->requestedEntity->setRequestedRight($this);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user