ProductVariantModelNormalizer   A
last analyzed

Complexity

Total Complexity 36

Size/Duplication

Total Lines 130
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 86
c 1
b 0
f 1
dl 0
loc 130
rs 9.52
wmc 36

4 Methods

Rating   Name   Duplication   Size   Complexity  
F denormalize() 0 65 20
A supportsNormalization() 0 3 1
A supportsDenormalization() 0 3 1
F normalize() 0 52 14
1
<?php
2
3
namespace Starweb\Api\Generated\Normalizer;
4
5
use Jane\JsonSchemaRuntime\Reference;
6
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
7
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface;
8
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait;
9
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
10
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
11
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
12
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
13
class ProductVariantModelNormalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface
14
{
15
    use DenormalizerAwareTrait;
16
    use NormalizerAwareTrait;
17
    public function supportsDenormalization($data, $type, $format = null)
18
    {
19
        return $type === 'Starweb\\Api\\Generated\\Model\\ProductVariantModel';
20
    }
21
    public function supportsNormalization($data, $format = null)
22
    {
23
        return get_class($data) === 'Starweb\\Api\\Generated\\Model\\ProductVariantModel';
24
    }
25
    public function denormalize($data, $class, $format = null, array $context = array())
26
    {
27
        if (!is_object($data)) {
28
            throw new InvalidArgumentException();
29
        }
30
        $object = new \Starweb\Api\Generated\Model\ProductVariantModel();
31
        if (property_exists($data, 'sku')) {
32
            $object->setSku($data->{'sku'});
33
        }
34
        if (property_exists($data, 'isActive')) {
35
            $object->setIsActive($data->{'isActive'});
36
        }
37
        if (property_exists($data, 'sortIndex')) {
38
            $object->setSortIndex($data->{'sortIndex'});
39
        }
40
        if (property_exists($data, 'stockStatusId')) {
41
            $object->setStockStatusId($data->{'stockStatusId'});
42
        }
43
        if (property_exists($data, 'stockQuantity')) {
44
            $object->setStockQuantity($data->{'stockQuantity'});
45
        }
46
        if (property_exists($data, 'weightInKg')) {
47
            $object->setWeightInKg($data->{'weightInKg'});
48
        }
49
        if (property_exists($data, 'costPrice')) {
50
            $object->setCostPrice($data->{'costPrice'});
51
        }
52
        if (property_exists($data, 'ean')) {
53
            $object->setEan($data->{'ean'});
54
        }
55
        if (property_exists($data, 'mpn')) {
56
            $object->setMpn($data->{'mpn'});
57
        }
58
        if (property_exists($data, 'imageFileId')) {
59
            $object->setImageFileId($data->{'imageFileId'});
60
        }
61
        if (property_exists($data, 'attributeValueLinks')) {
62
            $values = array();
63
            foreach ($data->{'attributeValueLinks'} as $value) {
64
                $values[] = $value;
65
            }
66
            $object->setAttributeValueLinks($values);
67
        }
68
        if (property_exists($data, 'volumePricingInheritancePricelistIds')) {
69
            $values_1 = array();
70
            foreach ($data->{'volumePricingInheritancePricelistIds'} as $value_1) {
71
                $values_1[] = $value_1;
72
            }
73
            $object->setVolumePricingInheritancePricelistIds($values_1);
74
        }
75
        if (property_exists($data, 'prices')) {
76
            $values_2 = array();
77
            foreach ($data->{'prices'} as $value_2) {
78
                $values_2[] = $this->denormalizer->denormalize($value_2, 'Starweb\\Api\\Generated\\Model\\ProductVariantPriceModel', 'json', $context);
79
            }
80
            $object->setPrices($values_2);
81
        }
82
        if (property_exists($data, 'attributeValues')) {
83
            $values_3 = array();
84
            foreach ($data->{'attributeValues'} as $value_3) {
85
                $values_3[] = $this->denormalizer->denormalize($value_3, 'Starweb\\Api\\Generated\\Model\\ProductVariantAttributeValueModel', 'json', $context);
86
            }
87
            $object->setAttributeValues($values_3);
88
        }
89
        return $object;
90
    }
91
    public function normalize($object, $format = null, array $context = array())
92
    {
93
        $data = new \stdClass();
94
        if (null !== $object->getSku()) {
95
            $data->{'sku'} = $object->getSku();
96
        }
97
        if (null !== $object->getIsActive()) {
98
            $data->{'isActive'} = $object->getIsActive();
99
        }
100
        if (null !== $object->getSortIndex()) {
101
            $data->{'sortIndex'} = $object->getSortIndex();
102
        }
103
        $data->{'stockStatusId'} = $object->getStockStatusId();
104
        $data->{'stockQuantity'} = $object->getStockQuantity();
105
        $data->{'weightInKg'} = $object->getWeightInKg();
106
        $data->{'costPrice'} = $object->getCostPrice();
107
        if (null !== $object->getEan()) {
108
            $data->{'ean'} = $object->getEan();
109
        }
110
        if (null !== $object->getMpn()) {
111
            $data->{'mpn'} = $object->getMpn();
112
        }
113
        $data->{'imageFileId'} = $object->getImageFileId();
114
        if (null !== $object->getAttributeValueLinks()) {
115
            $values = array();
116
            foreach ($object->getAttributeValueLinks() as $value) {
117
                $values[] = $value;
118
            }
119
            $data->{'attributeValueLinks'} = $values;
120
        }
121
        if (null !== $object->getVolumePricingInheritancePricelistIds()) {
122
            $values_1 = array();
123
            foreach ($object->getVolumePricingInheritancePricelistIds() as $value_1) {
124
                $values_1[] = $value_1;
125
            }
126
            $data->{'volumePricingInheritancePricelistIds'} = $values_1;
127
        }
128
        if (null !== $object->getPrices()) {
129
            $values_2 = array();
130
            foreach ($object->getPrices() as $value_2) {
131
                $values_2[] = $this->normalizer->normalize($value_2, 'json', $context);
132
            }
133
            $data->{'prices'} = $values_2;
134
        }
135
        if (null !== $object->getAttributeValues()) {
136
            $values_3 = array();
137
            foreach ($object->getAttributeValues() as $value_3) {
138
                $values_3[] = $this->normalizer->normalize($value_3, 'json', $context);
139
            }
140
            $data->{'attributeValues'} = $values_3;
141
        }
142
        return $data;
143
    }
144
}