Finished refactoring of exceptions

This commit is contained in:
Kevin Frantz
2019-04-15 01:37:17 +02:00
parent 9f179ead73
commit 06f69675ac
49 changed files with 159 additions and 135 deletions

View File

@@ -3,8 +3,8 @@
namespace Infinito\Domain\ActionManagement;
use Infinito\Entity\EntityInterface;
use Infinito\Exception\NotSecureException;
use Infinito\Exception\NotValidByFormException;
use Infinito\Exception\Validation\FormInvalidException;
use Infinito\Exception\Permission\NoPermissionException;
/**
* @author kevinfrantz
@@ -50,8 +50,8 @@ abstract class AbstractAction extends AbstractActionConstructor implements Actio
if ($this->isValid()) {
return $this->proccess();
}
throw new NotValidByFormException('The requested Entity is not valid!');
throw new FormInvalidException('The requested Entity is not valid!');
}
throw new NotSecureException("You don't have the permission to execute this action!");
throw new NoPermissionException("You don't have the permission to execute this action!");
}
}

View File

@@ -48,6 +48,7 @@ final class ActionsResultsDAOService extends AbstractActionsDAO implements Actio
/**
* @param string $actionType
*
* @throws InvalidChoiceTypeException
*/
private function throwNoValidActionTypeException(string $actionType): void

View File

@@ -5,7 +5,7 @@ namespace Infinito\Domain\FormManagement;
use Symfony\Component\Form\FormBuilderInterface;
use Infinito\Domain\RequestManagement\Action\RequestedActionInterface;
use Symfony\Component\Form\FormFactoryInterface;
use Infinito\Exception\Collection\NotSetException;
use Infinito\Exception\Attribut\UndefinedAttributException;
/**
* @author kevinfrantz
@@ -25,12 +25,12 @@ class RequestedActionFormBuilder implements RequestedActionFormBuilderInterface
/**
* @param RequestedActionInterface $requestedAction
*
* @throws NotSetException If the requested action can't be processed
* @throws UndefinedAttributException If the requested action can't be processed
*/
private function validateRequestedAction(RequestedActionInterface $requestedAction): void
{
if (!$requestedAction->hasRequestedEntity()) {
throw new NotSetException('The <<requested entity>> attribut of a <<requested action>> must be set, to be processed by '.__CLASS__.'!');
throw new UndefinedAttributException('The <<requested entity>> attribut of a <<requested action>> must be set, to be processed by '.__CLASS__.'!');
}
}

View File

@@ -4,7 +4,7 @@ namespace Infinito\Domain\LayerManagement;
use Infinito\DBAL\Types\Meta\Right\LayerType;
use Infinito\Entity\Source\AbstractSource;
use Infinito\Exception\Collection\NotSetException;
use Infinito\Exception\Collection\NotSetElementException;
use Infinito\Entity\Meta\Law;
use Infinito\Entity\Meta\Right;
use Infinito\Entity\Meta\Relation\Parent\HeredityRelation;
@@ -31,7 +31,7 @@ final class LayerClassMap implements LayerClassMapInterface
/**
* @param string $layer
*
* @throws NotSetException
* @throws NotSetElementException
*
* @return string
*/
@@ -40,6 +40,6 @@ final class LayerClassMap implements LayerClassMapInterface
if (array_key_exists($layer, self::LAYER_CLASS_MAP)) {
return self::LAYER_CLASS_MAP[$layer];
}
throw new NotSetException('The requested layer is not mapped!');
throw new NotSetElementException('The requested layer is not mapped!');
}
}

View File

