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

ProjectTaskNormalizer::denormalize()   B

Complexity

Conditions 9
Paths 129

Size

Total Lines 29
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 90

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 29
ccs 0
cts 28
cp 0
rs 7.8138
cc 9
nc 129
nop 4
crap 90
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 ProjectTaskNormalizer 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\\ProjectTask';
28
    }
29
30
    public function supportsNormalization($data, $format = null)
31
    {
32
        return is_object($data) && get_class($data) === 'ConnectHolland\\TimechimpBundle\\Api\\Client\\Model\\ProjectTask';
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\ProjectTask();
41
        if (property_exists($data, 'id')) {
42
            $object->setId($data->{'id'});
43
        }
44
        if (property_exists($data, 'taskId')) {
45
            $object->setTaskId($data->{'taskId'});
46
        }
47
        if (property_exists($data, 'taskName')) {
48
            $object->setTaskName($data->{'taskName'});
49
        }
50
        if (property_exists($data, 'hourlyRate')) {
51
            $object->setHourlyRate($data->{'hourlyRate'});
52
        }
53
        if (property_exists($data, 'billable')) {
54
            $object->setBillable($data->{'billable'});
55
        }
56
        if (property_exists($data, 'unspecified')) {
57
            $object->setUnspecified($data->{'unspecified'});
58
        }
59
        if (property_exists($data, 'budgetHours')) {
60
            $object->setBudgetHours($data->{'budgetHours'});
61
        }
62
63
        return $object;
64
    }
65
66
    public function normalize($object, $format = null, array $context = [])
67
    {
68
        $data = new \stdClass();
69
        if (null !== $object->getId()) {
70
            $data->{'id'} = $object->getId();
71
        }
72
        if (null !== $object->getTaskId()) {
73
            $data->{'taskId'} = $object->getTaskId();
74
        }
75
        if (null !== $object->getTaskName()) {
76
            $data->{'taskName'} = $object->getTaskName();
77
        }
78
        if (null !== $object->getHourlyRate()) {
79
            $data->{'hourlyRate'} = $object->getHourlyRate();
80
        }
81
        if (null !== $object->getBillable()) {
82
            $data->{'billable'} = $object->getBillable();
83
        }
84
        if (null !== $object->getUnspecified()) {
85
            $data->{'unspecified'} = $object->getUnspecified();
86
        }
87
        if (null !== $object->getBudgetHours()) {
88
            $data->{'budgetHours'} = $object->getBudgetHours();
89
        }
90
91
        return $data;
92
    }
93
}
94