ProductModelPatchableNormalizer   B
last analyzed

Complexity

Total Complexity 52

Size/Duplication

Total Lines 182
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 122
c 1
b 0
f 1
dl 0
loc 182
rs 7.44
wmc 52

4 Methods

Rating   Name   Duplication   Size   Complexity  
A supportsDenormalization() 0 3 1
A supportsNormalization() 0 3 1
F denormalize() 0 91 28
F normalize() 0 78 22

How to fix   Complexity   

Complex Class

Complex classes like ProductModelPatchableNormalizer 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 ProductModelPatchableNormalizer, 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 ProductModelPatchableNormalizer 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\\ProductModelPatchable';
20
    }
21
    public function supportsNormalization($data, $format = null)
22
    {
23
        return get_class($data) === 'Starweb\\Api\\Generated\\Model\\ProductModelPatchable';
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\ProductModelPatchable();
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, 'mediaFiles')) {
81
            $values_1 = array();
82
            foreach ($data->{'mediaFiles'} as $value_1) {
83
                $values_1[] = $this->denormalizer->denormalize($value_1, 'Starweb\\Api\\Generated\\Model\\ProductMediaFileLinkModel', 'json', $context);
84
            }
85
            $object->setMediaFiles($values_1);
86
        }
87
        if (property_exists($data, 'languages')) {
88
            $values_2 = array();
89
            foreach ($data->{'languages'} as $value_2) {
90
                $values_2[] = $this->denormalizer->denormalize($value_2, 'Starweb\\Api\\Generated\\Model\\ProductLanguageModel', 'json', $context);
91
            }
92
            $object->setLanguages($values_2);
93
        }
94
        if (property_exists($data, 'vatRates')) {
95
            $values_3 = array();
96
            foreach ($data->{'vatRates'} as $value_3) {
97
                $values_3[] = $this->denormalizer->denormalize($value_3, 'Starweb\\Api\\Generated\\Model\\ProductVatRateModel', 'json', $context);
98
            }
99
            $object->setVatRates($values_3);
100
        }
101
        if (property_exists($data, 'categories')) {
102
            $values_4 = array();
103
            foreach ($data->{'categories'} as $value_4) {
104
                $values_4[] = $this->denormalizer->denormalize($value_4, 'Starweb\\Api\\Generated\\Model\\ProductCategoryLinkModel', 'json', $context);
105
            }
106
            $object->setCategories($values_4);
107
        }
108
        if (property_exists($data, 'metaData')) {
109
            $values_5 = array();
110
            foreach ($data->{'metaData'} as $value_5) {
111
                $values_5[] = $this->denormalizer->denormalize($value_5, 'Starweb\\Api\\Generated\\Model\\ProductMetaDataModelUpdatable', 'json', $context);
112
            }
113
            $object->setMetaData($values_5);
114
        }
115
        return $object;
116
    }
117
    public function normalize($object, $format = null, array $context = array())
118
    {
119
        $data = new \stdClass();
120
        if (null !== $object->getProductId()) {
121
            $data->{'productId'} = $object->getProductId();
122
        }
123
        if (null !== $object->getCreatedAt()) {
124
            $data->{'createdAt'} = $object->getCreatedAt();
125
        }
126
        $data->{'defaultVatRate'} = $object->getDefaultVatRate();
127
        if (null !== $object->getVisibility()) {
128
            $data->{'visibility'} = $object->getVisibility();
129
        }
130
        if (null !== $object->getVisibilityPricelistIds()) {
131
            $values = array();
132
            foreach ($object->getVisibilityPricelistIds() as $value) {
133
                $values[] = $value;
134
            }
135
            $data->{'visibilityPricelistIds'} = $values;
136
        }
137
        if (null !== $object->getMoreInfoUrl()) {
138
            $data->{'moreInfoUrl'} = $object->getMoreInfoUrl();
139
        }
140
        $data->{'manufacturerId'} = $object->getManufacturerId();
141
        $data->{'unitId'} = $object->getUnitId();
142
        $data->{'sortIndex'} = $object->getSortIndex();
143
        if (null !== $object->getType()) {
144
            $data->{'type'} = $object->getType();
145
        }
146
        if (null !== $object->getIsBackInStockWatchable()) {
147
            $data->{'isBackInStockWatchable'} = $object->getIsBackInStockWatchable();
148
        }
149
        if (null !== $object->getBundleUseManualPrice()) {
150
            $data->{'bundleUseManualPrice'} = $object->getBundleUseManualPrice();
151
        }
152
        $data->{'accounting'} = $object->getAccounting();
153
        if (null !== $object->getHasSeveralVariants()) {
154
            $data->{'hasSeveralVariants'} = $object->getHasSeveralVariants();
155
        }
156
        if (null !== $object->getModifiedAt()) {
157
            $data->{'modifiedAt'} = $object->getModifiedAt();
158
        }
159
        if (null !== $object->getMediaFiles()) {
160
            $values_1 = array();
161
            foreach ($object->getMediaFiles() as $value_1) {
162
                $values_1[] = $this->normalizer->normalize($value_1, 'json', $context);
163
            }
164
            $data->{'mediaFiles'} = $values_1;
165
        }
166
        if (null !== $object->getLanguages()) {
167
            $values_2 = array();
168
            foreach ($object->getLanguages() as $value_2) {
169
                $values_2[] = $this->normalizer->normalize($value_2, 'json', $context);
170
            }
171
            $data->{'languages'} = $values_2;
172
        }
173
        if (null !== $object->getVatRates()) {
174
            $values_3 = array();
175
            foreach ($object->getVatRates() as $value_3) {
176
                $values_3[] = $this->normalizer->normalize($value_3, 'json', $context);
177
            }
178
            $data->{'vatRates'} = $values_3;
179
        }
180
        if (null !== $object->getCategories()) {
181
            $values_4 = array();
182
            foreach ($object->getCategories() as $value_4) {
183
                $values_4[] = $this->normalizer->normalize($value_4, 'json', $context);
184
            }
185
            $data->{'categories'} = $values_4;
186
        }
187
        if (null !== $object->getMetaData()) {
188
            $values_5 = array();
189
            foreach ($object->getMetaData() as $value_5) {
190
                $values_5[] = $this->normalizer->normalize($value_5, 'json', $context);
191
            }
192
            $data->{'metaData'} = $values_5;
193
        }
194
        return $data;
195
    }
196
}