Completed
Push — master ( e95f12...168b8f )
by Tobias
01:40
created

Customer::search()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 8

Duplication

Lines 13
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 3.1406

Importance

Changes 0
Metric Value
dl 13
loc 13
ccs 6
cts 8
cp 0.75
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 3
nop 1
crap 3.1406
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
class Customer extends HttpApi
17
{
18
    /**
19
     * @param array $param
20
     *
21
     * @return CustomerCollection|ResponseInterface
22
     *
23
     * @see https://billogram.com/api/documentation#customers_list
24
     */
25 1 View Code Duplication
    public function search(array $param = [])
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...
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
     *
42
     * @return Model|ResponseInterface
43
     *
44
     * @throws NotFoundException
45
     *
46
     * @see https://billogram.com/api/documentation#customers_fetch
47
     */
48 2 View Code Duplication
    public function fetch(int $customerNo)
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...
49
    {
50 2
        $response = $this->httpGet('/customer/'.$customerNo);
51 2
        if (!$this->hydrator) {
52
            return $response;
53
        }
54
        // Use any valid status code here
55 2
        if ($response->getStatusCode() !== 200) {
56
            $this->handleErrors($response);
57
        }
58
59 2
        return $this->hydrator->hydrate($response, Model::class);
60
    }
61
62
    /**
63
     * @param array $customer
64
     *
65
     * @return Model|ResponseInterface
66
     *
67
     * @throws ValidationException
68
     *
69
     * @see https://billogram.com/api/documentation#customers_create
70
     */
71 1 View Code Duplication
    public function create(array $customer)
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...
72
    {
73 1
        $response = $this->httpPost('/customer', $customer);
74 1
        if (!$this->hydrator) {
75
            return $response;
76
        }
77
        // Use any valid status code here
78 1
        if ($response->getStatusCode() !== 200) {
79
            $this->handleErrors($response);
80
        }
81
82 1
        return $this->hydrator->hydrate($response, Model::class);
83
    }
84
85
    /**
86
     * @param int   $customerNo
87
     * @param array $customer
88
     *
89
     * @return Model|ResponseInterface
90
     *
91
     * @throws NotFoundException
92
     * @throws ValidationException
93
     *
94
     * @see https://billogram.com/api/documentation#customers_edit
95
     */
96 1 View Code Duplication
    public function update(int $customerNo, array $customer)
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...
97
    {
98 1
        $response = $this->httpPut('/customer/'.$customerNo, $customer);
99 1
        if (!$this->hydrator) {
100
            return $response;
101
        }
102
        // Use any valid status code here
103 1
        if ($response->getStatusCode() !== 200) {
104
            $this->handleErrors($response);
105
        }
106
107 1
        return $this->hydrator->hydrate($response, Model::class);
108
    }
109
}
110