Invoice   A
last analyzed

Complexity

Total Complexity 18

Size/Duplication

Total Lines 128
Duplicated Lines 35.16 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 18
lcom 1
cbo 3
dl 45
loc 128
ccs 0
cts 66
cp 0
rs 10
c 0
b 0
f 0

6 Methods

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