Skip to content

Commit 6191c3e

Browse files
authored
Merge pull request #151 from fre5h/feature-refactoring-exceptios
Refactoring exceptions
2 parents 7ddd3d9 + c2467c2 commit 6191c3e

15 files changed

+98
-15
lines changed

Exception/Constant/ConstantIsFoundInFewRegisteredEnumTypesException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212

1313
namespace Fresh\DoctrineEnumBundle\Exception\Constant;
1414

15+
use Fresh\DoctrineEnumBundle\Exception\LogicException;
16+
1517
/**
1618
* ConstantIsFoundInFewRegisteredEnumTypesException.
1719
*
1820
* @author Artem Henvald <genvaldartem@gmail.com>
1921
*/
20-
class ConstantIsFoundInFewRegisteredEnumTypesException extends \LogicException
22+
class ConstantIsFoundInFewRegisteredEnumTypesException extends LogicException
2123
{
2224
}

Exception/Constant/ConstantIsNotFoundInAnyRegisteredEnumTypeException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212

1313
namespace Fresh\DoctrineEnumBundle\Exception\Constant;
1414

15+
use Fresh\DoctrineEnumBundle\Exception\LogicException;
16+
1517
/**
1618
* ConstantIsNotFoundInAnyRegisteredEnumTypeException.
1719
*
1820
* @author Artem Henvald <genvaldartem@gmail.com>
1921
*/
20-
class ConstantIsNotFoundInAnyRegisteredEnumTypeException extends \LogicException
22+
class ConstantIsNotFoundInAnyRegisteredEnumTypeException extends LogicException
2123
{
2224
}

Exception/EnumType/NoRegisteredEnumTypesException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212

1313
namespace Fresh\DoctrineEnumBundle\Exception\EnumType;
1414

15+
use Fresh\DoctrineEnumBundle\Exception\LogicException;
16+
1517
/**
1618
* NoRegisteredEnumTypesException.
1719
*
1820
* @author Artem Henvald <genvaldartem@gmail.com>
1921
*/
20-
class NoRegisteredEnumTypesException extends \LogicException
22+
class NoRegisteredEnumTypesException extends LogicException
2123
{
2224
}

Exception/EnumValue/ValueIsFoundInFewRegisteredEnumTypesException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212

1313
namespace Fresh\DoctrineEnumBundle\Exception\EnumValue;
1414

15+
use Fresh\DoctrineEnumBundle\Exception\LogicException;
16+
1517
/**
1618
* ValueIsFoundInFewRegisteredEnumTypesException.
1719
*
1820
* @author Artem Henvald <genvaldartem@gmail.com>
1921
*/
20-
class ValueIsFoundInFewRegisteredEnumTypesException extends \LogicException
22+
class ValueIsFoundInFewRegisteredEnumTypesException extends LogicException
2123
{
2224
}

Exception/EnumValue/ValueIsNotFoundInAnyRegisteredEnumTypeException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212

1313
namespace Fresh\DoctrineEnumBundle\Exception\EnumValue;
1414

