InvoiceController::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
nc 1
nop 3
dl 0
loc 3
c 0
b 0
f 0
cc 1
rs 10
1
<?php
2
3
namespace ItsMeLePassos\CafeApi;
4
5
use ItsMeLePassos\CafeApi\API\CafeApiController;
6
7
class InvoiceController extends CafeApiController
8
{
9
    /**
10
     * Invoices constructor
11
     * @param string $apiUrl
12
     * @param string $email
13
     * @param string $password
14
     */
15
    public function __construct(string $apiUrl, string $email, string $password)
16
    {
17
        parent::__construct($apiUrl, $email, $password);
18
    }
19
20
    /**
21
     * @param array|null $headers
22
     * @return InvoiceController
23
     */
24
    public function index(?array $headers): InvoiceController
25
    {
26
        $this->request(
27
            "GET",
28
            "/invoices",
29
            null,
30
            $headers
31
        );
32
33
        return $this;
34
    }
35
36
    /**
37
     * @param array $fields
38
     * @return InvoiceController
39
     */
40
    public function create(array $fields): InvoiceController
41
    {
42
        $this->request(
43
            "POST",
44
            "/invoices",
45
            $fields
46
        );
47
48
        return $this;
49
    }
50
51
    /**
52
     * @param int $invoiceId
53
     * @return InvoiceController
54
     */
55
    public function read(int $invoiceId): InvoiceController
56
    {
57
        $this->request(
58
            "GET",
59
            "/invoices/{$invoiceId}"
60
        );
61
62
        return $this;
63
    }
64
65
    /**
66
     * @param int $invoiceId
67
     * @param array $fields
68
     * @return InvoiceController
69
     */
70
    public function update(int $invoiceId, array $fields): InvoiceController
71
    {
72
        $this->request(
73
            "PUT",
74
            "/invoices/{$invoiceId}",
75
            $fields
76
        );
77
78
        return $this;
79
    }
80
81
    /**
82
     * @param int $invoiceId
83
     * @return InvoiceController
84
     */
85
    public function delete(int $invoiceId): InvoiceController
86
    {
87
        $this->request(
88
            "DELETE",
89
            "/invoices/{$invoiceId}"
90
        );
91
92
        return $this;
93
    }
94
}
95