Total Complexity | 6 |
Total Lines | 41 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
13 | class ValidateObjectStep extends AbstractConfigurableStep |
||
14 | { |
||
15 | /** @var ValidatorInterface */ |
||
16 | private $validator; |
||
17 | |||
18 | 3 | public function __construct(ValidatorInterface $validator) |
|
19 | { |
||
20 | 3 | $this->validator = $validator; |
|
21 | 3 | } |
|
22 | |||
23 | 1 | public function configureOptionResolver(OptionsResolver $resolver): OptionsResolver |
|
24 | { |
||
25 | 1 | $resolver->setRequired(['groups']); |
|
26 | 1 | $resolver->setDefault('groups', []); |
|
27 | |||
28 | 1 | return parent::configureOptionResolver($resolver); |
|
29 | } |
||
30 | |||
31 | 2 | public function execute(ProcessState $state) |
|
32 | { |
||
33 | 2 | $violations = $this->validator->validate($state->getData(), null, $state->getOptions()['groups']); |
|
34 | |||
35 | 2 | if ($violations->count() > 0) { |
|
36 | 1 | $state->error('error with object', [ |
|
37 | 1 | 'errors' => $this->violationToArray($violations), |
|
38 | ]); |
||
39 | 1 | $state->markFail(); |
|
40 | |||
41 | 1 | return; |
|
42 | } |
||
43 | 1 | } |
|
44 | |||
45 | 1 | private function violationToArray(ConstraintViolationListInterface $violationList): array |
|
54 | } |
||
55 | } |
||
56 |