| Total Complexity | 6 |
| Total Lines | 23 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 18 | class FormExceptionNormalizer implements NormalizerInterface |
||
| 19 | { |
||
| 20 | public function normalize($exception, $format = null, array $context = []): array |
||
| 21 | { |
||
| 22 | $formattedErrors = []; |
||
| 23 | |||
| 24 | foreach ($exception->getErrors() as $error) { |
||
| 25 | $cause = $error->getCause(); |
||
| 26 | |||
| 27 | if ($cause && method_exists($cause, 'getPropertyPath') && $cause->getPropertyPath()) { |
||
| 28 | $path = preg_replace('/^(data.)|(.data)|(\\])|(\\[)|children/', '', $cause->getPropertyPath()); |
||
| 29 | $formattedErrors[$path] = $error->getMessage(); |
||
| 30 | } else { |
||
| 31 | $formattedErrors[] = $error->getMessage(); |
||
| 32 | } |
||
| 33 | } |
||
| 34 | |||
| 35 | return $formattedErrors; |
||
| 36 | } |
||
| 37 | |||
| 38 | public function supportsNormalization($data, $format = null): bool |
||
| 41 | } |
||
| 42 | } |
||
| 43 |