1 | <?php |
||
24 | class FormErrorNormalizer implements NormalizerInterface |
||
25 | { |
||
26 | /** |
||
27 | * {@inheritdoc} |
||
28 | */ |
||
29 | 2 | public function normalize($object, $format = null, array $context = []): array |
|
30 | { |
||
31 | return [ |
||
32 | 2 | 'code' => isset($context['status_code']) ? $context['status_code'] : null, |
|
33 | 2 | 'message' => 'Validation Failed', |
|
34 | 2 | 'errors' => $this->convertFormToArray($object), |
|
35 | ]; |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * {@inheritdoc} |
||
40 | */ |
||
41 | 18 | public function supportsNormalization($data, $format = null): bool |
|
45 | |||
46 | /** |
||
47 | * This code has been taken from JMSSerializer. |
||
48 | */ |
||
49 | 2 | private function convertFormToArray(FormInterface $data): array |
|
74 | } |
||
75 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.