AttributeOptionNormalizer::normalize()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
rs 9.4285
cc 2
eloc 10
nc 2
nop 3
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