Passed
Push — master ( e73741...bdd95e )
by Nicolas
04:46
created

FormErrorNormalizer::normalize()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 1
nop 3
dl 0
loc 14
ccs 10
cts 10
cp 1
crap 3
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace App\Serializer\Normalizer;
4
5
/**
6
 * FormErrorNormalizer.
7
 */
8
class FormErrorNormalizer extends \FOS\RestBundle\Serializer\Normalizer\FormErrorNormalizer
9
{
10
    /**
11
     * {@inheritdoc}
12
     */
13 5
    public function normalize($object, $format = null, array $context = [])
14
    {
15 5
        $data = parent::normalize($object, $format, $context);
16 5
        $data = $data['errors']['children'];
17
18 5
        $data = array_filter($data, function ($child) {
19 5
            return isset($child['errors']) && count($child['errors']) > 0;
20 5
        });
21
22 5
        $data = array_map(function ($child) {
23 5
            return isset($child['errors']) ? $child['errors'] : [];
24 5
        }, $data);
25
26 5
        return $data;
27
    }
28
}
29