OrderUpdateModelNormalizer   F
last analyzed

Complexity

Total Complexity 109

Size/Duplication

Total Lines 338
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 221
c 1
b 0
f 1
dl 0
loc 338
rs 2
wmc 109

4 Methods

Rating   Name   Duplication   Size   Complexity  
F normalize() 0 161 53
A supportsDenormalization() 0 3 1
F denormalize() 0 164 54
A supportsNormalization() 0 3 1

How to fix   Complexity   

Complex Class

Complex classes like OrderUpdateModelNormalizer 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 OrderUpdateModelNormalizer, 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 OrderUpdateModelNormalizer 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\\OrderUpdateModel';
20
    }
21
    public function supportsNormalization($data, $format = null)
22
    {
23
        return get_class($data) === 'Starweb\\Api\\Generated\\Model\\OrderUpdateModel';
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\OrderUpdateModel();
31
        if (property_exists($data, 'orderId')) {
32
            $object->setOrderId($data->{'orderId'});
33
        }
34
        if (property_exists($data, 'modifiedAt')) {
35
            $object->setModifiedAt($data->{'modifiedAt'});
36
        }
37
        if (property_exists($data, 'baseCurrencyCode')) {
38
            $object->setBaseCurrencyCode($data->{'baseCurrencyCode'});
39
        }
40
        if (property_exists($data, 'shopCountryCode')) {
41
            $object->setShopCountryCode($data->{'shopCountryCode'});
42
        }
43
        if (property_exists($data, 'totalAmount')) {
44
            $object->setTotalAmount($data->{'totalAmount'});
45
        }
46
        if (property_exists($data, 'totalVat')) {
47
            $object->setTotalVat($data->{'totalVat'});
48
        }
49
        if (property_exists($data, 'amountToPay')) {
50
            $object->setAmountToPay($data->{'amountToPay'});
51
        }
52
        if (property_exists($data, 'totalAmountInBaseCurrency')) {
53
            $object->setTotalAmountInBaseCurrency($data->{'totalAmountInBaseCurrency'});
54
        }
55
        if (property_exists($data, 'totalVatInBaseCurrency')) {
56
            $object->setTotalVatInBaseCurrency($data->{'totalVatInBaseCurrency'});
57
        }
58
        if (property_exists($data, 'amountToPayInBaseCurrency')) {
59
            $object->setAmountToPayInBaseCurrency($data->{'amountToPayInBaseCurrency'});
60
        }
61
        if (property_exists($data, 'createdAt')) {
62
            $object->setCreatedAt($data->{'createdAt'});
63
        }
64
        if (property_exists($data, 'customerId')) {
65
            $object->setCustomerId($data->{'customerId'});
66
        }
67
        if (property_exists($data, 'statusId')) {
68
            $object->setStatusId($data->{'statusId'});
69
        }
70
        if (property_exists($data, 'onOrderStatusChangeSendEmail')) {
71
            $object->setOnOrderStatusChangeSendEmail($data->{'onOrderStatusChangeSendEmail'});
72
        }
73
        if (property_exists($data, 'onOrderStatusChangeProcessPayment')) {
74
            $object->setOnOrderStatusChangeProcessPayment($data->{'onOrderStatusChangeProcessPayment'});
75
        }
76
        if (property_exists($data, 'shippingMethodId')) {
77
            $object->setShippingMethodId($data->{'shippingMethodId'});
78
        }
79
        if (property_exists($data, 'paymentMethodId')) {
80
            $object->setPaymentMethodId($data->{'paymentMethodId'});
81
        }
82
        if (property_exists($data, 'paymentMethodIdCode')) {
83
            $object->setPaymentMethodIdCode($data->{'paymentMethodIdCode'});
84
        }
85
        if (property_exists($data, 'paymentMethodName')) {
86
            $object->setPaymentMethodName($data->{'paymentMethodName'});
87
        }
88
        if (property_exists($data, 'paymentFee')) {
89
            $object->setPaymentFee($data->{'paymentFee'});
90
        }
91
        if (property_exists($data, 'paymentVatRate')) {
92
            $object->setPaymentVatRate($data->{'paymentVatRate'});
93
        }
94
        if (property_exists($data, 'shippingMethodName')) {
95
            $object->setShippingMethodName($data->{'shippingMethodName'});
96
        }
97
        if (property_exists($data, 'shippingCost')) {
98
            $object->setShippingCost($data->{'shippingCost'});
99
        }
100
        if (property_exists($data, 'shippingVatRate')) {
101
            $object->setShippingVatRate($data->{'shippingVatRate'});
102
        }
103
        if (property_exists($data, 'totalWeight')) {
104
            $object->setTotalWeight($data->{'totalWeight'});
105
        }
106
        if (property_exists($data, 'customInfo1')) {
107
            $object->setCustomInfo1($data->{'customInfo1'});
108
        }
109
        if (property_exists($data, 'customInfo2')) {
110
            $object->setCustomInfo2($data->{'customInfo2'});
111
        }
112
        if (property_exists($data, 'customInfo3')) {
113
            $object->setCustomInfo3($data->{'customInfo3'});
114
        }
115
        if (property_exists($data, 'customInfo4')) {
116
            $object->setCustomInfo4($data->{'customInfo4'});
117
        }
118
        if (property_exists($data, 'discountCode')) {
119
            $object->setDiscountCode($data->{'discountCode'});
120
        }
121
        if (property_exists($data, 'amountPaid')) {
122
            $object->setAmountPaid($data->{'amountPaid'});
123
        }
124
        if (property_exists($data, 'amountPaidInBaseCurrency')) {
125
            $object->setAmountPaidInBaseCurrency($data->{'amountPaidInBaseCurrency'});
126
        }
127
        if (property_exists($data, 'isComplete')) {
128
            $object->setIsComplete($data->{'isComplete'});
129
        }
130
        if (property_exists($data, 'currencyCode')) {
131
            $object->setCurrencyCode($data->{'currencyCode'});
132
        }
133
        if (property_exists($data, 'currencyExchangeRate')) {
134
            $object->setCurrencyExchangeRate($data->{'currencyExchangeRate'});
135
        }
136
        if (property_exists($data, 'currencyPrecision')) {
137
            $object->setCurrencyPrecision($data->{'currencyPrecision'});
138
        }
139
        if (property_exists($data, 'langCode')) {
140
            $object->setLangCode($data->{'langCode'});
141
        }
142
        if (property_exists($data, 'paymentReference')) {
143
            $object->setPaymentReference($data->{'paymentReference'});
144
        }
145
        if (property_exists($data, 'paymentStatus')) {
146
            $object->setPaymentStatus($data->{'paymentStatus'});
147
        }
148
        if (property_exists($data, 'isRead')) {
149
            $object->setIsRead($data->{'isRead'});
150
        }
151
        if (property_exists($data, 'hasComment')) {
152
            $object->setHasComment($data->{'hasComment'});
153
        }
154
        if (property_exists($data, 'internalComment')) {
155
            $object->setInternalComment($data->{'internalComment'});
156
        }
157
        if (property_exists($data, 'shippingTrackerType')) {
158
            $object->setShippingTrackerType($data->{'shippingTrackerType'});
159
        }
160
        if (property_exists($data, 'shippingTrackingNo')) {
161
            $object->setShippingTrackingNo($data->{'shippingTrackingNo'});
162
        }
163
        if (property_exists($data, 'originalCustomerEmail')) {
164
            $object->setOriginalCustomerEmail($data->{'originalCustomerEmail'});
165
        }
166
        if (property_exists($data, 'originalCustomerNationalIdNo')) {
167
            $object->setOriginalCustomerNationalIdNo($data->{'originalCustomerNationalIdNo'});
168
        }
169
        if (property_exists($data, 'originalCustomerVatNo')) {
170
            $object->setOriginalCustomerVatNo($data->{'originalCustomerVatNo'});
171
        }
172
        if (property_exists($data, 'originalCustomerCustomInfo1')) {
173
            $object->setOriginalCustomerCustomInfo1($data->{'originalCustomerCustomInfo1'});
174
        }
175
        if (property_exists($data, 'originalCustomerCustomInfo2')) {
176
            $object->setOriginalCustomerCustomInfo2($data->{'originalCustomerCustomInfo2'});
177
        }
178
        if (property_exists($data, 'items')) {
179
            $values = array();
180
            foreach ($data->{'items'} as $value) {
181
                $values[] = $this->denormalizer->denormalize($value, 'Starweb\\Api\\Generated\\Model\\OrderItemModel', 'json', $context);
182
            }
183
            $object->setItems($values);
184
        }
185
        if (property_exists($data, 'addresses')) {
186
            $object->setAddresses($this->denormalizer->denormalize($data->{'addresses'}, 'Starweb\\Api\\Generated\\Model\\OrderAddressModel', 'json', $context));
0 ignored issues
show
Bug introduced by
It seems like $this->denormalizer->den...del', 'json', $context) can also be of type array; however, parameter $addresses of Starweb\Api\Generated\Mo...teModel::setAddresses() does only seem to accept Starweb\Api\Generated\Model\OrderAddressModel, 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

186
            $object->setAddresses(/** @scrutinizer ignore-type */ $this->denormalizer->denormalize($data->{'addresses'}, 'Starweb\\Api\\Generated\\Model\\OrderAddressModel', 'json', $context));
Loading history...
187
        }
188
        return $object;
189
    }
