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

ProjectTaskNormalizer::denormalize()   F

Complexity

Conditions 30
Paths 2188

Size

Total Lines 43
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 930

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 30
eloc 32
c 1
b 0
f 0
nc 2188
nop 4
dl 0
loc 43
ccs 0
cts 42
cp 0
crap 930
rs 0

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\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 ProjectTaskNormalizer 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\\ProjectTask';
27
    }
28
29
    public function supportsNormalization($data, $format = null)
30
    {
31
        return is_object($data) && get_class($data) === 'ConnectHolland\\TimechimpBundle\\Api\\Model\\ProjectTask';
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\ProjectTask();
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, 'taskId') && $data->{'taskId'} !== null) {
46
            $object->setTaskId($data->{'taskId'});
47
        } elseif (property_exists($data, 'taskId') && $data->{'taskId'} === null) {
48
            $object->setTaskId(null);
49
        }
50
        if (property_exists($data, 'taskName') && $data->{'taskName'} !== null) {
51
            $object->setTaskName($data->{'taskName'});
52
        } elseif (property_exists($data, 'taskName') && $data->{'taskName'} === null) {
53
            $object->setTaskName(null);
54
        }
55
        if (property_exists($data, 'hourlyRate') && $data->{'hourlyRate'} !== null) {
56
            $object->setHourlyRate($data->{'hourlyRate'});
57
        } elseif (property_exists($data, 'hourlyRate') && $data->{'hourlyRate'} === null) {
58
            $object->setHourlyRate(null);
59
        }
60
        if (property_exists($data, 'billable') && $data->{'billable'} !== null) {
61
            $object->setBillable($data->{'billable'});
62
        } elseif (property_exists($data, 'billable') && $data->{'billable'} === null) {
63
            $object->setBillable(null);
64
        }
65
        if (property_exists($data, 'unspecified') && $data->{'unspecified'} !== null) {
66
            $object->setUnspecified($data->{'unspecified'});
67
        } elseif (property_exists($data, 'unspecified') && $data->{'unspecified'} === null) {
68
            $object->setUnspecified(null);
69
        }
70
        if (property_exists($data, 'budgetHours') && $data->{'budgetHours'} !== null) {
71
            $object->setBudgetHours($data->{'budgetHours'});
72
        } elseif (property_exists($data, 'budgetHours') && $data->{'budgetHours'} === null) {
73
            $object->setBudgetHours(null);
74
        }
75
76
        return $object;
77
    }
78
79
    public function normalize($object, $format = null, array $context = [])
80
    {
81
        $data = new \stdClass();
82
        if (null !== $object->getId()) {
83
            $data->{'id'} = $object->getId();
84
        } else {
85
            $data->{'id'} = null;
86
        }
87
        if (null !== $object->getTaskId()) {
88
            $data->{'taskId'} = $object->getTaskId();
89
        } else {
90
            $data->{'taskId'} = null;
91
        }
92
        if (null !== $object->getTaskName()) {
93
            $data->{'taskName'} = $object->getTaskName();
94
        } else {
95
            $data->{'taskName'} = null;
96
        }
97
        if (null !== $object->getHourlyRate()) {
98
            $data->{'hourlyRate'} = $object->getHourlyRate();
99
        } else {
100
            $data->{'hourlyRate'} = null;
101
        }
102
        if (null !== $object->getBillable()) {
103
            $data->{'billable'} = $object->getBillable();
104
        } else {
105
            $data->{'billable'} = null;
106
        }
107
        if (null !== $object->getUnspecified()) {
108
            $data->{'unspecified'} = $object->getUnspecified();
109
        } else {
110
            $data->{'unspecified'} = null;
111
        }
112
        if (null !== $object->getBudgetHours()) {
113
            $data->{'budgetHours'} = $object->getBudgetHours();
114
        } else {
115
            $data->{'budgetHours'} = null;
116
        }
117
118
        return $data;
119
    }
120
}
121