Passed
Push — main ( 11438a...0b6967 )
by Dylan
02:15
created

Addresses::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Lifeboat\Services;
4
5
use Lifeboat\Exceptions\ApiException;
6
use Lifeboat\Exceptions\BadMethodException;
7
use Lifeboat\Exceptions\OAuthException;
8
use Lifeboat\Models\Address;
9
use Lifeboat\Resource\ListResource;
10
11
/**
12
 * Class Addresses
13
 * @package Lifeboat\Services
14
 */
15
class Addresses extends ApiService {
16
17
    /**
18
     * @param int $id
19
     * @return Address|null
20
     * @throws ApiException
21
     * @throws OAuthException
22
     */
23
    public function fetch(int $id): ?Address
24
    {
25
        /** @var Address|null $address */
26
        $address = $this->_get('api/addresses/address' . $id);
27
        return $address;
28
    }
29
30
    /**
31
     * @param array $data
32
     * @return Address|null
33
     * @throws ApiException
34
     * @throws OAuthException
35
     */
36
    public function create(array $data): ?Address
37
    {
38
        /** @var Address|null $address */
39
        $address = $this->_post('api/addresses/address', $data);
40
        return $address;
41
    }
42
43
    /**
44
     * @param int $id
45
     * @param array $data
46
     * @return Address|null
47
     * @throws ApiException
48
     * @throws OAuthException
49
     */
50
    public function update(int $id, array $data): ?Address
51
    {
52
        /** @var Address|null $address */
53
        $address = $this->_post('api/addresses/address/' . $id, $data);
54
        return $address;
55
    }
56
57
    /**
58
     * @param int $id
59
     * @return bool
60
     */
61
    public function delete(int $id): bool
62
    {
63
        throw new BadMethodException("Addresses cannot be deleted");
64
    }
65
66
    /**
67
     * @param string $search
68
     * @return ListResource
69
     */
70
    public function all(string $search = ''): ListResource {
71
        return new ListResource($this->getClient(), 'api/addresses/all', ['search' => $search], 20);
72
    }
73
}
74