@@ -4,7 +4,7 @@ namespace Infinito\Domain\ParameterManagement;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Request;
use Infinito\Exception\Attribut\UndefinedAttributException;
use Infinito\Exception\Collection\NotSetElementException;
/**
* This class exists out of refactoring reasons.
@@ -71,6 +71,6 @@ abstract class AbstractGetParameterService implements GetParameterServiceInterfa
if ($this->hasParameter($key)) {
return $this->currentRequest->get($key);
}
throw new UndefinedAttributException("The parameter <<$key>> is not defined!");
throw new NotSetElementException("The parameter <<$key>> is not defined!");
}
}

View File

@@ -6,7 +6,7 @@ use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use HaydenPierce\ClassFinder\ClassFinder;
use Infinito\Domain\ParameterManagement\Parameter\ParameterInterface;
use Infinito\Exception\Collection\NotSetElementException;
use Infinito\Exception\Core\NotImplementedCoreException;
/**
* @author kevinfrantz
@@ -67,7 +67,7 @@ final class ParameterFactory implements ParameterFactoryInterface
if ($parameter) {
return $parameter;
}
throw new NotSetElementException("The parameter for key <<$key>> doesn't exist! Generate a parameter class in the parameter folder!");
throw new NotImplementedCoreException("The parameter for key <<$key>> doesn't exist! Generate a parameter class in the parameter folder!");
}
/**

View File

@@ -4,6 +4,7 @@ namespace Infinito\Domain\ParameterManagement;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Infinito\Exception\Validation\GetParameterInvalidException;
/**
* @author kevinfrantz
@@ -34,8 +35,6 @@ final class ValidGetParametersService extends AbstractGetParameterService implem
/**
* @param string $key
*
* @throws UnvalidGetParameterException
*/
protected function validateParameter(string $key): void
{
@@ -43,7 +42,7 @@ final class ValidGetParametersService extends AbstractGetParameterService implem
$parameter->setValue($this->currentRequest->get($key));
$errors = $this->validator->validate($parameter);
foreach ($errors as $error) {
throw new UnvalidGetParameterException("Parameter <<$key>> didn't pass the validation; Message: <<".$error->getMessage().'>> ,Value: <<'.$parameter->getValue().'>> .');
throw new GetParameterInvalidException("Parameter <<$key>> didn't pass the validation; Message: <<".$error->getMessage().'>> ,Value: <<'.$parameter->getValue().'>> .');
}
}
}

View File

