Code Duplication    Length = 94-95 lines in 2 locations

src/Api/Customer.php 1 location

@@ 16-110 (lines=95) @@
13
/**
14
 * @author Ibrahim Hizeoui <[email protected]>
15
 */
16
class Customer extends HttpApi
17
{
18
    /**
19
     * @param array $param
20
     *
21
     * @return string|array
22
     *
23
     * @see https://billogram.com/api/documentation#customers_list
24
     */
25
    public function search(array $param = [])
26
    {
27
        $param = array_merge(['page' => 1, 'page_size' => 100], $param);
28
        $response = $this->httpGet('/customer', $param);
29
        if (!$this->hydrator) {
30
            return $response;
31
        }
32
        if ($response->getStatusCode() !== 200) {
33
            $this->handleErrors($response);
34
        }
35
36
        return $this->hydrator->hydrate($response, CustomerCollection::class);
37
    }
38
39
    /**
40
     * @param int   $customerNo
41
     * @param array $param
42
     *
43
     * @return Model|ResponseInterface
44
     *
45
     * @throws NotFoundException
46
     *
47
     * @see https://billogram.com/api/documentation#customers_fetch
48
     */
49
    public function fetch(int $customerNo, array $param = [])
50
    {
51
        $response = $this->httpGet('/customer/'.$customerNo, $param);
52
        if (!$this->hydrator) {
53
            return $response;
54
        }
55
        // Use any valid status code here
56
        if ($response->getStatusCode() !== 200) {
57
            $this->handleErrors($response);
58
        }
59
60
        return $this->hydrator->hydrate($response, Model::class);
61
    }
62
63
    /**
64
     * @param Model $customer
65
     *
66
     * @return Model|ResponseInterface
67
     *
68
     * @throws ValidationException
69
     *
70
     * @see https://billogram.com/api/documentation#customers_create
71
     */
72
    public function create(Model $customer)
73
    {
74
        $response = $this->httpPost('/customer', $customer->toArray());
75
        if (!$this->hydrator) {
76
            return $response;
77
        }
78
        // Use any valid status code here
79
        if ($response->getStatusCode() !== 200) {
80
            $this->handleErrors($response);
81
        }
82
83
        return $this->hydrator->hydrate($response, Model::class);
84
    }
85
86
    /**
87
     * @param int   $customerNo
88
     * @param Model $costumer
89
     *
90
     * @return Model|ResponseInterface
91
     *
92
     * @throws NotFoundException
93
     * @throws ValidationException
94
     *
95
     * @see https://billogram.com/api/documentation#customers_edit
96
     */
97
    public function update(int $customerNo, Model $costumer)
98
    {
99
        $response = $this->httpPut('/customer/'.$customerNo, $costumer->toArray());
100
        if (!$this->hydrator) {
101
            return $response;
102
        }
103
        // Use any valid status code here
104
        if ($response->getStatusCode() !== 200) {
105
            $this->handleErrors($response);
106
        }
107
108
        return $this->hydrator->hydrate($response, Model::class);
109
    }
110
}
111

src/Api/Invoice.php 1 location

@@ 14-107 (lines=94) @@
11
/**
12
 * @author Ibrahim Hizeoui <[email protected]>
13
 */
14
class Invoice extends HttpApi
15
{
16
    /**
17
     * @param array $param
18
     *
19
     * @return string|array
20
     *
21
     * @see https://billogram.com/api/documentation#billogram_call_create
22
     */
23
    public function search(array $param = [])
24
    {
25
        $param = array_merge(['page' => 1, 'page_size' => 100], $param);
26
        $response = $this->httpGet('/billogram', $param);
27
        if (!$this->hydrator) {
28
            return $response;
29
        }
30
31
        // Use any valid status code here
32
        if ($response->getStatusCode() !== 200) {
33
            $this->handleErrors($response);
34
        }
35
36
        return $this->hydrator->hydrate($response, InvoiceCollection::class);
37
    }
38
39
    /**
40
     * @param string $invoiceId
41
     * @param array  $param
42
     *
43
     * @return mixed|\Psr\Http\Message\ResponseInterface
44
     *
45
     * @see https://billogram.com/api/documentation#billogram_call_create
46
     */
47
    public function fetch(string $invoiceId, array $param = [])
48
    {
49
        $response = $this->httpGet('/billogram/'.$invoiceId, $param);
50
        if (!$this->hydrator) {
51
            return $response;
52
        }
53
        // Use any valid status code here
54
        if ($response->getStatusCode() !== 200) {
55
            $this->handleErrors($response);
56
        }
57
58
        return $this->hydrator->hydrate($response, Model::class);
59
    }
60
61
    /**
62
     * @param Model $invoice
63
     *
64
     * @return mixed|\Psr\Http\Message\ResponseInterface
65
     *
66
     * @see https://billogram.com/api/documentation#billogram_call_create
67
     *
68
     * @throws ValidationException
69
     */
70
    public function create(Model $invoice)
71
    {
72
        $response = $this->httpPost('/billogram', $invoice->toArray());
73
        if (!$this->hydrator) {
74
            return $response;
75
        }
76
        // Use any valid status code here
77
        if ($response->getStatusCode() !== 200) {
78
            $this->handleErrors($response);
79
        }
80
81
        return $this->hydrator->hydrate($response, Model::class);
82
    }
83
84
    /**
85
     * @param string $invoiceId
86
     * @param Model  $invoice
87
     *
88
     * @return mixed|\Psr\Http\Message\ResponseInterface
89
     *
90
     * @see https://billogram.com/api/documentation#billogram_call_create
91
     *
92
     * @throws ValidationException
93
     */
94
    public function update(string $invoiceId, Model $invoice)
95
    {
96
        $response = $this->httpPut('/billogram/'.$invoiceId, $invoice->toArray());
97
        if (!$this->hydrator) {
98
            return $response;
99
        }
100
        // Use any valid status code here
101
        if ($response->getStatusCode() !== 200) {
102
            $this->handleErrors($response);
103
        }
104
105
        return $this->hydrator->hydrate($response, Model::class);
106
    }
107
}
108