Completed
Push — master ( cc2b64...3127a8 )
by
unknown
28:00 queued 12:57
created

ProductModelNormalizer   C

Complexity

Total Complexity 53

Size/Duplication

Total Lines 170
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 109
c 1
b 0
f 1
dl 0
loc 170
rs 6.96
wmc 53

4 Methods

Rating   Name   Duplication   Size   Complexity  
A supportsDenormalization() 0 3 1
A supportsNormalization() 0 3 1
F denormalize() 0 80 26
F normalize() 0 77 25

How to fix   Complexity   

Complex Class

Complex classes like ProductModelNormalizer 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 ProductModelNormalizer, 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 ProductModelNormalizer 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\\ProductModel';
20
    }
21
    public function supportsNormalization($data, $format = null)
22
    {
23
        return $data instanceof \Starweb\Api\Generated\Model\ProductModel;
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\ProductModel();
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
            $object->setVariants($this->denormalizer->denormalize($data->{'variants'}, 'Starweb\\Api\\Generated\\Model\\ProductVariantModelCollection', 'json', $context));
0 ignored issues
show
Bug introduced by
It seems like $this->denormalizer->den...ion', 'json', $context) can also be of type array; however, parameter $variants of Starweb\Api\Generated\Mo...uctModel::setVariants() does only seem to accept Starweb\Api\Generated\Mo...antModelCollection|null, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

81
            $object->setVariants(/** @scrutinizer ignore-type */ $this->denormalizer->denormalize($data->{'variants'}, 'Starweb\\Api\\Generated\\Model\\ProductVariantModelCollection', 'json', $context));
Loading history...
82
        }
83
        if (property_exists($data, 'bundledProducts')) {
84
            $object->setBundledProducts($this->denormalizer->denormalize($data->{'bundledProducts'}, 'Starweb\\Api\\Generated\\Model\\BundledProductsModelCollection', 'json', $context));
0 ignored issues
show
Bug introduced by
It seems like $this->denormalizer->den...ion', 'json', $context) can also be of type array; however, parameter $bundledProducts of Starweb\Api\Generated\Mo...l::setBundledProducts() does only seem to accept Starweb\Api\Generated\Mo...ctsModelCollection|null, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

84
            $object->setBundledProducts(/** @scrutinizer ignore-type */ $this->denormalizer->denormalize($data->{'bundledProducts'}, 'Starweb\\Api\\Generated\\Model\\BundledProductsModelCollection', 'json', $context));
Loading history...
85
        }
86
        if (property_exists($data, 'mediaFiles')) {
87
            $object->setMediaFiles($this->denormalizer->denormalize($data->{'mediaFiles'}, 'Starweb\\Api\\Generated\\Model\\ProductMediaFileLinkModelCollection', 'json', $context));
0 ignored issues
show
Bug introduced by
It seems like $this->denormalizer->den...ion', 'json', $context) can also be of type array; however, parameter $mediaFiles of Starweb\Api\Generated\Mo...tModel::setMediaFiles() does only seem to accept Starweb\Api\Generated\Mo...inkModelCollection|null, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

87
            $object->setMediaFiles(/** @scrutinizer ignore-type */ $this->denormalizer->denormalize($data->{'mediaFiles'}, 'Starweb\\Api\\Generated\\Model\\ProductMediaFileLinkModelCollection', 'json', $context));
Loading history...
88
        }
89
        if (property_exists($data, 'languages')) {
90
            $object->setLanguages($this->denormalizer->denormalize($data->{'languages'}, 'Starweb\\Api\\Generated\\Model\\ProductModelLanguages', 'json', $context));
0 ignored issues
show
Bug introduced by
It seems like $this->denormalizer->den...ges', 'json', $context) can also be of type array; however, parameter $languages of Starweb\Api\Generated\Mo...ctModel::setLanguages() does only seem to accept Starweb\Api\Generated\Mo...ductModelLanguages|null, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

90
            $object->setLanguages(/** @scrutinizer ignore-type */ $this->denormalizer->denormalize($data->{'languages'}, 'Starweb\\Api\\Generated\\Model\\ProductModelLanguages', 'json', $context));
Loading history...
91
        }
92
        if (property_exists($data, 'vatRates')) {
93
            $object->setVatRates($this->denormalizer->denormalize($data->{'vatRates'}, 'Starweb\\Api\\Generated\\Model\\ProductVatRateModelCollection', 'json', $context));
0 ignored issues
show
Bug introduced by
It seems like $this->denormalizer->den...ion', 'json', $context) can also be of type array; however, parameter $vatRates of Starweb\Api\Generated\Mo...uctModel::setVatRates() does only seem to accept Starweb\Api\Generated\Mo...ateModelCollection|null, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

93
            $object->setVatRates(/** @scrutinizer ignore-type */ $this->denormalizer->denormalize($data->{'vatRates'}, 'Starweb\\Api\\Generated\\Model\\ProductVatRateModelCollection', 'json', $context));
Loading history...
94
        }
95
        if (property_exists($data, 'categories')) {
96
            $object->setCategories($this->denormalizer->denormalize($data->{'categories'}, 'Starweb\\Api\\Generated\\Model\\ProductCategoryLinkModelCollection', 'json', $context));
0 ignored issues
show
Bug introduced by
It seems like $this->denormalizer->den...ion', 'json', $context) can also be of type array; however, parameter $categories of Starweb\Api\Generated\Mo...tModel::setCategories() does only seem to accept Starweb\Api\Generated\Mo...inkModelCollection|null, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

96
            $object->setCategories(/** @scrutinizer ignore-type */ $this->denormalizer->denormalize($data->{'categories'}, 'Starweb\\Api\\Generated\\Model\\ProductCategoryLinkModelCollection', 'json', $context));
Loading history...
97
        }
