FolderNormalizer   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 36
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A normalize() 0 20 3
A supportsNormalization() 0 4 3
1
<?php
2
3
/*
4
 * This file is part of the PostmanGeneratorBundle package.
5
 *
6
 * (c) Vincent Chalamon <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace PostmanGeneratorBundle\Normalizer;
13
14
use Doctrine\Common\Inflector\Inflector;
15
use PostmanGeneratorBundle\Model\Folder;
16
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
17
18
class FolderNormalizer implements NormalizerInterface
19
{
20
    /**
21
     * {@inheritdoc}
22
     *
23
     * @param Folder $object
24
     */
25 1
    public function normalize($object, $format = null, array $context = [])
26
    {
27 1
        $data = [];
28 1
        $reflectionClass = new \ReflectionClass($object);
29
        /** @var \ReflectionProperty[] $properties */
30 1
        $properties = array_filter($reflectionClass->getProperties(), function (\ReflectionProperty $property) {
31 1
            return 'requests' !== $property->getName();
32 1
        });
33
34 1
        foreach ($properties as $property) {
35 1
            $method = $reflectionClass->getMethod('get'.Inflector::classify($property->getName()));
36 1
            if ('collection' === $property->getName()) {
37 1
                $data[$property->getName().'Id'] = $method->invoke($object)->getId();
38 1
            } else {
39 1
                $data[$property->getName()] = $method->invoke($object);
40
            }
41 1
        }
42
43 1
        return $data;
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49 2
    public function supportsNormalization($data, $format = null)
50
    {
51 2
        return 'json' === $format && is_object($data) && $data instanceof Folder;
52
    }
53
}
54