WorkLogHydrator::hydrate()   A
last analyzed

Complexity

Conditions 5
Paths 16

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 19
rs 9.6111
ccs 10
cts 10
cp 1
cc 5
nc 16
nop 2
crap 5
1
<?php
2
declare(strict_types=1);
3
4
namespace TogglJira\Hydrator;
5
6
use TogglJira\Entity\WorkLogEntry;
7
use Zend\Hydrator\HydratorInterface;
8
9
class WorkLogHydrator implements HydratorInterface
10
{
11
12
    /**
13
     * Extract values from an object
14
     *
15
     * @param  WorkLogEntry $object
16
     * @return array
17
     */
18 1
    public function extract($object)
19
    {
20
        return [
21 1
            'issueID' => $object->getIssueID(),
22 1
            'timeSpent' => $object->getTimeSpent(),
23 1
            'comment' => $object->getComment(),
24 1
            'spentOn' => $object->getSpentOn()
25
        ];
26
    }
27
28
    /**
29
     * Hydrate $object with the provided $data.
30
     *
31
     * @param  array $data
32
     * @param  WorkLogEntry $object
33
     * @return object
34
     * @throws \Exception
35
     */
36 1
    public function hydrate(array $data, $object): WorkLogEntry
37
    {
38 1
        if (isset($data['issueID'])) {
39 1
            $object->setIssueID($data['issueID']);
40
        }
41
42 1
        if (isset($data['timeSpent'])) {
43 1
            $object->setTimeSpent($data['timeSpent']);
44
        }
45
46 1
        if (isset($data['comment'])) {
47 1
            $object->setComment($data['comment']);
48
        }
49
50 1
        if (isset($data['spentOn'])) {
51 1
            $object->setSpentOn(new \DateTimeImmutable($data['spentOn']));
52
        }
53
54 1
        return $object;
55
    }
56
}
57