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