190
    public function normalize($object, $format = null, array $context = array())
191
    {
192
        $data = new \stdClass();
193
        if (null !== $object->getOrderId()) {
194
            $data->{'orderId'} = $object->getOrderId();
195
        }
196
        if (null !== $object->getModifiedAt()) {
197
            $data->{'modifiedAt'} = $object->getModifiedAt();
198
        }
199
        if (null !== $object->getBaseCurrencyCode()) {
200
            $data->{'baseCurrencyCode'} = $object->getBaseCurrencyCode();
201
        }
202
        if (null !== $object->getShopCountryCode()) {
203
            $data->{'shopCountryCode'} = $object->getShopCountryCode();
204
        }
205
        if (null !== $object->getTotalAmount()) {
206
            $data->{'totalAmount'} = $object->getTotalAmount();
207
        }
208
        if (null !== $object->getTotalVat()) {
209
            $data->{'totalVat'} = $object->getTotalVat();
210
        }
211
        if (null !== $object->getAmountToPay()) {
212
            $data->{'amountToPay'} = $object->getAmountToPay();
213
        }
214
        if (null !== $object->getTotalAmountInBaseCurrency()) {
215
            $data->{'totalAmountInBaseCurrency'} = $object->getTotalAmountInBaseCurrency();
216
        }
217
        if (null !== $object->getTotalVatInBaseCurrency()) {
218
            $data->{'totalVatInBaseCurrency'} = $object->getTotalVatInBaseCurrency();
219
        }
220
        if (null !== $object->getAmountToPayInBaseCurrency()) {
221
            $data->{'amountToPayInBaseCurrency'} = $object->getAmountToPayInBaseCurrency();
222
        }
223
        if (null !== $object->getCreatedAt()) {
224
            $data->{'createdAt'} = $object->getCreatedAt();
225
        }
226
        if (null !== $object->getCustomerId()) {
227
            $data->{'customerId'} = $object->getCustomerId();
228
        }
229
        if (null !== $object->getStatusId()) {
230
            $data->{'statusId'} = $object->getStatusId();
231
        }
232
        if (null !== $object->getOnOrderStatusChangeSendEmail()) {
233
            $data->{'onOrderStatusChangeSendEmail'} = $object->getOnOrderStatusChangeSendEmail();
234
        }
235
        if (null !== $object->getOnOrderStatusChangeProcessPayment()) {
236
            $data->{'onOrderStatusChangeProcessPayment'} = $object->getOnOrderStatusChangeProcessPayment();
237
        }
238
        if (null !== $object->getShippingMethodId()) {
239
            $data->{'shippingMethodId'} = $object->getShippingMethodId();
240
        }
241
        if (null !== $object->getPaymentMethodId()) {
242
            $data->{'paymentMethodId'} = $object->getPaymentMethodId();
243
        }
244
        if (null !== $object->getPaymentMethodIdCode()) {
245
            $data->{'paymentMethodIdCode'} = $object->getPaymentMethodIdCode();
246
        }
247
        if (null !== $object->getPaymentMethodName()) {
248
            $data->{'paymentMethodName'} = $object->getPaymentMethodName();
249
        }
250
        if (null !== $object->getPaymentFee()) {
251
            $data->{'paymentFee'} = $object->getPaymentFee();
252
        }
253
        if (null !== $object->getPaymentVatRate()) {
254
            $data->{'paymentVatRate'} = $object->getPaymentVatRate();
255
        }
256
        if (null !== $object->getShippingMethodName()) {
257
            $data->{'shippingMethodName'} = $object->getShippingMethodName();
258
        }
259
        if (null !== $object->getShippingCost()) {
260
            $data->{'shippingCost'} = $object->getShippingCost();
261
        }
262
        if (null !== $object->getShippingVatRate()) {
263
            $data->{'shippingVatRate'} = $object->getShippingVatRate();
264
        }
265
        if (null !== $object->getTotalWeight()) {
266
            $data->{'totalWeight'} = $object->getTotalWeight();
267
        }
268
        if (null !== $object->getCustomInfo1()) {
269
            $data->{'customInfo1'} = $object->getCustomInfo1();
270
        }
271
        if (null !== $object->getCustomInfo2()) {
272
            $data->{'customInfo2'} = $object->getCustomInfo2();
273
        }
274
        if (null !== $object->getCustomInfo3()) {
275
            $data->{'customInfo3'} = $object->getCustomInfo3();
276
        }
277
        if (null !== $object->getCustomInfo4()) {
278
            $data->{'customInfo4'} = $object->getCustomInfo4();
279
        }
280
        if (null !== $object->getDiscountCode()) {
281
            $data->{'discountCode'} = $object->getDiscountCode();
282
        }
283
        if (null !== $object->getAmountPaid()) {
284
            $data->{'amountPaid'} = $object->getAmountPaid();
285
        }
286
        if (null !== $object->getAmountPaidInBaseCurrency()) {
287
            $data->{'amountPaidInBaseCurrency'} = $object->getAmountPaidInBaseCurrency();
288
        }
289
        if (null !== $object->getIsComplete()) {
290
            $data->{'isComplete'} = $object->getIsComplete();
291
        }
292
        if (null !== $object->getCurrencyCode()) {
293
            $data->{'currencyCode'} = $object->getCurrencyCode();
294
        }
295
        if (null !== $object->getCurrencyExchangeRate()) {
296
            $data->{'currencyExchangeRate'} = $object->getCurrencyExchangeRate();
297
        }
298
        if (null !== $object->getCurrencyPrecision()) {
299
            $data->{'currencyPrecision'} = $object->getCurrencyPrecision();
300
        }
301
        if (null !== $object->getLangCode()) {
302
            $data->{'langCode'} = $object->getLangCode();
303
        }
304
        if (null !== $object->getPaymentReference()) {
305
            $data->{'paymentReference'} = $object->getPaymentReference();
306
        }
307
        if (null !== $object->getPaymentStatus()) {
308
            $data->{'paymentStatus'} = $object->getPaymentStatus();
309
        }
310
        if (null !== $object->getIsRead()) {
311
            $data->{'isRead'} = $object->getIsRead();
312
        }
313
        if (null !== $object->getHasComment()) {
314
            $data->{'hasComment'} = $object->getHasComment();
315
        }
316
        if (null !== $object->getInternalComment()) {
317
            $data->{'internalComment'} = $object->getInternalComment();
318
        }
319
        if (null !== $object->getShippingTrackerType()) {
320
            $data->{'shippingTrackerType'} = $object->getShippingTrackerType();
321
        }
322
        if (null !== $object->getShippingTrackingNo()) {
323
            $data->{'shippingTrackingNo'} = $object->getShippingTrackingNo();
324
        }
325
        if (null !== $object->getOriginalCustomerEmail()) {
326
            $data->{'originalCustomerEmail'} = $object->getOriginalCustomerEmail();
327
        }
328
        if (null !== $object->getOriginalCustomerNationalIdNo()) {
329
            $data->{'originalCustomerNationalIdNo'} = $object->getOriginalCustomerNationalIdNo();
330
        }
331
        if (null !== $object->getOriginalCustomerVatNo()) {
332
            $data->{'originalCustomerVatNo'} = $object->getOriginalCustomerVatNo();
333
        }
334
        if (null !== $object->getOriginalCustomerCustomInfo1()) {
335
            $data->{'originalCustomerCustomInfo1'} = $object->getOriginalCustomerCustomInfo1();
336
        }
337
        if (null !== $object->getOriginalCustomerCustomInfo2()) {
338
            $data->{'originalCustomerCustomInfo2'} = $object->getOriginalCustomerCustomInfo2();
339
        }
340
        if (null !== $object->getItems()) {
341
            $values = array();
342
            foreach ($object->getItems() as $value) {
343
                $values[] = $this->normalizer->normalize($value, 'json', $context);
344
            }
345
            $data->{'items'} = $values;
346
        }
347
        if (null !== $object->getAddresses()) {
348
            $data->{'addresses'} = $this->normalizer->normalize($object->getAddresses(), 'json', $context);
349
        }
350
        return $data;
351
    }
352
}