Completed
Push — master ( f2b799...761b51 )
by Tobias
04:02
created

Customer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 67
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 67
loc 67
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A search() 7 7 1
A fetch() 6 6 1
A create() 6 6 1
A update() 6 6 1

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 View Code Duplication
class Customer extends HttpApi
0 ignored issues
show
Duplication introduced by
This class 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...
17
{
18
    /**
19
     * @param array $param
20
     *
21
     * @return CustomerCollection|ResponseInterface
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
30 1
        return $this->handleResponse($response, CustomerCollection::class);
31
    }
32
33
    /**
34
     * @param int $customerNo
35
     *
36
     * @return Model|ResponseInterface
37
     *
38
     * @throws NotFoundException
39
     *
40
     * @see https://billogram.com/api/documentation#customers_fetch
41
     */
42 1
    public function fetch(int $customerNo)
43
    {
44 1
        $response = $this->httpGet('/customer/'.$customerNo);
45
46 1
        return $this->handleResponse($response, Model::class);
47
    }
48
49
    /**
50
     * @param array $customer
51
     *
52
     * @return Model|ResponseInterface
53
     *
54
     * @throws ValidationException
55
     *
56
     * @see https://billogram.com/api/documentation#customers_create
57
     */
58 1
    public function create(array $customer)
59
    {
60 1
        $response = $this->httpPost('/customer', $customer);
61
62 1
        return $this->handleResponse($response, Model::class);
63
    }
64
65
    /**
66
     * @param int   $customerNo
67
     * @param array $customer
68
     *
69
     * @return Model|ResponseInterface
70
     *
71
     * @throws NotFoundException
72
     * @throws ValidationException
73
     *
74
     * @see https://billogram.com/api/documentation#customers_edit
75
     */
76 1
    public function update(int $customerNo, array $customer)
77
    {
78 1
        $response = $this->httpPut('/customer/'.$customerNo, $customer);
79
80 1
        return $this->handleResponse($response, Model::class);
81
    }
82
}
83