Optimized Exceptions

This commit is contained in:
Kevin Frantz 2019-01-03 19:41:16 +01:00
parent 130682ef6c
commit 67428c2fea
10 changed files with 27 additions and 18 deletions

View File

@ -16,7 +16,7 @@ use App\Entity\Attribut\LayerAttribut;
use App\Entity\Attribut\RelationAttribut; use App\Entity\Attribut\RelationAttribut;
use App\Entity\Attribut\PriorityAttribut; use App\Entity\Attribut\PriorityAttribut;
use App\Entity\Source\SourceInterface; use App\Entity\Source\SourceInterface;
use App\Exception\NoValidChoice; use App\Exception\NoValidChoiceException;
/** /**
* @author kevinfrantz * @author kevinfrantz
@ -100,7 +100,7 @@ class Right extends AbstractMeta implements RightInterface
public function setType(string $type): void public function setType(string $type): void
{ {
if (!array_key_exists($type, RightType::getChoices())) { if (!array_key_exists($type, RightType::getChoices())) {
throw new NoValidChoice(); throw new NoValidChoiceException();
} }
$this->type = $type; $this->type = $type;
} }
@ -108,7 +108,7 @@ class Right extends AbstractMeta implements RightInterface
public function setLayer(string $layer): void public function setLayer(string $layer): void
{ {
if (!array_key_exists($layer, LayerType::getChoices())) { if (!array_key_exists($layer, LayerType::getChoices())) {
throw new NoValidChoice(); throw new NoValidChoiceException();
} }
$this->layer = $layer; $this->layer = $layer;
} }

View File

@ -0,0 +1,9 @@
<?php
namespace App\Exception;
use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
final class AllreadySetException extends ConflictHttpException
{
}

View File

@ -1,7 +0,0 @@
<?php
namespace App\Exception;
class NoValidChoice extends \Exception
{
}

View File

@ -0,0 +1,7 @@
<?php
namespace App\Exception;
final class NoValidChoiceException extends \Exception
{
}

View File

@ -2,7 +2,7 @@
namespace App\Exception; namespace App\Exception;
class NotDefinedException extends \Exception final class NotDefinedException extends \Exception
{ {
public function __construct($message = null) public function __construct($message = null)
{ {

View File

@ -2,7 +2,7 @@
namespace App\Exception; namespace App\Exception;
class NotProcessedException extends \Exception final class NotProcessedException extends \Exception
{ {
public function __construct($message = null) public function __construct($message = null)
{ {

View File

@ -2,6 +2,6 @@
namespace App\Exception; namespace App\Exception;
class NotSortableException extends \Exception final class NotSortableException extends \Exception
{ {
} }

View File

@ -2,6 +2,6 @@
namespace App\Exception; namespace App\Exception;
class RecursiveException extends \Exception final class RecursiveException extends \Exception
{ {
} }

View File

@ -4,6 +4,6 @@ namespace App\Exception;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
class SourceAccessDenied extends AccessDeniedHttpException final class SourceAccessDenied extends AccessDeniedHttpException
{ {
} }

View File

@ -8,7 +8,7 @@ use App\Entity\Meta\RightInterface;
use App\Entity\Meta\Right; use App\Entity\Meta\Right;
use App\Entity\Meta\Law; use App\Entity\Meta\Law;
use App\DBAL\Types\LayerType; use App\DBAL\Types\LayerType;
use App\Exception\NoValidChoice; use App\Exception\NoValidChoiceException;
use App\Entity\Source\AbstractSource; use App\Entity\Source\AbstractSource;
/** /**
@ -77,7 +77,7 @@ class RightTest extends TestCase
$this->assertNull($this->right->setType($key)); $this->assertNull($this->right->setType($key));
$this->assertEquals($key, $this->right->getType()); $this->assertEquals($key, $this->right->getType());
} }
$this->expectException(NoValidChoice::class); $this->expectException(NoValidChoiceException::class);
$this->right->setType('NoneValidType'); $this->right->setType('NoneValidType');
} }
@ -87,7 +87,7 @@ class RightTest extends TestCase
$this->assertNull($this->right->setLayer($key)); $this->assertNull($this->right->setLayer($key));
$this->assertEquals($key, $this->right->getLayer()); $this->assertEquals($key, $this->right->getLayer());
} }
$this->expectException(NoValidChoice::class); $this->expectException(NoValidChoiceException::class);
$this->right->setLayer('NoneValidLayer'); $this->right->setLayer('NoneValidLayer');
} }