GroupNormalizer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 40
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A normalize() 0 18 3
A supportsNormalization() 0 4 1
1
<?php
2
3
namespace Actualys\Bundle\DrupalCommerceConnectorBundle\Normalizer;
4
5
use Pim\Bundle\CatalogBundle\Entity\Group;
6
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
7
8
class GroupNormalizer implements NormalizerInterface
9
{
10
    /**
11
     * @param  object                                                $group
12
     * @param  null                                                  $format
13
     * @param  array                                                 $context
14
     * @return array|\Symfony\Component\Serializer\Normalizer\scalar
15
     */
16
    public function normalize($group, $format = null, array $context = [])
17
    {
18
        /**@var Group $group * */
19
        $normalizedGroup = [
20
          'code' => $group->getCode(),
21
          'type' => $group->getType()->getCode(),
22
23
        ];
24
        foreach ($group->getTranslations() as $trans) {
25
            $normalizedGroup['labels'][$trans->getLocale()] = $trans->getLabel(
26
            );
27
        }
28
        foreach ($group->getAttributes() as $attr) {
29
            $normalizedGroup['attributes'][] = $attr->getCode();
30
        }
31
32
        return $normalizedGroup;
33
    }
34
35
    /**
36
     * Checks whether the given class is supported for normalization by this normalizer
37
     *
38
     * @param mixed  $data   Data to normalize.
39
     * @param string $format The format being (de-)serialized from or into.
40
     *
41
     * @return boolean
42
     */
43
    public function supportsNormalization($data, $format = null)
44
    {
45
        return $data instanceof Group;
46
    }
47
}
48