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

Customers   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 9
c 1
b 0
f 0
dl 0
loc 57
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A update() 0 5 1
A create() 0 5 1
A delete() 0 3 1
A all() 0 2 1
A fetch() 0 5 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\Customer;
9
use Lifeboat\Resource\ListResource;
10
11
/**
12
 * Class Customers
13
 * @package Lifeboat\Services
14
 */
15
class Customers extends ApiService {
16
17
    /**
18
     * @param int $id
19
     * @return Customer|null
20
     * @throws ApiException
21
     * @throws OAuthException
22
     */
23
    public function fetch(int $id): ?Customer
24
    {
25
        /** @var Customer|null $fetch */
26
        $fetch = $this->_get('api/customers/customer' . $id);
27
        return $fetch;
28
    }
29
30
    /**
31
     * @param array $data
32
     * @return Customer|null
33
     * @throws ApiException
34
     * @throws OAuthException
35
     */
36
    public function create(array $data): ?Customer
37
    {
38
        /** @var Customer|null $create */
39
        $create = $this->_post('api/customers/customer', $data);
40
        return $create;
41
    }
42
43
    /**
44
     * @param int $id
45
     * @param array $data
46
     * @return Customer|null
47
     * @throws ApiException
48
     * @throws OAuthException
49
     */
50
    public function update(int $id, array $data): ?Customer
51
    {
52
        /** @var Customer|null $post */
53
        $post = $this->_post('api/customers/customer/' . $id, $data);
54
        return $post;
55
    }
56
57
    /**
58
     * @param int $id
59
     * @return bool
60
     */
61
    public function delete(int $id): bool
62
    {
63
        throw new BadMethodException("Customers 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/customers/all', ['search' => $search], 20);
72
    }
73
}
74