Client   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 54
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A saveNewTask() 0 15 1
1
<?php declare(strict_types=1);
2
3
namespace Syncer\InvoiceNinja;
4
5
use GuzzleHttp\Client as GuzzleClient;
6
use JMS\Serializer\SerializerInterface;
7
use Syncer\Dto\InvoiceNinja\Task;
8
9
/**
10
 * Class Client
11
 * @package Syncer\InvoiceNinja
12
 *
13
 * @author Matthieu Calie <[email protected]>
14
 */
15
class Client
16
{
17
    const VERSION = 'v1';
18
19
    /**
20
     * @var GuzzleClient
21
     */
22
    private $client;
23
24
    /**
25
     * @var SerializerInterface
26
     */
27
    private $serializer;
28
29
    /**
30
     * @var string
31
     */
32
    private $api_token;
33
34
    /**
35
     * Client constructor.
36
     *
37
     * @param GuzzleClient $client
38
     * @param SerializerInterface $serializer
39
     * @param $api_token
40
     */
41 2
    public function __construct(GuzzleClient $client, SerializerInterface $serializer, $api_token)
42
    {
43 2
        $this->client = $client;
44 2
        $this->serializer = $serializer;
45 2
        $this->api_token = $api_token;
46 2
    }
47
48
    /**
49
     * @param Task $task
50
     *
51
     * @return mixed
52
     */
53 1
    public function saveNewTask(Task $task)
54
    {
55 1
        $data = $this->serializer->serialize($task, 'json');
56
57 1
        $res = $this->client->request('POST', self::VERSION . '/tasks', [
58 1
            'body' => $data,
59
            'headers' => [
60 1
                'Content-Type' => 'application/json',
61 1
                'X-Ninja-Token' => $this->api_token,
62 1
                'X-Requested-With' => 'XMLHttpRequest',
63
            ]
64
        ]);
65
66 1
        return $this->serializer->deserialize($res->getBody(), Task::class, 'json');
67
    }
68
}
69