Customer   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 107
Duplicated Lines 14.02 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 15
lcom 1
cbo 3
dl 15
loc 107
ccs 0
cts 55
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 15 3
A delete() 0 15 3
A all() 0 15 3
A get() 15 15 3
A update() 0 15 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 FAPI\Fortnox\Api;
6
7
use FAPI\Fortnox\Model\ApiResponse;
8
use FAPI\Fortnox\Model\Customer\Customer as Model;
9
use FAPI\Fortnox\Model\Customer\CustomerCollection;
10
use Psr\Http\Message\ResponseInterface;
11
12
/**
13
 * {@link https://developer.fortnox.se/documentation/resources/customers/}.
14
 *
15
 * @author Tobias Nyholm <[email protected]>
16
 */
17
class Customer extends HttpApi
18
{
19
    /**
20
     * @throws \FAPI\Fortnox\Exception\DomainException
21
     *
22
     * @return CustomerCollection|ResponseInterface
23
     */
24
    public function all(array $params = [])
25
    {
26
        $response = $this->httpGet('/3/customers', $params);
27
28
        if (!$this->hydrator) {
29
            return $response;
30
        }
31
32
        // Use any valid status code here
33
        if (200 !== $response->getStatusCode()) {
34
            $this->handleErrors($response);
35
        }
36
37
        return $this->hydrator->hydrate($response, CustomerCollection::class);
38
    }
39
40
    /**
41
     * @throws \FAPI\Fortnox\Exception\DomainException
42
     *
43
     * @return Model|ResponseInterface
44
     */
45 View Code Duplication
    public function get(string $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...
46
    {
47
        $response = $this->httpGet('/3/customers/'.$customer);
48
49
        if (!$this->hydrator) {
50
            return $response;
51
        }
52
53
        // Use any valid status code here
54
        if (200 !== $response->getStatusCode()) {
55
            $this->handleErrors($response);
56
        }
57
58
        return $this->hydrator->hydrate($response, Model::class);
59
    }
60
61
    /**
62
     * @throws \FAPI\Fortnox\Exception\DomainException
63
     *
64
     * @return Model|ResponseInterface
65
     */
66
    public function create(array $data)
67
    {
68
        $response = $this->httpPost('/3/customers', ['Customer' => $data]);
69
70
        if (!$this->hydrator) {
71
            return $response;
72
        }
73
74
        // Use any valid status code here
75
        if (201 !== $response->getStatusCode()) {
76
            $this->handleErrors($response);
77
        }
78
79
        return $this->hydrator->hydrate($response, Model::class);
80
    }
81
82
    /**
83
     * @throws \FAPI\Fortnox\Exception\DomainException
84
     *
85
     * @return Model|ResponseInterface
86
     */
87
    public function update(string $customer, array $data)
88
    {
89
        $response = $this->httpPut('/3/customers/'.$customer, ['Customer' => $data]);
90
91
        if (!$this->hydrator) {
92
            return $response;
93
        }
94
95
        // Use any valid status code here
96
        if (200 !== $response->getStatusCode()) {
97
            $this->handleErrors($response);
98
        }
99
100
        return $this->hydrator->hydrate($response, Model::class);
101
    }
102
103
    /**
104
     * @throws \FAPI\Fortnox\Exception\DomainException
105
     *
106
     * @return ApiResponse|ResponseInterface
107
     */
108
    public function delete(string $customer)
109
    {
110
        $response = $this->httpDelete('/3/customers/'.$customer);
111
112
        if (!$this->hydrator) {
113
            return $response;
114
        }
115
116
        // Use any valid status code here
117
        if (204 !== $response->getStatusCode()) {
118
            $this->handleErrors($response);
119
        }
120
121
        return $this->hydrator->hydrate($response, ApiResponse::class);
122
    }
123
}
124