| Total Complexity | 10 |
| Total Lines | 45 |
| Duplicated Lines | 0 % |
| Coverage | 85.71% |
| Changes | 0 | ||
| 1 | <?php |
||
| 7 | class ValidatorException extends \Symfony\Component\Validator\Exception\ValidatorException |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var ConstraintViolationListInterface[] |
||
| 11 | */ |
||
| 12 | protected $violations; |
||
| 13 | |||
| 14 | 11 | public function __construct($violations) |
|
| 15 | { |
||
| 16 | 11 | $this->violations = $violations; |
|
| 17 | 11 | parent::__construct($this->buildMessage($violations)); |
|
| 18 | 11 | } |
|
| 19 | |||
| 20 | 11 | protected function buildMessage($violations): string |
|
| 21 | { |
||
| 22 | 11 | $message = ''; |
|
| 23 | 11 | foreach ($violations as $propertyName => $propertyViolations) { |
|
| 24 | 11 | if (! empty($propertyViolations)) { |
|
| 25 | 11 | $message = $message."Exception on property '".$propertyName."': "; |
|
| 26 | } |
||
| 27 | 11 | foreach ($propertyViolations as $violation) { |
|
| 28 | 11 | $message = $message.$violation->getMessage().'.'; |
|
| 29 | } |
||
| 30 | 11 | $message = $message."\n"; |
|
| 31 | } |
||
| 32 | |||
| 33 | 11 | return $message; |
|
| 34 | } |
||
| 35 | |||
| 36 | 10 | public function propertyViolationExists(string $property, string $violationClass) |
|
| 37 | { |
||
| 38 | 10 | if (array_key_exists($property, $this->violations)) { |
|
| 39 | 10 | foreach ($this->violations[$property] as $violation) { |
|
| 40 | 10 | if ($violation instanceof $violationClass) { |
|
| 41 | 10 | return true; |
|
| 42 | } |
||
| 43 | } |
||
| 44 | } |
||
| 45 | |||
| 46 | return false; |
||
| 47 | } |
||
| 48 | |||
| 49 | public function getViolations(): array |
||
| 52 | } |
||
| 53 | } |
||
| 54 |