15+
use Fresh\DoctrineEnumBundle\Exception\LogicException;
16+
1517
/**
1618
* ValueIsNotFoundInAnyRegisteredEnumTypeException.
1719
*
1820
* @author Artem Henvald <genvaldartem@gmail.com>
1921
*/
20-
class ValueIsNotFoundInAnyRegisteredEnumTypeException extends \LogicException
22+
class ValueIsNotFoundInAnyRegisteredEnumTypeException extends LogicException
2123
{
2224
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/*
3+
* This file is part of the FreshDoctrineEnumBundle.
4+
*
5+
* (c) Artem Henvald <genvaldartem@gmail.com>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
declare(strict_types=1);
12+
13+
namespace Fresh\DoctrineEnumBundle\Exception;
14+
15+
/**
16+
* InvalidArgumentException.
17+
*
18+
* @author Artem Henvald <genvaldartem@gmail.com>
19+
*/
20+
class InvalidArgumentException extends \InvalidArgumentException
21+
{
22+
}

Exception/LogicException.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/*
3+
* This file is part of the FreshDoctrineEnumBundle.
4+
*
5+
* (c) Artem Henvald <genvaldartem@gmail.com>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
declare(strict_types=1);
12+
13+
namespace Fresh\DoctrineEnumBundle\Exception;
14+
15+
/**
16+
* LogicException.
17+
*
18+
* @author Artem Henvald <genvaldartem@gmail.com>
19+
*/
20+
class LogicException extends \LogicException
21+
{
22+
}

Exception/RuntimeException.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/*
3+
* This file is part of the FreshDoctrineEnumBundle.
4+
*
5+
* (c) Artem Henvald <genvaldartem@gmail.com>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
declare(strict_types=1);
12+
13+
namespace Fresh\DoctrineEnumBundle\Exception;
14+
15+
/**
16+
* RuntimeException.
17+
*
18+
* @author Artem Henvald <genvaldartem@gmail.com>
19+
*/
20+
class RuntimeException extends \LogicException
21+
{
22+
}

FreshDoctrineEnumBundle.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
namespace Fresh\DoctrineEnumBundle;
1212

1313
use Doctrine\Common\Persistence\ConnectionRegistry;
14+
use Fresh\DoctrineEnumBundle\Exception\InvalidArgumentException;
1415
use Symfony\Component\DependencyInjection\ContainerInterface;
1516
use Symfony\Component\HttpKernel\Bundle\Bundle;
1617

@@ -24,7 +25,7 @@ class FreshDoctrineEnumBundle extends Bundle
2425
/**
2526
* {@inheritdoc}
2627
*
27-
* @throws \InvalidArgumentException
28+
* @throws InvalidArgumentException
2829
* @throws \Doctrine\DBAL\DBALException
2930
* @throws \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
3031
* @throws \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
@@ -35,7 +36,7 @@ public function boot(): void
3536

3637
$doctrine = $this->container->get('doctrine', ContainerInterface::NULL_ON_INVALID_REFERENCE);
3738
if (!$doctrine instanceof ConnectionRegistry) {
38-
throw new \InvalidArgumentException('Service "doctrine" is missed in container');
39+
throw new InvalidArgumentException('Service "doctrine" is missed in container');
3940
}
4041

4142
/** @var \Doctrine\DBAL\Connection $connection */

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ Provides support of **ENUM type** for Doctrine in Symfony applications.
2121

2222
## Installation
2323

24-
```composer req fresh/doctrine-enum-bundle='~6.2'```
24+
```composer req fresh/doctrine-enum-bundle='~6.5'```
2525

2626
##### Choose the version you need
2727

2828
| Bundle Version (X.Y.Z) | PHP | Symfony | Doctrine DBAL | Comment |
2929
|:----------------------:|:----------------:|:----------------:|:-------------:|:--------------------|
30-
| `6.4.*` | `>= 7.1.3` | `>= 4.3 ` | `>= 2.6` | **Current version** |
30+
| `6.5.*` | `>= 7.1.3` | `>= 4.3 ` | `>= 2.6` | **Current version** |
3131
| `6.3.*` | `>= 7.1.3` | `>= 4.0, <= 4.2` | `>= 2.6` | *Bug fix support* |
3232

3333
#### Check the `config/bundles.php` file

Tests/FreshDoctrineEnumBundleTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Doctrine\Common\Persistence\ManagerRegistry;
1616
use Doctrine\DBAL\Connection;
1717
use Doctrine\DBAL\Platforms\AbstractPlatform;
18+
use Fresh\DoctrineEnumBundle\Exception\InvalidArgumentException;
1819
use Fresh\DoctrineEnumBundle\FreshDoctrineEnumBundle;
1920
use PHPUnit\Framework\MockObject\MockObject;
2021
use PHPUnit\Framework\TestCase;
@@ -175,7 +176,7 @@ public function testMissedDoctrine(): void
175176
->willReturn(null)
176177
;
177178

178-
$this->expectException(\InvalidArgumentException::class);
179+
$this->expectException(InvalidArgumentException::class);
179180
$this->expectExceptionMessage('Service "doctrine" is missed in container');
180181

181182
$bundle = new FreshDoctrineEnumBundle();

Tests/Twig/Extension/EnumValuesAsArrayExtensionTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
use Fresh\DoctrineEnumBundle\Exception\EnumType\EnumTypeIsNotRegisteredException;
1616
use Fresh\DoctrineEnumBundle\Exception\EnumType\NoRegisteredEnumTypesException;
17+
use Fresh\DoctrineEnumBundle\Exception\LogicException;
1718
use Fresh\DoctrineEnumBundle\Tests\Fixtures\DBAL\Types\BasketballPositionType;
1819
use Fresh\DoctrineEnumBundle\Twig\Extension\EnumValuesAsArrayTwigExtension;
1920
use PHPUnit\Framework\TestCase;
@@ -95,7 +96,7 @@ public function testInvalidCallable(): void
9596
$property->setValue($extension, ['invalid_callable' => 'dummy']);
9697
$property->setAccessible(false);
9798

98-
$this->expectException(\LogicException::class);
99+
$this->expectException(LogicException::class);
99100
$this->expectExceptionMessage('dummy::getReadableValues is not a valid exception');
100101

101102
$extension->getReadableEnumValuesAsArray('invalid_callable');

Tests/Validator/EnumValidatorTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace Fresh\DoctrineEnumBundle\Tests\Validator;
1414

15+
use Fresh\DoctrineEnumBundle\Exception\RuntimeException;
1516
use Fresh\DoctrineEnumBundle\Tests\Fixtures\DBAL\Types\BasketballPositionType;
1617
use Fresh\DoctrineEnumBundle\Validator\Constraints\Enum;
1718
use Fresh\DoctrineEnumBundle\Validator\Constraints\EnumValidator;
@@ -47,7 +48,7 @@ protected function tearDown(): void
4748

4849
public function testValidateIncorrectConstraintClass(): void
4950
{
50-
$this->expectException(\RuntimeException::class);
51+
$this->expectException(RuntimeException::class);
5152
$this->expectExceptionMessageRegExp('/^Object of class .* is not instance of .*$/');
5253

5354
$this->enumValidator->validate(BasketballPositionType::POINT_GUARD, new DummyConstraint());

Twig/Extension/EnumValuesAsArrayTwigExtension.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
use Fresh\DoctrineEnumBundle\Exception\EnumType\EnumTypeIsNotRegisteredException;
1616
use Fresh\DoctrineEnumBundle\Exception\EnumType\NoRegisteredEnumTypesException;
17+
use Fresh\DoctrineEnumBundle\Exception\LogicException;
1718
use Twig\TwigFunction;
1819

1920
/**
@@ -64,6 +65,7 @@ public function getReadableEnumValuesAsArray(string $enumType): array
6465
* @param string $enumType
6566
* @param string $staticMethodName
6667
*
68+
* @throws LogicException
6769
* @throws EnumTypeIsNotRegisteredException
6870
* @throws NoRegisteredEnumTypesException
6971
*
@@ -77,7 +79,7 @@ private function callEnumTypeStaticMethod(string $enumType, string $staticMethod
7779
$function = [$this->registeredEnumTypes[$enumType], $staticMethodName];
7880

7981
if (!\is_callable($function)) {
80-
throw new \LogicException(\sprintf('%s::%s is not a valid exception', $this->registeredEnumTypes[$enumType], $staticMethodName));
82+
throw new LogicException(\sprintf('%s::%s is not a valid exception', $this->registeredEnumTypes[$enumType], $staticMethodName));
8183
}
8284

8385
return $function();

Validator/Constraints/EnumValidator.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
namespace Fresh\DoctrineEnumBundle\Validator\Constraints;
1212

13+
use Fresh\DoctrineEnumBundle\Exception\RuntimeException;
1314
use Symfony\Component\Validator\Constraint;
1415
use Symfony\Component\Validator\Constraints\ChoiceValidator;
1516
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
@@ -25,13 +26,13 @@ class EnumValidator extends ChoiceValidator
2526
* @param mixed $value
2627
* @param Constraint|Enum $constraint
2728
*
28-
* @throws \RuntimeException
29+
* @throws RuntimeException
2930
* @throws ConstraintDefinitionException
3031
*/
3132
public function validate($value, Constraint $constraint): void
3233
{
3334
if (!$constraint instanceof Enum) {
34-
throw new \RuntimeException(\sprintf('Object of class %s is not instance of %s', \get_class($constraint), Enum::class));
35+
throw new RuntimeException(\sprintf('Object of class %s is not instance of %s', \get_class($constraint), Enum::class));
3536
}
3637

3738
if (!$constraint->entity) {

0 commit comments

Comments
 (0)