AttributeOptionNormalizer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A normalize() 0 18 2
A supportsNormalization() 0 4 1
1
<?php
2
3
namespace Actualys\Bundle\DrupalCommerceConnectorBundle\Normalizer;
4
5
use Pim\Bundle\CatalogBundle\Entity\AttributeOption;
6
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
7
8
class AttributeOptionNormalizer implements NormalizerInterface
9
{
10
    /**
11
     * @param  object AttributeOption                                $attributeOption
12
     * @param  null                                                  $format
13
     * @param  array                                                 $context
14
     * @return array|\Symfony\Component\Serializer\Normalizer\scalar
15
     */
16
    public function normalize(
17
      $attributeOption,
18
      $format = null,
19
      array $context = []
20
    ) {
21
        /**@var AttributeOptionNormalizer $attributeOption * */
22
        $normalizedAttributeOption = [
23
          'labels' => [],
24
        ];
25
26
        /** @var AttributeOption $attributeOption */
27
        foreach ($attributeOption->getOptionValues() as $optionValue) {
28
            $normalizedAttributeOption['labels'][$optionValue->getLocale(
29
            )] = $optionValue->getValue();
30
        }
31
32
        return $normalizedAttributeOption;
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 AttributeOption;
46
    }
47
}
48