Passed
Push — master ( 17481c...d9f781 )
by Reyo
02:57
created

CustomerNormalizer::denormalize()   F

Complexity

Conditions 33
Paths > 20000

Size

Total Lines 103
Code Lines 68

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 1122

Importance

Changes 0
Metric Value
cc 33
eloc 68
nc 536870913
nop 4
dl 0
loc 103
ccs 0
cts 102
cp 0
crap 1122
rs 0
c 0
b 0
f 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\Exception\InvalidArgumentException;
13
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface;
14
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait;
15
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
16
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
17
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
18
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
19
20
class CustomerNormalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface
21
{
22
    use DenormalizerAwareTrait;
23
    use NormalizerAwareTrait;
24
25
    public function supportsDenormalization($data, $type, $format = null)
26
    {
27
        return $type === 'ConnectHolland\\TimechimpBundle\\Api\\Model\\Customer';
28
    }
29
30
    public function supportsNormalization($data, $format = null)
31
    {
32
        return is_object($data) && get_class($data) === 'ConnectHolland\\TimechimpBundle\\Api\\Model\\Customer';
33
    }
34
35
    public function denormalize($data, $class, $format = null, array $context = [])
36
    {
37
        if (!is_object($data)) {
38
            throw new InvalidArgumentException(sprintf('Given $data is not an object (%s given). We need an object in order to continue denormalize method.', gettype($data)));
39
        }
40
        $object = new \ConnectHolland\TimechimpBundle\Api\Model\Customer();
41
        if (property_exists($data, 'id')) {
42
            $object->setId($data->{'id'});
43
        }
44
        if (property_exists($data, 'active')) {
45
            $object->setActive($data->{'active'});
46
        }
47
        if (property_exists($data, 'relationId')) {
48
            $object->setRelationId($data->{'relationId'});
49
        }
50
        if (property_exists($data, 'name')) {
51
            $object->setName($data->{'name'});
52
        }
53
        if (property_exists($data, 'address')) {
54
            $object->setAddress($data->{'address'});
55
        }
56
        if (property_exists($data, 'postalCode')) {
57
            $object->setPostalCode($data->{'postalCode'});
58
        }
59
        if (property_exists($data, 'city')) {
60
            $object->setCity($data->{'city'});
61
        }
62
        if (property_exists($data, 'country')) {
63
            $object->setCountry($data->{'country'});
64
        }
65
        if (property_exists($data, 'phone')) {
66
            $object->setPhone($data->{'phone'});
67
        }
68
        if (property_exists($data, 'email')) {
69
            $object->setEmail($data->{'email'});
70
        }
71
        if (property_exists($data, 'website')) {
72
            $object->setWebsite($data->{'website'});
73
        }
74
        if (property_exists($data, 'paymentPeriod')) {
75
            $object->setPaymentPeriod($data->{'paymentPeriod'});
76
        }
77
        if (property_exists($data, 'tax')) {
78
            $object->setTax($data->{'tax'});
79
        }
80
        if (property_exists($data, 'hourlyRate')) {
81
            $object->setHourlyRate($data->{'hourlyRate'});
82
        }
83
        if (property_exists($data, 'mileageRate')) {
84
            $object->setMileageRate($data->{'mileageRate'});
85
        }
86
        if (property_exists($data, 'iban')) {
87
            $object->setIban($data->{'iban'});
88
        }
89
        if (property_exists($data, 'bic')) {
90
            $object->setBic($data->{'bic'});
91
        }
92
        if (property_exists($data, 'vatNumber')) {
93
            $object->setVatNumber($data->{'vatNumber'});
94
        }
95
        if (property_exists($data, 'kvkNumber')) {
96
            $object->setKvkNumber($data->{'kvkNumber'});
97
        }
98
        if (property_exists($data, 'invoiceAddress')) {
99
            $object->setInvoiceAddress($data->{'invoiceAddress'});
100
        }
101
        if (property_exists($data, 'invoicePostalCode')) {
102
            $object->setInvoicePostalCode($data->{'invoicePostalCode'});
103
        }
104
        if (property_exists($data, 'invoiceCity')) {
105
            $object->setInvoiceCity($data->{'invoiceCity'});
106
        }
107
        if (property_exists($data, 'invoiceCountry')) {
108
            $object->setInvoiceCountry($data->{'invoiceCountry'});
109
        }
110
        if (property_exists($data, 'notes')) {
111
            $object->setNotes($data->{'notes'});
112
        }
113
        if (property_exists($data, 'clientId')) {
114
            $object->setClientId($data->{'clientId'});
115
        }
116
        if (property_exists($data, 'tagIds')) {
117
            $values = [];
118
            foreach ($data->{'tagIds'} as $value) {
119
                $values[] = $value;
120
            }
121
            $object->setTagIds($values);
122
        }
123
        if (property_exists($data, 'tagNames')) {
124
            $values_1 = [];
125
            foreach ($data->{'tagNames'} as $value_1) {
126
                $values_1[] = $value_1;
127
            }
128
            $object->setTagNames($values_1);
129
        }
130
        if (property_exists($data, 'vatRateId')) {
131
            $object->setVatRateId($data->{'vatRateId'});
132
        }
133
        if (property_exists($data, 'vatRatePercentage')) {
134
            $object->setVatRatePercentage($data->{'vatRatePercentage'});
135
        }
136
137
        return $object;
138
    }
139
140
    public function normalize($object, $format = null, array $context = [])
141
    {
142
        $data = new \stdClass();
143
        if (null !== $object->getId()) {
144
            $data->{'id'} = $object->getId();
145
        }
146
        if (null !== $object->getActive()) {
147
            $data->{'active'} = $object->getActive();
148
        }
149
        if (null !== $object->getRelationId()) {
150
            $data->{'relationId'} = $object->getRelationId();
151
        }
152
        if (null !== $object->getName()) {
153
            $data->{'name'} = $object->getName();
154
        }
155
        if (null !== $object->getAddress()) {
156
            $data->{'address'} = $object->getAddress();
157
        }
158
        if (null !== $object->getPostalCode()) {
159
            $data->{'postalCode'} = $object->getPostalCode();
160
        }
161
        if (null !== $object->getCity()) {
162
            $data->{'city'} = $object->getCity();
163
        }
164
        if (null !== $object->getCountry()) {
165
            $data->{'country'} = $object->getCountry();
166
        }
167
        if (null !== $object->getPhone()) {
168
            $data->{'phone'} = $object->getPhone();
169
        }
170
        if (null !== $object->getEmail()) {
171
            $data->{'email'} = $object->getEmail();
172
        }
173
        if (null !== $object->getWebsite()) {
174
            $data->{'website'} = $object->getWebsite();
175
        }
176
        if (null !== $object->getPaymentPeriod()) {
177
            $data->{'paymentPeriod'} = $object->getPaymentPeriod();
178
        }
179
        if (null !== $object->getTax()) {
180
            $data->{'tax'} = $object->getTax();
181
        }
182
        if (null !== $object->getHourlyRate()) {
183
            $data->{'hourlyRate'} = $object->getHourlyRate();
184
        }
185
        if (null !== $object->getMileageRate()) {
186
            $data->{'mileageRate'} = $object->getMileageRate();
187
        }
188
        if (null !== $object->getIban()) {
189
            $data->{'iban'} = $object->getIban();
190
        }
191
        if (null !== $object->getBic()) {
192
            $data->{'bic'} = $object->getBic();
193
        }
194
        if (null !== $object->getVatNumber()) {
195
            $data->{'vatNumber'} = $object->getVatNumber();
196
        }
197
        if (null !== $object->getKvkNumber()) {
198
            $data->{'kvkNumber'} = $object->getKvkNumber();
199
        }
200
        if (null !== $object->getInvoiceAddress()) {
201
            $data->{'invoiceAddress'} = $object->getInvoiceAddress();
202
        }
203
        if (null !== $object->getInvoicePostalCode()) {
204
            $data->{'invoicePostalCode'} = $object->getInvoicePostalCode();
205
        }
206
        if (null !== $object->getInvoiceCity()) {
207
            $data->{'invoiceCity'} = $object->getInvoiceCity();
208
        }
209
        if (null !== $object->getInvoiceCountry()) {
210
            $data->{'invoiceCountry'} = $object->getInvoiceCountry();
211
        }
212
        if (null !== $object->getNotes()) {
213
            $data->{'notes'} = $object->getNotes();
214
        }
215
        if (null !== $object->getClientId()) {
216
            $data->{'clientId'} = $object->getClientId();
217
        }
218
        if (null !== $object->getTagIds()) {
219
            $values = [];
220
            foreach ($object->getTagIds() as $value) {
221
                $values[] = $value;
222
            }
223
            $data->{'tagIds'} = $values;
224
        }
225
        if (null !== $object->getTagNames()) {
226
            $values_1 = [];
227
            foreach ($object->getTagNames() as $value_1) {
228
                $values_1[] = $value_1;
229
            }
230
            $data->{'tagNames'} = $values_1;
231
        }
232
        if (null !== $object->getVatRateId()) {
233
            $data->{'vatRateId'} = $object->getVatRateId();
234
        }
235
        if (null !== $object->getVatRatePercentage()) {
236
            $data->{'vatRatePercentage'} = $object->getVatRatePercentage();
237
        }
238
239
        return $data;
240
    }
241
}
242