ProductModelUpdatableNormalizer   F
last analyzed

Complexity

Total Complexity 60

Size/Duplication

Total Lines 210
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 142
c 2
b 0
f 1
dl 0
loc 210
rs 3.6
wmc 60

4 Methods

Rating   Name   Duplication   Size   Complexity  
A supportsDenormalization() 0 3 1
A supportsNormalization() 0 3 1
F denormalize() 0 105 32
F normalize() 0 92 26

How to fix   Complexity   

Complex Class

Complex classes like ProductModelUpdatableNormalizer often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ProductModelUpdatableNormalizer, and based on these observations, apply Extract Interface, too.

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 ProductModelUpdatableNormalizer 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\\ProductModelUpdatable';
20
    }
21
    public function supportsNormalization($data, $format = null)
22
    {
23
        return get_class($data) === 'Starweb\\Api\\Generated\\Model\\ProductModelUpdatable';
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\ProductModelUpdatable();
31
        if (property_exists($data, 'productId')) {
32
            $object->setProductId($data->{'productId'});
33
        }
34
        if (property_exists($data, 'createdAt')) {
35
            $object->setCreatedAt($data->{'createdAt'});
36
        }
37
        if (property_exists($data, 'defaultVatRate')) {
38
            $object->setDefaultVatRate($data->{'defaultVatRate'});
39
        }
40
        if (property_exists($data, 'visibility')) {
41
            $object->setVisibility($data->{'visibility'});
42
        }
43
        if (property_exists($data, 'visibilityPricelistIds')) {
44
            $values = array();
45
            foreach ($data->{'visibilityPricelistIds'} as $value) {
46
                $values[] = $value;
47
            }
48
            $object->setVisibilityPricelistIds($values);
49
        }
50
        if (property_exists($data, 'moreInfoUrl')) {
51
            $object->setMoreInfoUrl($data->{'moreInfoUrl'});
52
        }
53
        if (property_exists($data, 'manufacturerId')) {
54
            $object->setManufacturerId($data->{'manufacturerId'});
55
        }
56
        if (property_exists($data, 'unitId')) {
57
            $object->setUnitId($data->{'unitId'});
58
        }
59
        if (property_exists($data, 'sortIndex')) {
60
            $object->setSortIndex($data->{'sortIndex'});
61
        }
62
        if (property_exists($data, 'type')) {
63
            $object->setType($data->{'type'});
64
        }
65
        if (property_exists($data, 'isBackInStockWatchable')) {
66
            $object->setIsBackInStockWatchable($data->{'isBackInStockWatchable'});
67
        }
68
        if (property_exists($data, 'bundleUseManualPrice')) {
69
            $object->setBundleUseManualPrice($data->{'bundleUseManualPrice'});
70
        }
71
        if (property_exists($data, 'accounting')) {
72
            $object->setAccounting($data->{'accounting'});
73
        }
74
        if (property_exists($data, 'hasSeveralVariants')) {
75
            $object->setHasSeveralVariants($data->{'hasSeveralVariants'});
76
        }
77
        if (property_exists($data, 'modifiedAt')) {
78
            $object->setModifiedAt($data->{'modifiedAt'});
79
        }
80
        if (property_exists($data, 'variants')) {
81
            $values_1 = array();
82
            foreach ($data->{'variants'} as $value_1) {
83
                $values_1[] = $this->denormalizer->denormalize($value_1, 'Starweb\\Api\\Generated\\Model\\ProductVariantModel', 'json', $context);
84
            }
85
            $object->setVariants($values_1);
86
        }
87
        if (property_exists($data, 'bundledProducts')) {
88
            $values_2 = array();
89
            foreach ($data->{'bundledProducts'} as $value_2) {
90
                $values_2[] = $this->denormalizer->denormalize($value_2, 'Starweb\\Api\\Generated\\Model\\BundledProductsModel', 'json', $context);
91
            }
92
            $object->setBundledProducts($values_2);
93
        }
94
        if (property_exists($data, 'mediaFiles')) {
95
            $values_3 = array();
96
            foreach ($data->{'mediaFiles'} as $value_3) {
97
                $values_3[] = $this->denormalizer->denormalize($value_3, 'Starweb\\Api\\Generated\\Model\\ProductMediaFileLinkModel', 'json', $context);
98
            }
99
            $object->setMediaFiles($values_3);
100
        }
101
        if (property_exists($data, 'languages')) {
102
            $values_4 = array();
103
            foreach ($data->{'languages'} as $value_4) {
104
                $values_4[] = $this->denormalizer->denormalize($value_4, 'Starweb\\Api\\Generated\\Model\\ProductLanguageModel', 'json', $context);
105
            }
106
            $object->setLanguages($values_4);
107
        }
108
        if (property_exists($data, 'vatRates')) {
109
            $values_5 = array();
110
            foreach ($data->{'vatRates'} as $value_5) {
111
                $values_5[] = $this->denormalizer->denormalize($value_5, 'Starweb\\Api\\Generated\\Model\\ProductVatRateModel', 'json', $context);
112
            }
113
            $object->setVatRates($values_5);
114
        }
115
        if (property_exists($data, 'categories')) {
116
            $values_6 = array();
117
            foreach ($data->{'categories'} as $value_6) {
118
                $values_6[] = $this->denormalizer->denormalize($value_6, 'Starweb\\Api\\Generated\\Model\\ProductCategoryLinkModel', 'json', $context);
119
            }
120
            $object->setCategories($values_6);
121
        }
122
        if (property_exists($data, 'metaData')) {
123
            $values_7 = array();
124
            foreach ($data->{'metaData'} as $value_7) {
125
                $values_7[] = $this->denormalizer->denormalize($value_7, 'Starweb\\Api\\Generated\\Model\\ProductMetaDataModelUpdatable', 'json', $context);
126
            }
127
            $object->setMetaData($values_7);
128
        }
129
        return $object;
130
    }
