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

ProjectUserNormalizer::denormalize()   F

Complexity

Conditions 26
Paths 730

Size

Total Lines 38
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 702

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 26
eloc 28
c 1
b 0
f 0
nc 730
nop 4
dl 0
loc 38
ccs 0
cts 37
cp 0
crap 702
rs 0.375

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 ProjectUserNormalizer 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\\ProjectUser';
27
    }
28
29
    public function supportsNormalization($data, $format = null)
30
    {
31
        return is_object($data) && get_class($data) === 'ConnectHolland\\TimechimpBundle\\Api\\Model\\ProjectUser';
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\ProjectUser();
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, 'userId') && $data->{'userId'} !== null) {
46
            $object->setUserId($data->{'userId'});
47
        } elseif (property_exists($data, 'userId') && $data->{'userId'} === null) {
48
            $object->setUserId(null);
49
        }
50
        if (property_exists($data, 'userDisplayName') && $data->{'userDisplayName'} !== null) {
51
            $object->setUserDisplayName($data->{'userDisplayName'});
52
        } elseif (property_exists($data, 'userDisplayName') && $data->{'userDisplayName'} === null) {
53
            $object->setUserDisplayName(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, 'budgetHours') && $data->{'budgetHours'} !== null) {
61
            $object->setBudgetHours($data->{'budgetHours'});
62
        } elseif (property_exists($data, 'budgetHours') && $data->{'budgetHours'} === null) {
63
            $object->setBudgetHours(null);
64
        }
65
        if (property_exists($data, 'projectManager') && $data->{'projectManager'} !== null) {
66
            $object->setProjectManager($data->{'projectManager'});
67
        } elseif (property_exists($data, 'projectManager') && $data->{'projectManager'} === null) {
68
            $object->setProjectManager(null);
69
        }
70
71
        return $object;
72
    }
73
74
    public function normalize($object, $format = null, array $context = [])
75
    {
76
        $data = new \stdClass();
77
        if (null !== $object->getId()) {
78
            $data->{'id'} = $object->getId();
79
        } else {
80
            $data->{'id'} = null;
81
        }
82
        if (null !== $object->getUserId()) {
83
            $data->{'userId'} = $object->getUserId();
84
        } else {
85
            $data->{'userId'} = null;
86
        }
87
        if (null !== $object->getUserDisplayName()) {
88
            $data->{'userDisplayName'} = $object->getUserDisplayName();
89
        } else {
90
            $data->{'userDisplayName'} = null;
91
        }
92
        if (null !== $object->getHourlyRate()) {
93
            $data->{'hourlyRate'} = $object->getHourlyRate();
94
        } else {
95
            $data->{'hourlyRate'} = null;
96
        }
97
        if (null !== $object->getBudgetHours()) {
98
            $data->{'budgetHours'} = $object->getBudgetHours();
99
        } else {
100
            $data->{'budgetHours'} = null;
101
        }
102
        if (null !== $object->getProjectManager()) {
103
            $data->{'projectManager'} = $object->getProjectManager();
104
        } else {
105
            $data->{'projectManager'} = null;
106
        }
107
108
        return $data;
109
    }
110
}
111