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

Customer   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 94
Duplicated Lines 55.32 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 72.41%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 3
dl 52
loc 94
ccs 21
cts 29
cp 0.7241
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A search() 13 13 3
A fetch() 13 13 3
A create() 13 13 3
A update() 13 13 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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