Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
CRAP | |
88.89% |
8 / 9 |
| FormErrorHandlerTrait | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6.05 | |
88.89% |
8 / 9 |
| getErrors | |
0.00% |
0 / 1 |
6.05 | |
88.89% |
8 / 9 |
|||
| <?php | |
| declare(strict_types=1); | |
| namespace App\UI\HTTP\FormType; | |
| use Symfony\Component\Form\FormError; | |
| use Symfony\Component\Form\FormInterface; | |
| trait FormErrorHandlerTrait | |
| { | |
| public function getErrors(FormInterface $form): array | |
| { | |
| $errors = []; | |
| foreach ($form->getErrors() as $error) { | |
| if (!$error instanceof FormError) { | |
| continue; | |
| } | |
| $errors[] = $error->getMessage(); | |
| } | |
| foreach ($form->all() as $childForm) { | |
| if (($childForm instanceof FormInterface) && $childErrors = $this->getErrors($childForm)) { | |
| $errors[$childForm->getName()] = $childErrors; | |
| } | |
| } | |
| return $errors; | |
| } | |
| } |