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