| Total Complexity | 7 |
| Total Lines | 30 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 8 | final class ValidationExceptionFactory implements ValidationExceptionFactoryInterface |
||
| 9 | { |
||
| 10 | private static ?ValidationExceptionFactoryInterface $userDefinedFactory = null; |
||
| 11 | |||
| 12 | public function __construct(private ValidationExceptionInterface | string | null $exception = null) |
||
| 13 | { |
||
| 14 | } |
||
| 15 | |||
| 16 | public static function setDefault(ValidationExceptionFactoryInterface $factory): void |
||
| 17 | { |
||
| 18 | self::$userDefinedFactory = $factory; |
||
| 19 | } |
||
| 20 | |||
| 21 | /** @inheritDoc */ |
||
| 22 | public function create(Result $result): ValidationExceptionInterface |
||
| 23 | { |
||
| 24 | return |
||
| 25 | self::$userDefinedFactory instanceof ValidationExceptionFactoryInterface ? |
||
| 26 | self::$userDefinedFactory->create($result) : |
||
| 27 | $this->defaultException($result); |
||
| 28 | } |
||
| 29 | |||
| 30 | private function defaultException(Result $result): ValidationExceptionInterface |
||
| 38 | ); |
||
| 39 | } |
||
| 40 | } |
||
| 41 |