Test Failed
Pull Request — master (#4)
by
unknown
01:25
created

InvoiceNinjaClient::getClients()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 12
loc 12
ccs 0
cts 11
cp 0
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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
use Syncer\Dto\InvoiceNinja\Client;
9
use Syncer\Dto\InvoiceNinja\Project;
10
11
/**
12
 * Class InvoiceNinjaClient
13
 * @package Syncer\InvoiceNinja
14
 *
15
 * @author Matthieu Calie <[email protected]>
16
 */
17
class InvoiceNinjaClient
18
{
19
    const VERSION = 'v1';
20
21
    /**
22
     * @var GuzzleClient
23
     */
24
    private $client;
25
26
    /**
27
     * @var SerializerInterface
28
     */
29
    private $serializer;
30
31
    /**
32
     * @var string
33
     */
34
    private $api_token;
35
36
    /**
37
     * Client constructor.
38
     *
39
     * @param GuzzleClient $client
40
     * @param SerializerInterface $serializer
41
     * @param $api_token
42
     */
43
    public function __construct(GuzzleClient $client, SerializerInterface $serializer, $api_token)
44
    {
45
        $this->client = $client;
46
        $this->serializer = $serializer;
47
        $this->api_token = $api_token;
48
    }
49
50
    /**
51
     * @param Task $task
52
     *
53
     * @return mixed
54
     */
55 View Code Duplication
    public function saveNewTask(Task $task)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
    {
57
        $data = $this->serializer->serialize($task, 'json');
58
59
        $res = $this->client->request('POST', self::VERSION . '/tasks', [
60
            'body' => $data,
61
            'headers' => [
62
                'Content-Type' => 'application/json',
63
                'X-Ninja-Token' => $this->api_token,
64
                'X-Requested-With' => 'XMLHttpRequest',
65
            ]
66
        ]);
67
68
        return $this->serializer->deserialize($res->getBody(), Task::class, 'json');
69
    }
70
71
    /**
72
     * @param Project $project
73
     *
74
     * @return mixed
75
     */
76 View Code Duplication
    public function saveNewProject(Project $project)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
77
    {
78
        $data = $this->serializer->serialize($project, 'json');
79
80
        $res = $this->client->request('POST', self::VERSION . '/projects', [
81
            'body' => $data,
82
            'headers' => [
83
                'Content-Type' => 'application/json',
84
                'X-Ninja-Token' => $this->api_token,
85
                'X-Requested-With' => 'XMLHttpRequest',
86
            ]
87
        ]);
88
89
        return $this->serializer->deserialize($res->getBody(), 'Syncer\Dto\InvoiceNinja\ProjectWrapper', 'json')->getData();
90
    }
91
92
    /**
93
     * @param Project $project
0 ignored issues
show
Bug introduced by
There is no parameter named $project. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
94
     *
95
     * @return mixed
96
     */
97 View Code Duplication
    public function saveNewClient(Client $client)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
98
    {
99
        $data = $this->serializer->serialize($client, 'json');
100
101
        $res = $this->client->request('POST', self::VERSION . '/clients', [
102
            'body' => $data,
103
            'headers' => [
104
                'Content-Type' => 'application/json',
105
                'X-Ninja-Token' => $this->api_token,
106
                'X-Requested-With' => 'XMLHttpRequest',
107
            ]
108
        ]);
109
110
        return $this->serializer->deserialize($res->getBody(), 'Syncer\Dto\InvoiceNinja\ClientWrapper', 'json')->getData();
111
    }
112
113
    /**
114
     * @return array|Project[]
115
     */
116 View Code Duplication
    public function getProjects()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
117
    {
118
        $response = $this->client->request('GET', self::VERSION . '/projects', [
119
            'headers' => [
120
                'Content-Type' => 'application/json',
121
                'X-Ninja-Token' => $this->api_token,
122
                'X-Requested-With' => 'XMLHttpRequest',
123
            ]
124
        ]);
125
126
        return $this->serializer->deserialize($response->getBody(), 'Syncer\Dto\InvoiceNinja\ProjectsWrapper', 'json')->getData();
127
    }
128
129
    /**
130
     * @return array|Client[]
131
     */
132 View Code Duplication
    public function getClients()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
133
    {
134
        $response = $this->client->request('GET', self::VERSION . '/clients', [
135
            'headers' => [
136
                'Content-Type' => 'application/json',
137
                'X-Ninja-Token' => $this->api_token,
138
                'X-Requested-With' => 'XMLHttpRequest',
139
            ]
140
        ]);
141
142
        return $this->serializer->deserialize($response->getBody(), 'Syncer\Dto\InvoiceNinja\ClientsWrapper', 'json')->getData();
143
    }
144
}
145