Passed
Push — master ( 9db3d0...354d5b )
by Reyo
02:53
created

CustomerNormalizer::normalize()   F

Complexity

Conditions 32
Paths > 20000

Size

Total Lines 158
Code Lines 124

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 1056

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 32
eloc 124
c 1
b 0
f 0
nc 536870912
nop 3
dl 0
loc 158
ccs 0
cts 157
cp 0
crap 1056
rs 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the timechimp bundle package.
7
 * (c) Connect Holland.
8
 */
9
10
namespace ConnectHolland\TimechimpBundle\Api\Normalizer;
11
12
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface;
13
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait;
14
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
15
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
16
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
17
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
18
19
class CustomerNormalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface
20
{
21
    use DenormalizerAwareTrait;
22
    use NormalizerAwareTrait;
23
24
    public function supportsDenormalization($data, $type, $format = null)
25
    {
26
        return $type === 'ConnectHolland\\TimechimpBundle\\Api\\Model\\Customer';
27
    }
28
29
    public function supportsNormalization($data, $format = null)
30
    {
31
        return is_object($data) && get_class($data) === 'ConnectHolland\\TimechimpBundle\\Api\\Model\\Customer';
32
    }
33
34
    public function denormalize($data, $class, $format = null, array $context = [])
35
    {
36
        if (!is_object($data)) {
37
            return null;
38
        }
39
        $object = new \ConnectHolland\TimechimpBundle\Api\Model\Customer();
40
        if (property_exists($data, 'id') && $data->{'id'} !== null) {
41
            $object->setId($data->{'id'});
42
        } elseif (property_exists($data, 'id') && $data->{'id'} === null) {
43
            $object->setId(null);
44
        }
45
        if (property_exists($data, 'active') && $data->{'active'} !== null) {
46
            $object->setActive($data->{'active'});
47
        } elseif (property_exists($data, 'active') && $data->{'active'} === null) {
48
            $object->setActive(null);
49
        }
50
        if (property_exists($data, 'relationId') && $data->{'relationId'} !== null) {
51
            $object->setRelationId($data->{'relationId'});
52
        } elseif (property_exists($data, 'relationId') && $data->{'relationId'} === null) {
53
            $object->setRelationId(null);
54
        }
55
        if (property_exists($data, 'name') && $data->{'name'} !== null) {
56
            $object->setName($data->{'name'});
57
        } elseif (property_exists($data, 'name') && $data->{'name'} === null) {
58
            $object->setName(null);
59
        }
60
        if (property_exists($data, 'address') && $data->{'address'} !== null) {
61
            $object->setAddress($data->{'address'});
62
        } elseif (property_exists($data, 'address') && $data->{'address'} === null) {
63
            $object->setAddress(null);
64
        }
65
        if (property_exists($data, 'postalCode') && $data->{'postalCode'} !== null) {
66
            $object->setPostalCode($data->{'postalCode'});
67
        } elseif (property_exists($data, 'postalCode') && $data->{'postalCode'} === null) {
68
            $object->setPostalCode(null);
69
        }
70
        if (property_exists($data, 'city') && $data->{'city'} !== null) {
71
            $object->setCity($data->{'city'});
72
        } elseif (property_exists($data, 'city') && $data->{'city'} === null) {
73
            $object->setCity(null);
74
        }
75
        if (property_exists($data, 'country') && $data->{'country'} !== null) {
76
            $object->setCountry($data->{'country'});
77
        } elseif (property_exists($data, 'country') && $data->{'country'} === null) {
78
            $object->setCountry(null);
79
        }
80
        if (property_exists($data, 'phone') && $data->{'phone'} !== null) {
81
            $object->setPhone($data->{'phone'});
82
        } elseif (property_exists($data, 'phone') && $data->{'phone'} === null) {
83
            $object->setPhone(null);
84
        }
85
        if (property_exists($data, 'email') && $data->{'email'} !== null) {
86
            $object->setEmail($data->{'email'});
87
        } elseif (property_exists($data, 'email') && $data->{'email'} === null) {
88
            $object->setEmail(null);
89
        }
90
        if (property_exists($data, 'website') && $data->{'website'} !== null) {
91
            $object->setWebsite($data->{'website'});
92
        } elseif (property_exists($data, 'website') && $data->{'website'} === null) {
93
            $object->setWebsite(null);
94
        }
95
        if (property_exists($data, 'paymentPeriod') && $data->{'paymentPeriod'} !== null) {
96
            $object->setPaymentPeriod($data->{'paymentPeriod'});
97
        } elseif (property_exists($data, 'paymentPeriod') && $data->{'paymentPeriod'} === null) {
98
            $object->setPaymentPeriod(null);
99
        }
100
        if (property_exists($data, 'tax') && $data->{'tax'} !== null) {
101
            $object->setTax($data->{'tax'});
102
        } elseif (property_exists($data, 'tax') && $data->{'tax'} === null) {
103
            $object->setTax(null);
104
        }
105
        if (property_exists($data, 'hourlyRate') && $data->{'hourlyRate'} !== null) {
106
            $object->setHourlyRate($data->{'hourlyRate'});
107
        } elseif (property_exists($data, 'hourlyRate') && $data->{'hourlyRate'} === null) {
108
            $object->setHourlyRate(null);
109
        }
110
        if (property_exists($data, 'mileageRate') && $data->{'mileageRate'} !== null) {
111
            $object->setMileageRate($data->{'mileageRate'});
112
        } elseif (property_exists($data, 'mileageRate') && $data->{'mileageRate'} === null) {
113
            $object->setMileageRate(null);
114
        }
115
        if (property_exists($data, 'iban') && $data->{'iban'} !== null) {
116
            $object->setIban($data->{'iban'});
117
        } elseif (property_exists($data, 'iban') && $data->{'iban'} === null) {
118
            $object->setIban(null);
119
        }
120
        if (property_exists($data, 'bic') && $data->{'bic'} !== null) {
121
            $object->setBic($data->{'bic'});
122
        } elseif (property_exists($data, 'bic') && $data->{'bic'} === null) {
123
            $object->setBic(null);
124
        }
125
        if (property_exists($data, 'vatNumber') && $data->{'vatNumber'} !== null) {
126
            $object->setVatNumber($data->{'vatNumber'});
127
        } elseif (property_exists($data, 'vatNumber') && $data->{'vatNumber'} === null) {
128
            $object->setVatNumber(null);
129
        }
130
        if (property_exists($data, 'kvkNumber') && $data->{'kvkNumber'} !== null) {
131
            $object->setKvkNumber($data->{'kvkNumber'});
132
        } elseif (property_exists($data, 'kvkNumber') && $data->{'kvkNumber'} === null) {
133
            $object->setKvkNumber(null);
134
        }
135
        if (property_exists($data, 'invoiceAddress') && $data->{'invoiceAddress'} !== null) {
136
            $object->setInvoiceAddress($data->{'invoiceAddress'});
137
        } elseif (property_exists($data, 'invoiceAddress') && $data->{'invoiceAddress'} === null) {
138
            $object->setInvoiceAddress(null);
139
        }
140
        if (property_exists($data, 'invoicePostalCode') && $data->{'invoicePostalCode'} !== null) {
141
            $object->setInvoicePostalCode($data->{'invoicePostalCode'});
142
        } elseif (property_exists($data, 'invoicePostalCode') && $data->{'invoicePostalCode'} === null) {
143
            $object->setInvoicePostalCode(null);
144
        }
145
        if (property_exists($data, 'invoiceCity') && $data->{'invoiceCity'} !== null) {
146
            $object->setInvoiceCity($data->{'invoiceCity'});
147
        } elseif (property_exists($data, 'invoiceCity') && $data->{'invoiceCity'} === null) {
148
            $object->setInvoiceCity(null);
149
        }
150
        if (property_exists($data, 'invoiceCountry') && $data->{'invoiceCountry'} !== null) {
151
            $object->setInvoiceCountry($data->{'invoiceCountry'});
152
        } elseif (property_exists($data, 'invoiceCountry') && $data->{'invoiceCountry'} === null) {
153
            $object->setInvoiceCountry(null);
154
        }
155
        if (property_exists($data, 'notes') && $data->{'notes'} !== null) {
156
            $object->setNotes($data->{'notes'});
157
        } elseif (property_exists($data, 'notes') && $data->{'notes'} === null) {
158
            $object->setNotes(null);
159
        }
160
        if (property_exists($data, 'clientId') && $data->{'clientId'} !== null) {
161
            $object->setClientId($data->{'clientId'});
162
        } elseif (property_exists($data, 'clientId') && $data->{'clientId'} === null) {
163
            $object->setClientId(null);
164
        }
165
        if (property_exists($data, 'tagIds') && $data->{'tagIds'} !== null) {
166
            $values = [];
167
            foreach ($data->{'tagIds'} as $value) {
168
                $values[] = $value;
169
            }
170
            $object->setTagIds($values);
171
        } elseif (property_exists($data, 'tagIds') && $data->{'tagIds'} === null) {
172
            $object->setTagIds(null);
173
        }
174
        if (property_exists($data, 'tagNames') && $data->{'tagNames'} !== null) {
175
            $values_1 = [];
176
            foreach ($data->{'tagNames'} as $value_1) {
177
                $values_1[] = $value_1;
178
            }
179
            $object->setTagNames($values_1);
180
        } elseif (property_exists($data, 'tagNames') && $data->{'tagNames'} === null) {
181
            $object->setTagNames(null);
182
        }
183
        if (property_exists($data, 'vatRateId') && $data->{'vatRateId'} !== null) {
184
            $object->setVatRateId($data->{'vatRateId'});
185
        } elseif (property_exists($data, 'vatRateId') && $data->{'vatRateId'} === null) {
186
            $object->setVatRateId(null);
187
        }
188
        if (property_exists($data, 'vatRatePercentage') && $data->{'vatRatePercentage'} !== null) {
189
            $object->setVatRatePercentage($data->{'vatRatePercentage'});
190
        } elseif (property_exists($data, 'vatRatePercentage') && $data->{'vatRatePercentage'} === null) {
191
            $object->setVatRatePercentage(null);
192
        }
193
194
        return $object;
195
    }
196
197
    public function normalize($object, $format = null, array $context = [])
198
    {
199
        $data = new \stdClass();
200
        if (null !== $object->getId()) {
201
            $data->{'id'} = $object->getId();
202
        } else {
203
            $data->{'id'} = null;
204
        }
205
        if (null !== $object->getActive()) {
206
            $data->{'active'} = $object->getActive();
207
        } else {
208
            $data->{'active'} = null;
209
        }
210
        if (null !== $object->getRelationId()) {
211
            $data->{'relationId'} = $object->getRelationId();
212
        } else {
213
            $data->{'relationId'} = null;
214
        }
215
        if (null !== $object->getName()) {
216
            $data->{'name'} = $object->getName();
217
        } else {
218
            $data->{'name'} = null;
219
        }
220
        if (null !== $object->getAddress()) {
221
            $data->{'address'} = $object->getAddress();
222
        } else {
223
            $data->{'address'} = null;
224
        }
225
        if (null !== $object->getPostalCode()) {
226
            $data->{'postalCode'} = $object->getPostalCode();
227
        } else {
228
            $data->{'postalCode'} = null;
229
        }
230
        if (null !== $object->getCity()) {
231
            $data->{'city'} = $object->getCity();
232
        } else {
233
            $data->{'city'} = null;
234
        }
235
        if (null !== $object->getCountry()) {
236
            $data->{'country'} = $object->getCountry();
237
        } else {
238
            $data->{'country'} = null;
239
        }
240
        if (null !== $object->getPhone()) {
241
            $data->{'phone'} = $object->getPhone();
242
        } else {
243
            $data->{'phone'} = null;
244
        }
245
        if (null !== $object->getEmail()) {
246
            $data->{'email'} = $object->getEmail();
247
        } else {
248
            $data->{'email'} = null;
249
        }
250
        if (null !== $object->getWebsite()) {
251
            $data->{'website'} = $object->getWebsite();
252
        } else {
253
            $data->{'website'} = null;
254
        }
255
        if (null !== $object->getPaymentPeriod()) {
256
            $data->{'paymentPeriod'} = $object->getPaymentPeriod();
257
        } else {
258
            $data->{'paymentPeriod'} = null;
259
        }
260
        if (null !== $object->getTax()) {
261
            $data->{'tax'} = $object->getTax();
262
        } else {
263
            $data->{'tax'} = null;
264
        }
265
        if (null !== $object->getHourlyRate()) {
266
            $data->{'hourlyRate'} = $object->getHourlyRate();
267
        } else {
268
            $data->{'hourlyRate'} = null;
269
        }
270
        if (null !== $object->getMileageRate()) {
271
            $data->{'mileageRate'} = $object->getMileageRate();
272
        } else {
273
            $data->{'mileageRate'} = null;
274
        }
275
        if (null !== $object->getIban()) {
276
            $data->{'iban'} = $object->getIban();
277
        } else {
278
            $data->{'iban'} = null;
279
        }
280
        if (null !== $object->getBic()) {
281
            $data->{'bic'} = $object->getBic();
282
        } else {
283
            $data->{'bic'} = null;
284
        }
285
        if (null !== $object->getVatNumber()) {
286
            $data->{'vatNumber'} = $object->getVatNumber();
287
        } else {
288
            $data->{'vatNumber'} = null;
289
        }
290
        if (null !== $object->getKvkNumber()) {
291
            $data->{'kvkNumber'} = $object->getKvkNumber();
292
        } else {
293
            $data->{'kvkNumber'} = null;
294
        }
295
        if (null !== $object->getInvoiceAddress()) {
296
            $data->{'invoiceAddress'} = $object->getInvoiceAddress();
297
        } else {
298
            $data->{'invoiceAddress'} = null;
299
        }
300
        if (null !== $object->getInvoicePostalCode()) {
301
            $data->{'invoicePostalCode'} = $object->getInvoicePostalCode();
302
        } else {
303
            $data->{'invoicePostalCode'} = null;
304
        }
305
        if (null !== $object->getInvoiceCity()) {
306
            $data->{'invoiceCity'} = $object->getInvoiceCity();
307
        } else {
308
            $data->{'invoiceCity'} = null;
309
        }
310
        if (null !== $object->getInvoiceCountry()) {
311
            $data->{'invoiceCountry'} = $object->getInvoiceCountry();
312
        } else {
313
            $data->{'invoiceCountry'} = null;
314
        }
315
        if (null !== $object->getNotes()) {
316
            $data->{'notes'} = $object->getNotes();
317
        } else {
318
            $data->{'notes'} = null;
319
        }
320
        if (null !== $object->getClientId()) {
321
            $data->{'clientId'} = $object->getClientId();
322
        } else {
323
            $data->{'clientId'} = null;
324
        }
325
        if (null !== $object->getTagIds()) {
326
            $values = [];
327
            foreach ($object->getTagIds() as $value) {
328
                $values[] = $value;
329
            }
330
            $data->{'tagIds'} = $values;
331
        } else {
332
            $data->{'tagIds'} = null;
333
        }
334
        if (null !== $object->getTagNames()) {
335
            $values_1 = [];
336
            foreach ($object->getTagNames() as $value_1) {
337
                $values_1[] = $value_1;
338
            }
339
            $data->{'tagNames'} = $values_1;
340
        } else {
341
            $data->{'tagNames'} = null;
342
        }
343
        if (null !== $object->getVatRateId()) {
344
            $data->{'vatRateId'} = $object->getVatRateId();
345
        } else {
346
            $data->{'vatRateId'} = null;
347
        }
348
        if (null !== $object->getVatRatePercentage()) {
349
            $data->{'vatRatePercentage'} = $object->getVatRatePercentage();
350
        } else {
351
            $data->{'vatRatePercentage'} = null;
352
        }
353
354
        return $data;
355
    }
356
}
357