@@ -3,10 +3,9 @@
namespace Infinito\Domain\RequestManagement\Action;
use Doctrine\Common\Collections\Collection;
use Infinito\Domain\ReInfinito\Management\RequestedActionStackInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Infinito\Exception\AllreadySetException;
use Infinito\Exception\Collection\NotSetException;
use Infinito\Exception\Collection\ContainsElementException;
use Infinito\Exception\Collection\NotSetElementException;
/**
* @author kevinfrantz
@@ -26,7 +25,7 @@ class RequestedActionStack implements RequestedActionStackInterface
/**
* {@inheritdoc}
*
* @see \Infinito\Domain\ReInfinito\Management\RequestedActionStackInterface::containesRequestedAction()
* @see \Infinito\Domain\RequestManagement\Action\RequestedActionStackInterface::containesRequestedAction()
*/
public function containesRequestedAction(string $actionType): bool
{
@@ -36,13 +35,13 @@ class RequestedActionStack implements RequestedActionStackInterface
/**
* {@inheritdoc}
*
* @see \Infinito\Domain\ReInfinito\Management\RequestedActionStackInterface::addRequestedAction()
* @see \Infinito\Domain\RequestManagement\Action\RequestedActionStackInterface::addRequestedAction()
*/
public function addRequestedAction(RequestedActionInterface $requestedAction): void
{
$key = $requestedAction->getActionType();
if ($this->containesRequestedAction($key)) {
throw new AllreadySetException("The key is allready set <<$key>>!");
throw new ContainsElementException("The key is allready set <<$key>>!");
}
$this->requestedActions->set($key, $requestedAction);
}
@@ -50,7 +49,7 @@ class RequestedActionStack implements RequestedActionStackInterface
/**
* {@inheritdoc}
*
* @see \Infinito\Domain\ReInfinito\Management\RequestedActionStackInterface::getAllRequestedActions()
* @see \Infinito\Domain\RequestManagement\Action\RequestedActionStackInterface::getAllRequestedActions()
*/
public function getAllRequestedActions(): Collection
{
@@ -60,13 +59,13 @@ class RequestedActionStack implements RequestedActionStackInterface
/**
* {@inheritdoc}
*
* @see \Infinito\Domain\ReInfinito\Management\RequestedActionStackInterface::getRequestedAction()
* @see \Infinito\Domain\RequestManagement\Action\RequestedActionStackInterface::getRequestedAction()
*/
public function getRequestedAction(string $actionType): RequestedActionInterface
{
if ($this->requestedActions->containsKey($actionType)) {
return $this->requestedActions->get($actionType);
}
throw new NotSetException(RequestedActionInterface::class." object for action type <<$actionType>> was not set!");
throw new NotSetElementException(RequestedActionInterface::class." object for action type <<$actionType>> was not set!");
}
}

View File

@@ -44,9 +44,10 @@ class RequestedEntity extends AbstractEntity implements RequestedEntityInterface
*/
private function validateHasIdentity(): void
{
if (!($this->hasId() || $this->hasSlug())) {
throw new NoIdentityCoreException('No identity attribut like id or slug was set!');
if ($this->hasId() || $this->hasSlug()) {
return;
}
throw new NoIdentityCoreException('No identity attribut like id or slug was set!');
}
/**
@@ -56,9 +57,10 @@ class RequestedEntity extends AbstractEntity implements RequestedEntityInterface
*/
private function validateLoadedEntity(?EntityInterface $entity): void
{
if (!$entity) {
throw new EntityNotFoundException('Entity with {id:"'.$this->id.'",slug:"'.$this->slug.'"} not found');
if ($entity) {
return;
}
throw new EntityNotFoundException('Entity with {id:"'.$this->id.'",slug:"'.$this->slug.'"} not found');
}
/**

View File

@@ -11,8 +11,8 @@ use Infinito\Entity\Meta\MetaInterface;
use Infinito\Domain\RequestManagement\Entity\RequestedEntity;
use Infinito\Attribut\ActionTypeAttribut;
use Infinito\Exception\Core\NotCorrectInstanceCoreException;
use Infinito\Exception\NoIdentityCoreException;
use Infinito\Exception\Attribut\AllreadyDefinedAttributException;
use Infinito\Exception\Core\NoIdentityCoreException;
use Infinito\Exception\Collection\ContainsElementException;
/**
* @author kevinfrantz
@@ -57,7 +57,7 @@ class RequestedRight implements RequestedRightInterface
if ($this->requestedEntity->hasIdentity()) {
return;
}
throw new NoIdentityCoreException(get_class($this->requestedEntity).' needs to have a defined attribut id or slug!');
throw new NoIdentityCoreException(get_class($this->requestedEntity).' needs to have a defined id or slug attribut!');
}
/**
@@ -79,7 +79,7 @@ class RequestedRight implements RequestedRightInterface
public function setActionType(string $actionType): void
{
if (isset($this->actionType)) {
throw new AllreadyDefinedAttributException("The action type is allready set! Origine: $this->actionType New: $actionType");
throw new ContainsElementException("The action type is allready set! Origine: $this->actionType New: $actionType");
}
$this->setActionTypeTrait($actionType);
}

View File

@@ -4,9 +4,9 @@ namespace Infinito\Domain\RequestManagement\User;
use Infinito\Entity\Source\SourceInterface;
use Infinito\Domain\UserManagement\UserSourceDirectorInterface;
use Infinito\Exception\SetNotPossibleException;
use Infinito\Domain\RequestManagement\Right\RequestedRightInterface;
use Infinito\Domain\RequestManagement\Right\AbstractRequestedRightFacade;
use Infinito\Exception\Collection\NotPossibleSetElementException;
/**
* @author kevinfrantz
@@ -37,7 +37,7 @@ class RequestedUser extends AbstractRequestedRightFacade implements RequestedUse
*/
public function setReciever(?SourceInterface $reciever): void
{
throw new SetNotPossibleException('It\'s not possible to set the reciever! Set it via '.UserSourceDirectorInterface::class.'!');
throw new NotPossibleSetElementException('It\'s not possible to set the reciever! Set it via '.UserSourceDirectorInterface::class.'!');
}
/**

View File

@@ -5,7 +5,7 @@ namespace Infinito\Domain\SecureManagement;
use Infinito\Entity\Meta\RightInterface;
use Infinito\Entity\Source\SourceInterface;
use Infinito\Domain\LawManagement\LawPermissionChecker;
use Infinito\Exception\SourceAccessDenied;
use Infinito\Exception\Permission\NoSourcePermissionException;
/**
* @author kevinfrantz
@@ -62,7 +62,7 @@ final class SecureSourceChecker implements SecureSourceCheckerInterface
/**
* @param RightInterface $requestedRight
*
* @throws SourceAccessDenied It's important to fire this exception to reduce complexity in debuging
* @throws NoSourcePermissionException It's important to fire this exception to reduce complexity in debuging
*
* @return bool
*/
@@ -77,7 +77,7 @@ final class SecureSourceChecker implements SecureSourceCheckerInterface
if ($this->isSource($attributExpectedSource)) {
$methodSecureSourceChecker = new self($attributExpectedSource);
if (!$methodSecureSourceChecker->hasPermission($requestedSubSourceRight)) {
throw new SourceAccessDenied('Access denied for subsource!');
throw new NoSourcePermissionException('Access denied for subsource!');
}
}
}

View File

@@ -3,7 +3,6 @@
namespace Infinito\Domain\SecureManagement;
use Infinito\Entity\Meta\RightInterface;
use Infinito\Exception\SourceAccessDenied;
/**
* @author kevinfrantz
@@ -11,8 +10,6 @@ use Infinito\Exception\SourceAccessDenied;
interface SecureSourceCheckerInterface
{
/**
* @throws SourceAccessDenied
*
* @param RightInterface $right
*
* @return bool

View File

@@ -4,12 +4,12 @@ namespace Infinito\Domain\SourceManagement;
use Infinito\Entity\Meta\RightInterface;
use Infinito\Entity\Source\SourceInterface;
use Infinito\Exception\AllreadySetException;
use Infinito\Entity\Source\AbstractSource;
use Infinito\Entity\Meta\Law;
use Infinito\Exception\AllreadyDefinedException;
use Infinito\Exception\Collection\NotSetException;
use Doctrine\Common\Collections\ArrayCollection;
use Infinito\Exception\Attribut\AllreadyDefinedAttributException;
use Infinito\Exception\Collection\ContainsElementException;
use Infinito\Exception\Collection\NotSetElementException;
/**
* @author kevinfrantz
@@ -30,7 +30,7 @@ final class SourceRightManager implements SourceRightManagerInterface
}
/**
* @throws AllreadyDefinedException If the attribut is allready defined
* @throws AllreadyDefinedAttributException If the attribut is allready defined
*/
private function checkRightAttributes(RightInterface $right): void
{
@@ -38,7 +38,7 @@ final class SourceRightManager implements SourceRightManagerInterface
foreach ($attributes as $attribut) {
try {
$right->{'get'.ucfirst($attribut)}();
throw new AllreadyDefinedException("The attribut \"$attribut\" is allready defined!");
throw new AllreadyDefinedAttributException("The attribut \"$attribut\" is allready defined!");
} catch (\Error $error) {
//Expected
}
@@ -61,7 +61,7 @@ final class SourceRightManager implements SourceRightManagerInterface
public function addRight(RightInterface $right): void
{
if ($this->getRights()->contains($right)) {
throw new AllreadySetException('The right was allready added.');
throw new ContainsElementException('The right was allready added.');
}
$this->checkRightAttributes($right);
$right->setSource($this->source);
@@ -80,7 +80,7 @@ final class SourceRightManager implements SourceRightManagerInterface
});
$right->setLaw(new Law());
if (!$this->getRights()->removeElement($right)) {
throw new NotSetException('The right to remove is not set.');
throw new NotSetElementException('The right to remove is not set.');
}
}
}

View File

@@ -3,9 +3,6 @@
namespace Infinito\Domain\SourceManagement;
use Infinito\Entity\Meta\RightInterface;
use Infinito\Exception\AllreadySetException;
use Infinito\Exception\AllreadyDefinedException;
use Infinito\Exception\Collection\NotSetException;
/**
* Allows to add and remove rights of a source.
@@ -16,16 +13,11 @@ interface SourceRightManagerInterface
{
/**
* @param RightInterface $right
*
* @throws AllreadySetException
* @throws AllreadyDefinedException
*/
public function addRight(RightInterface $right): void;
/**
* @param RightInterface $right
*
* @throws NotSetException
*/
public function removeRight(RightInterface $right): void;
}

