Skip to content

Commit b04d7db

Browse files
committed
add unique exceptions
1 parent f46483d commit b04d7db

7 files changed

+40
-9
lines changed

ecs.yaml

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ parameters:
1515
PhpCsFixer\Fixer\Operator\UnaryOperatorSpacesFixer: null
1616
Symplify\CodingStandard\Sniffs\ControlStructure\SprintfOverContactSniff: null
1717
Symplify\CodingStandard\Sniffs\CleanCode\ForbiddenStaticFunctionSniff: null
18-
# Symplify\CodingStandard\Sniffs\CleanCode\CognitiveComplexitySniff: null
1918
Symplify\CodingStandard\Sniffs\CleanCode\ForbiddenReferenceSniff: null
20-
Symplify\CodingStandard\Sniffs\Architecture\ExplicitExceptionSniff: null
19+
# Symplify\CodingStandard\Sniffs\Architecture\ExplicitExceptionSniff: null
2120
Symplify\CodingStandard\Sniffs\Architecture\DuplicatedClassShortNameSniff: null
2221

2322
# mixed types

src/Exception/SluggableException.php

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Knp\DoctrineBehaviors\Exception;
6+
7+
use Exception;
8+
9+
final class SluggableException extends Exception
10+
{
11+
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Knp\DoctrineBehaviors\Exception;
6+
7+
use Exception;
8+
9+
final class TranslatableException extends Exception
10+
{
11+
}

src/Exception/TreeException.php

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Knp\DoctrineBehaviors\Exception;
6+
7+
use Exception;
8+
9+
final class TreeException extends Exception
10+
{
11+
}

src/Model/Sluggable/SluggableMethodsTrait.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace Knp\DoctrineBehaviors\Model\Sluggable;
66

7+
use Knp\DoctrineBehaviors\Exception\SluggableException;
78
use Symfony\Component\String\Slugger\AsciiSlugger;
8-
use UnexpectedValueException;
99

1010
trait SluggableMethodsTrait
1111
{
@@ -84,7 +84,7 @@ private function ensureAtLeastOneUsableValue(array $values, array $usableValues)
8484
return;
8585
}
8686

87-
throw new UnexpectedValueException(sprintf(
87+
throw new SluggableException(sprintf(
8888
'Sluggable expects to have at least one non-empty field from the following: ["%s"]',
8989
implode('", "', array_keys($values))
9090
));

src/Model/Translatable/TranslatableMethodsTrait.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
use Doctrine\Common\Collections\ArrayCollection;
88
use Doctrine\Common\Collections\Collection;
9-
use InvalidArgumentException;
109
use Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface;
10+
use Knp\DoctrineBehaviors\Exception\TranslatableException;
1111

1212
trait TranslatableMethodsTrait
1313
{
@@ -222,8 +222,7 @@ private function ensureIsIterableOrCollection($translations): void
222222
return;
223223
}
224224

225-
throw new InvalidArgumentException(sprintf(
226-
'$translations parameter must be iterable or %s', Collection::class)
225+
throw new TranslatableException(sprintf('$translations parameter must be iterable or %s', Collection::class)
227226
);
228227
}
229228

src/Model/Tree/TreeNodeMethodsTrait.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Doctrine\Common\Collections\ArrayCollection;
99
use Doctrine\Common\Collections\Collection;
1010
use Knp\DoctrineBehaviors\Contract\Entity\TreeNodeInterface;
11-
use LogicException;
11+
use Knp\DoctrineBehaviors\Exception\TreeException;
1212
use Nette\Utils\Json;
1313

1414
trait TreeNodeMethodsTrait
@@ -110,7 +110,7 @@ public function setChildNodeOf(?TreeNodeInterface $treeNode = null): void
110110
{
111111
$id = $this->getNodeId();
112112
if (empty($id)) {
113-
throw new LogicException('You must provide an id for this node if you want it to be part of a tree.');
113+
throw new TreeException('You must provide an id for this node if you want it to be part of a tree.');
114114
}
115115

116116
$path = $treeNode !== null

0 commit comments

Comments
 (0)