1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Billogram\Api; |
6
|
|
|
|
7
|
|
|
use Billogram\Exception\Domain\ValidationException; |
8
|
|
|
use Billogram\Model\Invoice\Invoice as Model; |
9
|
|
|
use Billogram\Model\Invoice\InvoiceCollection; |
10
|
|
|
use Psr\Http\Message\ResponseInterface; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @author Ibrahim Hizeoui <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
class Invoice extends HttpApi |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @param array $param |
19
|
|
|
* |
20
|
|
|
* @return InvoiceCollection|ResponseInterface |
21
|
|
|
* |
22
|
|
|
* @see https://billogram.com/api/documentation#billogram_call_create |
23
|
|
|
*/ |
24
|
1 |
View Code Duplication |
public function search(array $param = []) |
|
|
|
|
25
|
|
|
{ |
26
|
1 |
|
$param = array_merge(['page' => 1, 'page_size' => 100], $param); |
27
|
1 |
|
$response = $this->httpGet('/billogram', $param); |
28
|
1 |
|
if (!$this->hydrator) { |
29
|
|
|
return $response; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
// Use any valid status code here |
33
|
1 |
|
if ($response->getStatusCode() !== 200) { |
34
|
|
|
$this->handleErrors($response); |
35
|
|
|
} |
36
|
|
|
|
37
|
1 |
|
return $this->hydrator->hydrate($response, InvoiceCollection::class); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param string $invoiceId |
42
|
|
|
* |
43
|
|
|
* @return Model|ResponseInterface |
44
|
|
|
* |
45
|
|
|
* @see https://billogram.com/api/documentation#billogram_call_create |
46
|
|
|
*/ |
47
|
2 |
View Code Duplication |
public function fetch(string $invoiceId) |
|
|
|
|
48
|
|
|
{ |
49
|
2 |
|
$response = $this->httpGet('/billogram/'.$invoiceId); |
50
|
2 |
|
if (!$this->hydrator) { |
51
|
|
|
return $response; |
52
|
|
|
} |
53
|
|
|
// Use any valid status code here |
54
|
2 |
|
if ($response->getStatusCode() !== 200) { |
55
|
|
|
$this->handleErrors($response); |
56
|
|
|
} |
57
|
|
|
|
58
|
2 |
|
return $this->hydrator->hydrate($response, Model::class); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param array $invoice |
63
|
|
|
* |
64
|
|
|
* @return Model|ResponseInterface |
65
|
|
|
* |
66
|
|
|
* @see https://billogram.com/api/documentation#billogram_call_create |
67
|
|
|
* |
68
|
|
|
* @throws ValidationException |
69
|
|
|
*/ |
70
|
1 |
View Code Duplication |
public function create(array $invoice) |
|
|
|
|
71
|
|
|
{ |
72
|
1 |
|
$response = $this->httpPost('/billogram', $invoice); |
73
|
1 |
|
if (!$this->hydrator) { |
74
|
|
|
return $response; |
75
|
|
|
} |
76
|
|
|
// Use any valid status code here |
77
|
1 |
|
if ($response->getStatusCode() !== 200) { |
78
|
|
|
$this->handleErrors($response); |
79
|
|
|
} |
80
|
|
|
|
81
|
1 |
|
return $this->hydrator->hydrate($response, Model::class); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param string $invoiceId |
86
|
|
|
* @param array $invoice |
87
|
|
|
* |
88
|
|
|
* @return Model|ResponseInterface |
89
|
|
|
* |
90
|
|
|
* @see https://billogram.com/api/documentation#billogram_call_create |
91
|
|
|
* |
92
|
|
|
* @throws ValidationException |
93
|
|
|
*/ |
94
|
1 |
View Code Duplication |
public function update(string $invoiceId, array $invoice) |
|
|
|
|
95
|
|
|
{ |
96
|
1 |
|
$response = $this->httpPut('/billogram/'.$invoiceId, $invoice); |
97
|
1 |
|
if (!$this->hydrator) { |
98
|
|
|
return $response; |
99
|
|
|
} |
100
|
|
|
// Use any valid status code here |
101
|
1 |
|
if ($response->getStatusCode() !== 200) { |
102
|
|
|
$this->handleErrors($response); |
103
|
|
|
} |
104
|
|
|
|
105
|
1 |
|
return $this->hydrator->hydrate($response, Model::class); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
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.