Passed
Pull Request — master (#1)
by Jérémy
02:11
created

TimeEntry::entry()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 13
rs 9.6111
cc 5
nc 3
nop 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace JDecool\Clockify\Api\TimeEntry;
6
7
use JDecool\Clockify\{
8
    Client,
9
    Exception\ClockifyException,
10
    Model\TimeEntryDtoImpl
11
};
12
13
class TimeEntry
14
{
15
    private $http;
16
17
    public function __construct(Client $http)
18
    {
19
        $this->http = $http;
20
    }
21
22
    public function create(string $workspaceId, TimeEntryRequest $request): TimeEntryDtoImpl
23
    {
24
        $data = $this->http->post(" /workspaces/$workspaceId/time-entries", $request->toArray());
25
26
        return TimeEntryDtoImpl::fromArray($data);
27
    }
28
29
    public function entry(string $workspaceId, string $id, array $params = []): TimeEntryDtoImpl
30
    {
31
        if (isset($params['consider-duration-format']) && !is_bool($params['consider-duration-format'])) {
32
            throw new ClockifyException('Invalid "consider-duration-format" parameter (should be a boolean value)');
33
        }
34
35
        if (isset($params['hydrated']) && !is_bool($params['hydrated'])) {
36
            throw new ClockifyException('Invalid "hydrated" parameter (should be a boolean value)');
37
        }
38
39
        $data = $this->http->get("/workspaces/$workspaceId/time-entries/$id", $params);
40
41
        return TimeEntryDtoImpl::fromArray($data);
42
    }
43
}
44