Contract   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 75
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A listContracts() 0 4 1
A getContract() 0 4 1
A createContract() 0 12 1
A updateContract() 0 12 1
A deleteContract() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Fenerum\API;
6
7
class Contract extends Base
8
{
9
    /**
10
     * @param string $accountCode
11
     * @return array|null
12
     * @throws \Fenerum\API\Exceptions\FenerumApiException
13
     */
14
    public function listContracts(string $accountCode): ?array
15
    {
16
        return $this->client->get('accounts/'.$accountCode.'/contracts/');
17
    }
18
19
    /**
20
     * @param string $accountCode
21
     * @param string $uuid
22
     * @return array|null
23
     * @throws \Fenerum\API\Exceptions\FenerumApiException
24
     */
25
    public function getContract(string $accountCode, string $uuid): ?array
26
    {
27
        return $this->client->get('accounts/'.$accountCode.'/contracts/'.$uuid.'/');
28
    }
29
30
    /**
31
     * @param array $data
32
     * @param string $accountCode
33
     * @return array|null
34
     * @throws \Fenerum\API\Exceptions\FenerumValidationException
35
     * @throws \Fenerum\API\Exceptions\FenerumApiException
36
     */
37
    public function createContract(array $data, string $accountCode): ?array
38
    {
39
        $this->validate($data, [
40
            'plan_terms' => 'required|string',
41
            'start_date' => 'required|date',
42
            'end_date' => 'date',
43
            'commitment_length' => 'required|integer',
44
            'exclusive_tiers' => 'boolean',
45
        ]);
46
47
        return $this->client->post('accounts/'.$accountCode.'/contracts/', $data);
48
    }
49
50
    /**
51
     * @param array $data
52
     * @param string $accountCode
53
     * @param string $uuid
54
     * @return array|null
55
     * @throws \Fenerum\API\Exceptions\FenerumApiException
56
     * @throws \Fenerum\API\Exceptions\FenerumValidationException
57
     */
58
    public function updateContract(array $data, string $accountCode, string $uuid): ?array
59
    {
60
        $this->validate($data, [
61
            'plan_terms' => 'required|string',
62
            'start_date' => 'required|date',
63
            'end_date' => 'date',
64
            'commitment_length' => 'required|integer',
65
            'exclusive_tiers' => 'boolean',
66
        ]);
67
68
        return $this->client->put('accounts/'.$accountCode.'/contracts/'.$uuid.'/', $data);
69
    }
70
71
    /**
72
     * @param string $accountCode
73
     * @param string $uuid
74
     * @return array|null
75
     * @throws \Fenerum\API\Exceptions\FenerumApiException
76
     */
77
    public function deleteContract(string $accountCode, string $uuid): ?array
78
    {
79
        return $this->client->delete('accounts/'.$accountCode.'/contracts/'.$uuid.'/');
80
    }
81
}
82