Passed
Push — master ( 248c35...f550ad )
by Reyo
04:07
created

ProjectInsightsNormalizer::denormalize()   F

Complexity

Conditions 14
Paths 4097

Size

Total Lines 44
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 210

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 28
c 1
b 0
f 0
dl 0
loc 44
ccs 0
cts 43
cp 0
rs 2.1
cc 14
nc 4097
nop 4
crap 210

How to fix   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\Client\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 ProjectInsightsNormalizer 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\\Client\\Model\\ProjectInsights';
28
    }
29
30
    public function supportsNormalization($data, $format = null)
31
    {
32
        return is_object($data) && get_class($data) === 'ConnectHolland\\TimechimpBundle\\Api\\Client\\Model\\ProjectInsights';
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\Client\Model\ProjectInsights();
41
        if (property_exists($data, 'totalHours')) {
42
            $object->setTotalHours($data->{'totalHours'});
43
        }
44
        if (property_exists($data, 'totalHoursBillable')) {
45
            $object->setTotalHoursBillable($data->{'totalHoursBillable'});
46
        }
47
        if (property_exists($data, 'totalHoursNonBillable')) {
48
            $object->setTotalHoursNonBillable($data->{'totalHoursNonBillable'});
49
        }
50
        if (property_exists($data, 'totalUninvoiced')) {
51
            $object->setTotalUninvoiced($data->{'totalUninvoiced'});
52
        }
53
        if (property_exists($data, 'totalInvoiced')) {
54
            $object->setTotalInvoiced($data->{'totalInvoiced'});
55
        }
56
        if (property_exists($data, 'totalWrittenOff')) {
57
            $object->setTotalWrittenOff($data->{'totalWrittenOff'});
58
        }
59
        if (property_exists($data, 'totalScheduled')) {
60
            $object->setTotalScheduled($data->{'totalScheduled'});
61
        }
62
        if (property_exists($data, 'budgetPercentage')) {
63
            $object->setBudgetPercentage($data->{'budgetPercentage'});
64
        }
65
        if (property_exists($data, 'budget')) {
66
            $object->setBudget($data->{'budget'});
67
        }
68
        if (property_exists($data, 'spend')) {
69
            $object->setSpend($data->{'spend'});
70
        }
71
        if (property_exists($data, 'remainingBudget')) {
72
            $object->setRemainingBudget($data->{'remainingBudget'});
73
        }
74
        if (property_exists($data, 'costs')) {
75
            $object->setCosts($data->{'costs'});
76
        }
77
78
        return $object;
79
    }
80
81
    public function normalize($object, $format = null, array $context = [])
82
    {
83
        $data = new \stdClass();
84
        if (null !== $object->getTotalHours()) {
85
            $data->{'totalHours'} = $object->getTotalHours();
86
        }
87
        if (null !== $object->getTotalHoursBillable()) {
88
            $data->{'totalHoursBillable'} = $object->getTotalHoursBillable();
89
        }
90
        if (null !== $object->getTotalHoursNonBillable()) {
91
            $data->{'totalHoursNonBillable'} = $object->getTotalHoursNonBillable();
92
        }
93
        if (null !== $object->getTotalUninvoiced()) {
94
            $data->{'totalUninvoiced'} = $object->getTotalUninvoiced();
95
        }
96
        if (null !== $object->getTotalInvoiced()) {
97
            $data->{'totalInvoiced'} = $object->getTotalInvoiced();
98
        }
99
        if (null !== $object->getTotalWrittenOff()) {
100
            $data->{'totalWrittenOff'} = $object->getTotalWrittenOff();
101
        }
102
        if (null !== $object->getTotalScheduled()) {
103
            $data->{'totalScheduled'} = $object->getTotalScheduled();
104
        }
105
        if (null !== $object->getBudgetPercentage()) {
106
            $data->{'budgetPercentage'} = $object->getBudgetPercentage();
107
        }
108
        if (null !== $object->getBudget()) {
109
            $data->{'budget'} = $object->getBudget();
110
        }
111
        if (null !== $object->getSpend()) {
112
            $data->{'spend'} = $object->getSpend();
113
        }
114
        if (null !== $object->getRemainingBudget()) {
115
            $data->{'remainingBudget'} = $object->getRemainingBudget();
116
        }
117
        if (null !== $object->getCosts()) {
118
            $data->{'costs'} = $object->getCosts();
119
        }
120
121
        return $data;
122
    }
123
}
124