98
        if (property_exists($data, 'unit')) {
99
            $object->setUnit($this->denormalizer->denormalize($data->{'unit'}, 'Starweb\\Api\\Generated\\Model\\ProductUnitModelItem', 'json', $context));
0 ignored issues
show
Bug introduced by
It seems like $this->denormalizer->den...tem', 'json', $context) can also be of type array; however, parameter $unit of Starweb\Api\Generated\Mo...ProductModel::setUnit() does only seem to accept Starweb\Api\Generated\Mo...oductUnitModelItem|null, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

99
            $object->setUnit(/** @scrutinizer ignore-type */ $this->denormalizer->denormalize($data->{'unit'}, 'Starweb\\Api\\Generated\\Model\\ProductUnitModelItem', 'json', $context));
Loading history...
100
        }
101
        if (property_exists($data, 'metaData')) {
102
            $object->setMetaData($this->denormalizer->denormalize($data->{'metaData'}, 'Starweb\\Api\\Generated\\Model\\ProductMetaDataModelCollection', 'json', $context));
0 ignored issues
show
Bug introduced by
It seems like $this->denormalizer->den...ion', 'json', $context) can also be of type array; however, parameter $metaData of Starweb\Api\Generated\Mo...uctModel::setMetaData() does only seem to accept Starweb\Api\Generated\Mo...ataModelCollection|null, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

102
            $object->setMetaData(/** @scrutinizer ignore-type */ $this->denormalizer->denormalize($data->{'metaData'}, 'Starweb\\Api\\Generated\\Model\\ProductMetaDataModelCollection', 'json', $context));
Loading history...
103
        }
104
        return $object;
105
    }
106
    public function normalize($object, $format = null, array $context = array())
107
    {
108
        $data = new \stdClass();
109
        if (null !== $object->getProductId()) {
110
            $data->{'productId'} = $object->getProductId();
111
        }
112
        if (null !== $object->getCreatedAt()) {
113
            $data->{'createdAt'} = $object->getCreatedAt();
114
        }
115
        if (null !== $object->getDefaultVatRate()) {
116
            $data->{'defaultVatRate'} = $object->getDefaultVatRate();
117
        }
118
        if (null !== $object->getVisibility()) {
119
            $data->{'visibility'} = $object->getVisibility();
120
        }
121
        if (null !== $object->getVisibilityPricelistIds()) {
122
            $values = array();
123
            foreach ($object->getVisibilityPricelistIds() as $value) {
124
                $values[] = $value;
125
            }
126
            $data->{'visibilityPricelistIds'} = $values;
127
        }
128
        if (null !== $object->getMoreInfoUrl()) {
129
            $data->{'moreInfoUrl'} = $object->getMoreInfoUrl();
130
        }
131
        if (null !== $object->getManufacturerId()) {
132
            $data->{'manufacturerId'} = $object->getManufacturerId();
133
        }
134
        if (null !== $object->getUnitId()) {
135
            $data->{'unitId'} = $object->getUnitId();
136
        }
137
        if (null !== $object->getSortIndex()) {
138
            $data->{'sortIndex'} = $object->getSortIndex();
139
        }
140
        if (null !== $object->getType()) {
141
            $data->{'type'} = $object->getType();
142
        }
143
        if (null !== $object->getIsBackInStockWatchable()) {
144
            $data->{'isBackInStockWatchable'} = $object->getIsBackInStockWatchable();
145
        }
146
        if (null !== $object->getBundleUseManualPrice()) {
147
            $data->{'bundleUseManualPrice'} = $object->getBundleUseManualPrice();
148
        }
149
        if (null !== $object->getAccounting()) {
150
            $data->{'accounting'} = $object->getAccounting();
151
        }
152
        if (null !== $object->getHasSeveralVariants()) {
153
            $data->{'hasSeveralVariants'} = $object->getHasSeveralVariants();
154
        }
155
        if (null !== $object->getModifiedAt()) {
156
            $data->{'modifiedAt'} = $object->getModifiedAt();
157
        }
158
        if (null !== $object->getVariants()) {
159
            $data->{'variants'} = $this->normalizer->normalize($object->getVariants(), 'json', $context);
160
        }
161
        if (null !== $object->getBundledProducts()) {
162
            $data->{'bundledProducts'} = $this->normalizer->normalize($object->getBundledProducts(), 'json', $context);
163
        }
164
        if (null !== $object->getMediaFiles()) {
165
            $data->{'mediaFiles'} = $this->normalizer->normalize($object->getMediaFiles(), 'json', $context);
166
        }
167
        if (null !== $object->getLanguages()) {
168
            $data->{'languages'} = $this->normalizer->normalize($object->getLanguages(), 'json', $context);
169
        }
170
        if (null !== $object->getVatRates()) {
171
            $data->{'vatRates'} = $this->normalizer->normalize($object->getVatRates(), 'json', $context);
172
        }
173
        if (null !== $object->getCategories()) {
174
            $data->{'categories'} = $this->normalizer->normalize($object->getCategories(), 'json', $context);
175
        }
176
        if (null !== $object->getUnit()) {
177
            $data->{'unit'} = $this->normalizer->normalize($object->getUnit(), 'json', $context);
178
        }
179
        if (null !== $object->getMetaData()) {
180
            $data->{'metaData'} = $this->normalizer->normalize($object->getMetaData(), 'json', $context);
181
        }
182
        return $data;
183
    }
184
}