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 UserNormalizer 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\\User'; |
||||
28 | } |
||||
29 | |||||
30 | public function supportsNormalization($data, $format = null) |
||||
31 | { |
||||
32 | return is_object($data) && get_class($data) === 'ConnectHolland\\TimechimpBundle\\Api\\Client\\Model\\User'; |
||||
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\User(); |
||||
41 | if (property_exists($data, 'id')) { |
||||
42 | $object->setId($data->{'id'}); |
||||
43 | } |
||||
44 | if (property_exists($data, 'userName')) { |
||||
45 | $object->setUserName($data->{'userName'}); |
||||
46 | } |
||||
47 | if (property_exists($data, 'displayName')) { |
||||
48 | $object->setDisplayName($data->{'displayName'}); |
||||
49 | } |
||||
50 | if (property_exists($data, 'accountType')) { |
||||
51 | $object->setAccountType($data->{'accountType'}); |
||||
52 | } |
||||
53 | if (property_exists($data, 'isLocked')) { |
||||
54 | $object->setIsLocked($data->{'isLocked'}); |
||||
55 | } |
||||
56 | if (property_exists($data, 'picture')) { |
||||
57 | $object->setPicture($data->{'picture'}); |
||||
58 | } |
||||
59 | if (property_exists($data, 'tagNames')) { |
||||
60 | $values = []; |
||||
61 | foreach ($data->{'tagNames'} as $value) { |
||||
62 | $values[] = $value; |
||||
63 | } |
||||
64 | $object->setTagNames($values); |
||||
65 | } |
||||
66 | if (property_exists($data, 'language')) { |
||||
67 | $object->setLanguage($data->{'language'}); |
||||
68 | } |
||||
69 | if (property_exists($data, 'contractHours')) { |
||||
70 | $object->setContractHours($data->{'contractHours'}); |
||||
71 | } |
||||
72 | if (property_exists($data, 'contractHourlyRate')) { |
||||
73 | $object->setContractHourlyRate($data->{'contractHourlyRate'}); |
||||
74 | } |
||||
75 | if (property_exists($data, 'contractCostHourlyRate')) { |
||||
76 | $object->setContractCostHourlyRate($data->{'contractCostHourlyRate'}); |
||||
77 | } |
||||
78 | if (property_exists($data, 'contractStartDate')) { |
||||
79 | $object->setContractStartDate(\DateTime::createFromFormat('Y-m-d\\TH:i:sP', $data->{'contractStartDate'})); |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
80 | } |
||||
81 | if (property_exists($data, 'contractEndDate')) { |
||||
82 | $object->setContractEndDate(\DateTime::createFromFormat('Y-m-d\\TH:i:sP', $data->{'contractEndDate'})); |
||||
0 ignored issues
–
show
It seems like
DateTime::createFromForm...ata->'contractEndDate') can also be of type false ; however, parameter $contractEndDate of ConnectHolland\Timechimp...r::setContractEndDate() does only seem to accept DateTime , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
83 | } |
||||
84 | if (property_exists($data, 'created')) { |
||||
85 | $object->setCreated(\DateTime::createFromFormat('Y-m-d\\TH:i:sP', $data->{'created'})); |
||||
0 ignored issues
–
show
It seems like
DateTime::createFromForm...:sP', $data->'created') can also be of type false ; however, parameter $created of ConnectHolland\Timechimp...odel\User::setCreated() does only seem to accept DateTime , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
86 | } |
||||
87 | if (property_exists($data, 'teamName')) { |
||||
88 | $object->setTeamName($data->{'teamName'}); |
||||
89 | } |
||||
90 | if (property_exists($data, 'employeeNumber')) { |
||||
91 | $object->setEmployeeNumber($data->{'employeeNumber'}); |
||||
92 | } |
||||
93 | |||||
94 | return $object; |
||||
95 | } |
||||
96 | |||||
97 | public function normalize($object, $format = null, array $context = []) |
||||
98 | { |
||||
99 | $data = new \stdClass(); |
||||
100 | if (null !== $object->getId()) { |
||||
101 | $data->{'id'} = $object->getId(); |
||||
102 | } |
||||
103 | if (null !== $object->getUserName()) { |
||||
104 | $data->{'userName'} = $object->getUserName(); |
||||
105 | } |
||||
106 | if (null !== $object->getDisplayName()) { |
||||
107 | $data->{'displayName'} = $object->getDisplayName(); |
||||
108 | } |
||||
109 | if (null !== $object->getAccountType()) { |
||||
110 | $data->{'accountType'} = $object->getAccountType(); |
||||
111 | } |
||||
112 | if (null !== $object->getIsLocked()) { |
||||
113 | $data->{'isLocked'} = $object->getIsLocked(); |
||||
114 | } |
||||
115 | if (null !== $object->getPicture()) { |
||||
116 | $data->{'picture'} = $object->getPicture(); |
||||
117 | } |
||||
118 | if (null !== $object->getTagNames()) { |
||||
119 | $values = []; |
||||
120 | foreach ($object->getTagNames() as $value) { |
||||
121 | $values[] = $value; |
||||
122 | } |
||||
123 | $data->{'tagNames'} = $values; |
||||
124 | } |
||||
125 | if (null !== $object->getLanguage()) { |
||||
126 | $data->{'language'} = $object->getLanguage(); |
||||
127 | } |
||||
128 | if (null !== $object->getContractHours()) { |
||||
129 | $data->{'contractHours'} = $object->getContractHours(); |
||||
130 | } |
||||
131 | if (null !== $object->getContractHourlyRate()) { |
||||
132 | $data->{'contractHourlyRate'} = $object->getContractHourlyRate(); |
||||
133 | } |
||||
134 | if (null !== $object->getContractCostHourlyRate()) { |
||||
135 | $data->{'contractCostHourlyRate'} = $object->getContractCostHourlyRate(); |
||||
136 | } |
||||
137 | if (null !== $object->getContractStartDate()) { |
||||
138 | $data->{'contractStartDate'} = $object->getContractStartDate()->format('Y-m-d\\TH:i:sP'); |
||||
139 | } |
||||
140 | if (null !== $object->getContractEndDate()) { |
||||
141 | $data->{'contractEndDate'} = $object->getContractEndDate()->format('Y-m-d\\TH:i:sP'); |
||||
142 | } |
||||
143 | if (null !== $object->getCreated()) { |
||||
144 | $data->{'created'} = $object->getCreated()->format('Y-m-d\\TH:i:sP'); |
||||
145 | } |
||||
146 | if (null !== $object->getTeamName()) { |
||||
147 | $data->{'teamName'} = $object->getTeamName(); |
||||
148 | } |
||||
149 | if (null !== $object->getEmployeeNumber()) { |
||||
150 | $data->{'employeeNumber'} = $object->getEmployeeNumber(); |
||||
151 | } |
||||
152 | |||||
153 | return $data; |
||||
154 | } |
||||
155 | } |
||||
156 |