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

InvoiceRowNormalizer::denormalize()   F

Complexity

Conditions 38
Paths 19684

Size

Total Lines 53
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 1482

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 38
eloc 40
c 1
b 0
f 0
nc 19684
nop 4
dl 0
loc 53
ccs 0
cts 52
cp 0
crap 1482
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 InvoiceRowNormalizer 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\\InvoiceRow';
27
    }
28
29
    public function supportsNormalization($data, $format = null)
30
    {
31
        return is_object($data) && get_class($data) === 'ConnectHolland\\TimechimpBundle\\Api\\Model\\InvoiceRow';
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\InvoiceRow();
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, 'invoiceId') && $data->{'invoiceId'} !== null) {
46
            $object->setInvoiceId($data->{'invoiceId'});
47
        } elseif (property_exists($data, 'invoiceId') && $data->{'invoiceId'} === null) {
48
            $object->setInvoiceId(null);
49
        }
50
        if (property_exists($data, 'description') && $data->{'description'} !== null) {
51
            $object->setDescription($data->{'description'});
52
        } elseif (property_exists($data, 'description') && $data->{'description'} === null) {
53
            $object->setDescription(null);
54
        }
55
        if (property_exists($data, 'quantity') && $data->{'quantity'} !== null) {
56
            $object->setQuantity($data->{'quantity'});
57
        } elseif (property_exists($data, 'quantity') && $data->{'quantity'} === null) {
58
            $object->setQuantity(null);
59
        }
60
        if (property_exists($data, 'price') && $data->{'price'} !== null) {
61
            $object->setPrice($data->{'price'});
62
        } elseif (property_exists($data, 'price') && $data->{'price'} === null) {
63
            $object->setPrice(null);
64
        }
65
        if (property_exists($data, 'tax') && $data->{'tax'} !== null) {
66
            $object->setTax($data->{'tax'});
67
        } elseif (property_exists($data, 'tax') && $data->{'tax'} === null) {
68
            $object->setTax(null);
69
        }
70
        if (property_exists($data, 'total') && $data->{'total'} !== null) {
71
            $object->setTotal($data->{'total'});
72
        } elseif (property_exists($data, 'total') && $data->{'total'} === null) {
73
            $object->setTotal(null);
74
        }
75
        if (property_exists($data, 'index') && $data->{'index'} !== null) {
76
            $object->setIndex($data->{'index'});
77
        } elseif (property_exists($data, 'index') && $data->{'index'} === null) {
78
            $object->setIndex(null);
79
        }
80
        if (property_exists($data, 'code') && $data->{'code'} !== null) {
81
            $object->setCode($data->{'code'});
82
        } elseif (property_exists($data, 'code') && $data->{'code'} === null) {
83
            $object->setCode(null);
84
        }
85
86
        return $object;
87
    }
88
89
    public function normalize($object, $format = null, array $context = [])
90
    {
91
        $data = new \stdClass();
92
        if (null !== $object->getId()) {
93
            $data->{'id'} = $object->getId();
94
        } else {
95
            $data->{'id'} = null;
96
        }
97
        if (null !== $object->getInvoiceId()) {
98
            $data->{'invoiceId'} = $object->getInvoiceId();
99
        } else {
100
            $data->{'invoiceId'} = null;
101
        }
102
        if (null !== $object->getDescription()) {
103
            $data->{'description'} = $object->getDescription();
104
        } else {
105
            $data->{'description'} = null;
106
        }
107
        if (null !== $object->getQuantity()) {
108
            $data->{'quantity'} = $object->getQuantity();
109
        } else {
110
            $data->{'quantity'} = null;
111
        }
112
        if (null !== $object->getPrice()) {
113
            $data->{'price'} = $object->getPrice();
114
        } else {
115
            $data->{'price'} = null;
116
        }
117
        if (null !== $object->getTax()) {
118
            $data->{'tax'} = $object->getTax();
119
        } else {
120
            $data->{'tax'} = null;
121
        }
122
        if (null !== $object->getTotal()) {
123
            $data->{'total'} = $object->getTotal();
124
        } else {
125
            $data->{'total'} = null;
126
        }
127
        if (null !== $object->getIndex()) {
128
            $data->{'index'} = $object->getIndex();
129
        } else {
130
            $data->{'index'} = null;
131
        }
132
        if (null !== $object->getCode()) {
133
            $data->{'code'} = $object->getCode();
134
        } else {
135
            $data->{'code'} = null;
136
        }
137
138
        return $data;
139
    }
140
}
141