Total Complexity | 4 |
Total Lines | 43 |
Duplicated Lines | 0 % |
Coverage | 92.86% |
Changes | 0 |
1 | <?php declare(strict_types=1); |
||
11 | class ValidationException extends DoctrineStaticMetaException |
||
12 | { |
||
13 | use RelativePathTraceTrait; |
||
14 | |||
15 | protected $entity; |
||
16 | |||
17 | protected $errors; |
||
18 | |||
19 | /** |
||
20 | * ValidationException constructor. |
||
21 | * |
||
22 | * @param ConstraintViolationListInterface|ConstraintViolationInterface[] $errors |
||
23 | * @param EntityInterface $entity |
||
24 | * @param int $code |
||
25 | * @param \Exception|null $previous |
||
26 | */ |
||
27 | 2 | public function __construct( |
|
28 | ConstraintViolationListInterface $errors, |
||
29 | EntityInterface $entity, |
||
30 | $code = 0, |
||
31 | \Exception $previous = null |
||
32 | ) { |
||
33 | 2 | $this->entity = $entity; |
|
34 | 2 | $this->errors = $errors; |
|
35 | |||
36 | 2 | $message = 'found ' . $errors->count() . ' errors validating entity ' |
|
37 | 2 | . $entity::getDoctrineStaticMeta()->getShortName(); |
|
38 | 2 | foreach ($errors as $error) { |
|
39 | $message .= "\n\n" . $error->getPropertyPath() . ': ' . $error->getMessage(); |
||
40 | } |
||
41 | 2 | $message .= "\n\nFull Entity Dump:" . (new EntityDebugDumper())->dump($entity); |
|
42 | |||
43 | 2 | parent::__construct($message, $code, $previous); |
|
44 | 2 | } |
|
45 | |||
46 | 1 | public function getInvalidEntity(): EntityInterface |
|
47 | { |
||
48 | 1 | return $this->entity; |
|
49 | } |
||
50 | |||
51 | 1 | public function getValidationErrors(): ConstraintViolationListInterface |
|
54 | } |
||
55 | } |
||
56 |