Account::listAccounts()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Fenerum\API;
6
7
class Account extends Base
8
{
9
    /**
10
     * @return array|null
11
     * @throws \Fenerum\API\Exceptions\FenerumApiException
12
     */
13
    public function listAccounts(): ?array
14
    {
15
        return $this->client->get('accounts/');
16
    }
17
18
    /**
19
     * @param string $code
20
     * @return array|null
21
     * @throws \Fenerum\API\Exceptions\FenerumApiException
22
     */
23
    public function getAccount(string $code): ?array
24
    {
25
        return $this->client->get('accounts/'.$code.'/');
26
    }
27
28
    /**
29
     * @see http://docs.fenerum.com/#operation/accounts_create
30
     *
31
     * @param array $data
32
     * @return array|null
33
     * @throws \Fenerum\API\Exceptions\FenerumApiException
34
     * @throws \Fenerum\API\Exceptions\FenerumValidationException
35
     */
36
    public function createAccount(array $data): ?array
37
    {
38
        $validated = $this->validate($data, [
39
            'company_name' => 'required|string|max:128',
40
            'code' => 'required|string|max:128',
41
            'legal_address' => 'required|string',
42
            'legal_zipcode' => 'required|string',
43
            'legal_city' => 'required|string',
44
            'legal_country' => 'required|string',
45
            'partner' => 'integer',
46
            'ean_invoicing' => 'boolean',
47
            'ean_number' => 'string',
48
            'language' => 'string',
49
            'legal_vat_number' => 'string',
50
            'billing_same_as_legal' => 'boolean',
51
            'billing_address' => 'string',
52
            'billing_zipcode' => 'string',
53
            'billing_city' => 'string',
54
            'billing_country' => 'string',
55
        ]);
56
57
        return $this->client->post('accounts/', $validated);
58
    }
59
60
    /**
61
     * @param array $data
62
     * @param string $code
63
     * @return array|null
64
     * @throws \Fenerum\API\Exceptions\FenerumApiException
65
     * @throws \Fenerum\API\Exceptions\FenerumValidationException
66
     */
67
    public function updateAccount(array $data, string $code): ?array
68
    {
69
        $validated = $this->validate($data, [
70
            'company_name' => 'required|string|max:128',
71
            'code' => 'required|string|max:128',
72
            'legal_address' => 'required|string',
73
            'legal_zipcode' => 'required|string',
74
            'legal_city' => 'required|string',
75
            'legal_country' => 'required|string',
76
            'partner' => 'integer',
77
            'ean_invoicing' => 'boolean',
78
            'ean_number' => 'string',
79
            'language' => 'string',
80
            'legal_vat_number' => 'string',
81
            'billing_same_as_legal' => 'boolean',
82
            'billing_address' => 'string',
83
            'billing_zipcode' => 'string',
84
            'billing_city' => 'string',
85
            'billing_country' => 'string',
86
        ]);
87
88
        return $this->client->put('accounts/'.$code.'/', $validated);
89
    }
90
}
91