Passed
Push — master ( 17481c...d9f781 )
by Reyo
02:57
created

TaskNormalizer   A

Complexity

Total Complexity 22

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 43
dl 0
loc 78
ccs 0
cts 68
cp 0
rs 10
c 0
b 0
f 0
wmc 22

4 Methods

Rating   Name   Duplication   Size   Complexity  
A supportsDenormalization() 0 3 1
C normalize() 0 29 9
C denormalize() 0 32 10
A supportsNormalization() 0 3 2
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\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 TaskNormalizer 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\\Model\\Task';
28
    }
29
30
    public function supportsNormalization($data, $format = null)
31
    {
32
        return is_object($data) && get_class($data) === 'ConnectHolland\\TimechimpBundle\\Api\\Model\\Task';
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\Model\Task();
41
        if (property_exists($data, 'id')) {
42
            $object->setId($data->{'id'});
43
        }
44
        if (property_exists($data, 'active')) {
45
            $object->setActive($data->{'active'});
46
        }
47
        if (property_exists($data, 'name')) {
48
            $object->setName($data->{'name'});
49
        }
50
        if (property_exists($data, 'code')) {
51
            $object->setCode($data->{'code'});
52
        }
53
        if (property_exists($data, 'hourlyRate')) {
54
            $object->setHourlyRate($data->{'hourlyRate'});
55
        }
56
        if (property_exists($data, 'billable')) {
57
            $object->setBillable($data->{'billable'});
58
        }
59
        if (property_exists($data, 'common')) {
60
            $object->setCommon($data->{'common'});
61
        }
62
        if (property_exists($data, 'unspecified')) {
63
            $object->setUnspecified($data->{'unspecified'});
64
        }
65
66
        return $object;
67
    }
68
69
    public function normalize($object, $format = null, array $context = [])
70
    {
71
        $data = new \stdClass();
72
        if (null !== $object->getId()) {
73
            $data->{'id'} = $object->getId();
74
        }
75
        if (null !== $object->getActive()) {
76
            $data->{'active'} = $object->getActive();
77
        }
78
        if (null !== $object->getName()) {
79
            $data->{'name'} = $object->getName();
80
        }
81
        if (null !== $object->getCode()) {
82
            $data->{'code'} = $object->getCode();
83
        }
84
        if (null !== $object->getHourlyRate()) {
85
            $data->{'hourlyRate'} = $object->getHourlyRate();
86
        }
87
        if (null !== $object->getBillable()) {
88
            $data->{'billable'} = $object->getBillable();
89
        }
90
        if (null !== $object->getCommon()) {
91
            $data->{'common'} = $object->getCommon();
92
        }
93
        if (null !== $object->getUnspecified()) {
94
            $data->{'unspecified'} = $object->getUnspecified();
95
        }
96
97
        return $data;
98
    }
99
}
100