131
    public function normalize($object, $format = null, array $context = array())
132
    {
133
        $data = new \stdClass();
134
        if (null !== $object->getProductId()) {
135
            $data->{'productId'} = $object->getProductId();
136
        }
137
        if (null !== $object->getCreatedAt()) {
138
            $data->{'createdAt'} = $object->getCreatedAt();
139
        }
140
        $data->{'defaultVatRate'} = $object->getDefaultVatRate();
141
        if (null !== $object->getVisibility()) {
142
            $data->{'visibility'} = $object->getVisibility();
143
        }
144
        if (null !== $object->getVisibilityPricelistIds()) {
145
            $values = array();
146
            foreach ($object->getVisibilityPricelistIds() as $value) {
147
                $values[] = $value;
148
            }
149
            $data->{'visibilityPricelistIds'} = $values;
150
        }
151
        if (null !== $object->getMoreInfoUrl()) {
152
            $data->{'moreInfoUrl'} = $object->getMoreInfoUrl();
153
        }
154
        $data->{'manufacturerId'} = $object->getManufacturerId();
155
        $data->{'unitId'} = $object->getUnitId();
156
        $data->{'sortIndex'} = $object->getSortIndex();
157
        if (null !== $object->getType()) {
158
            $data->{'type'} = $object->getType();
159
        }
160
        if (null !== $object->getIsBackInStockWatchable()) {
161
            $data->{'isBackInStockWatchable'} = $object->getIsBackInStockWatchable();
162
        }
163
        if (null !== $object->getBundleUseManualPrice()) {
164
            $data->{'bundleUseManualPrice'} = $object->getBundleUseManualPrice();
165
        }
166
        $data->{'accounting'} = $object->getAccounting();
167
        if (null !== $object->getHasSeveralVariants()) {
168
            $data->{'hasSeveralVariants'} = $object->getHasSeveralVariants();
169
        }
170
        if (null !== $object->getModifiedAt()) {
171
            $data->{'modifiedAt'} = $object->getModifiedAt();
172
        }
173
        if (null !== $object->getVariants()) {
174
            $values_1 = array();
175
            foreach ($object->getVariants() as $value_1) {
176
                $values_1[] = $this->normalizer->normalize($value_1, 'json', $context);
177
            }
178
            $data->{'variants'} = $values_1;
179
        }
180
        if (null !== $object->getBundledProducts()) {
181
            $values_2 = array();
182
            foreach ($object->getBundledProducts() as $value_2) {
183
                $values_2[] = $this->normalizer->normalize($value_2, 'json', $context);
184
            }
185
            $data->{'bundledProducts'} = $values_2;
186
        }
187
        if (null !== $object->getMediaFiles()) {
188
            $values_3 = array();
189
            foreach ($object->getMediaFiles() as $value_3) {
190
                $values_3[] = $this->normalizer->normalize($value_3, 'json', $context);
191
            }
192
            $data->{'mediaFiles'} = $values_3;
193
        }
194
        if (null !== $object->getLanguages()) {
195
            $values_4 = array();
196
            foreach ($object->getLanguages() as $value_4) {
197
                $values_4[] = $this->normalizer->normalize($value_4, 'json', $context);
198
            }
199
            $data->{'languages'} = $values_4;
200
        }
201
        if (null !== $object->getVatRates()) {
202
            $values_5 = array();
203
            foreach ($object->getVatRates() as $value_5) {
204
                $values_5[] = $this->normalizer->normalize($value_5, 'json', $context);
205
            }
206
            $data->{'vatRates'} = $values_5;
207
        }
208
        if (null !== $object->getCategories()) {
209
            $values_6 = array();
210
            foreach ($object->getCategories() as $value_6) {
211
                $values_6[] = $this->normalizer->normalize($value_6, 'json', $context);
212
            }
213
            $data->{'categories'} = $values_6;
214
        }
215
        if (null !== $object->getMetaData()) {
216
            $values_7 = array();
217
            foreach ($object->getMetaData() as $value_7) {
218
                $values_7[] = $this->normalizer->normalize($value_7, 'json', $context);
219
            }
220
            $data->{'metaData'} = $values_7;
221
        }
222
        return $data;
223
    }
224
}