ReportsClient::getDetailedReport()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 1
crap 1
1
<?php declare(strict_types=1);
2
3
namespace Syncer\Toggl;
4
5
use Carbon\Carbon;
6
use GuzzleHttp\Client;
7
use JMS\Serializer\SerializerInterface;
8
use Syncer\Dto\Toggl\DetailedReport;
9
10
/**
11
 * Class ReportsClient
12
 * @package Syncer\Toggl
13
 *
14
 * @author Matthieu Calie <[email protected]>
15
 */
16
class ReportsClient
17
{
18
    const VERSION = 'v2';
19
20
    /**
21
     * @var Client;
22
     */
23
    private $client;
24
25
    /**
26
     * @var SerializerInterface
27
     */
28
    private $serializer;
29
30
    /**
31
     * @var string
32
     */
33
    private $api_key;
34
35
    /**
36
     * TogglClient constructor.
37
     * @param Client $client
38
     * @param SerializerInterface $serializer
39
     * @param $api_key
40
     */
41 2
    public function __construct(Client $client, SerializerInterface $serializer, $api_key)
42
    {
43 2
        $this->client = $client;
44 2
        $this->serializer = $serializer;
45 2
        $this->api_key = $api_key;
46 2
    }
47
48
    /**
49
     * Get detailed report from since yesterday
50
     *
51
     * @param int $workspaceId
52
     * @return array|\JMS\Serializer\scalar|object|DetailedReport
53
     */
54 1
    public function getDetailedReport(int $workspaceId)
55
    {
56 1
        $res = $this->client->request('GET', self::VERSION . '/details', [
57 1
            'auth' => [$this->api_key, 'api_token'],
58
            'query' => [
59 1
                'user_agent' => '[email protected]',
60 1
                'workspace_id' => $workspaceId,
61 1
                'since' => Carbon::yesterday()->format('Y-m-d')
62
            ]
63
        ]);
64
65 1
        return $this->serializer->deserialize($res->getBody(), DetailedReport::class, 'json');
66
    }
67
}
68