| Total Complexity | 6 |
| Total Lines | 49 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 16 | class ValidationException extends RuntimeException |
||
| 17 | { |
||
| 18 | /** @var array */ |
||
| 19 | private $invalidElements; |
||
| 20 | |||
| 21 | 9 | public function __construct( |
|
| 22 | string $message = '', |
||
| 23 | array $invalidElements = [], |
||
| 24 | int $code = 0, |
||
| 25 | ?Throwable $previous = null |
||
| 26 | ) { |
||
| 27 | 9 | $this->invalidElements = $invalidElements; |
|
| 28 | 9 | parent::__construct($message, $code, $previous); |
|
| 29 | } |
||
| 30 | |||
| 31 | 4 | public static function fromInputFilter(InputFilterInterface $inputFilter, ?Throwable $prev = null): self |
|
| 32 | { |
||
| 33 | 4 | return static::fromArray($inputFilter->getMessages(), $prev); |
|
| 34 | } |
||
| 35 | |||
| 36 | 4 | private static function fromArray(array $invalidData, ?Throwable $prev = null): self |
|
| 37 | { |
||
| 38 | 4 | return new self( |
|
| 39 | 4 | sprintf( |
|
| 40 | 4 | 'Provided data is not valid. These are the messages:%s%s%s', |
|
| 41 | 4 | PHP_EOL, |
|
| 42 | 4 | self::formMessagesToString($invalidData), |
|
| 43 | 4 | PHP_EOL |
|
| 44 | ), |
||
| 45 | $invalidData, |
||
| 46 | 4 | -1, |
|
| 47 | $prev |
||
| 48 | ); |
||
| 49 | } |
||
| 50 | |||
| 51 | 4 | private static function formMessagesToString(array $messages = []): string |
|
| 60 | } |
||
| 61 | |||
| 62 | 6 | public function getInvalidElements(): array |
|
| 63 | { |
||
| 67 |