View File

@@ -3,7 +3,7 @@
namespace Infinito\Domain\TwigManagement;
use Infinito\DBAL\Types\ActionType;
use Infinito\Exception\Collection\NotSetException;
use Infinito\Exception\Collection\NotSetElementException;
/**
* @author kevinfrantz
@@ -31,6 +31,6 @@ final class ActionIconClassMap implements ActionIconClassMapInterface
if (key_exists($action, self::ACTION_ICON_CLASS_MAP)) {
return self::ACTION_ICON_CLASS_MAP[$action];
}
throw new NotSetException("The key <<$action>> is not defined in the map!");
throw new NotSetElementException("The key <<$action>> is not defined in the map!");
}
}

View File

@@ -2,8 +2,8 @@
namespace Infinito\Domain\TwigManagement;
use Infinito\Exception\Collection\NotSetException;
use Infinito\DBAL\Types\Meta\Right\LayerType;
use Infinito\Exception\Collection\NotSetElementException;
/**
* @author kevinfrantz
@@ -32,6 +32,6 @@ final class LayerIconClassMap implements LayerIconClassMapInterface
if (key_exists($layer, self::LAYER_ICON_CLASS_MAP)) {
return self::LAYER_ICON_CLASS_MAP[$layer];
}
throw new NotSetException("The key <<$layer>> is not defined in the map!");
throw new NotSetElementException("The key <<$layer>> is not defined in the map!");
}
}