Passed
Push — main ( 0b6967...cc8184 )
by Dylan
02:05
created

Collections   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
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 58
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A update() 0 5 1
A delete() 0 3 1
A all() 0 2 1
A create() 0 5 1
A fetch() 0 5 1
1
<?php
2
3
namespace Lifeboat\Services;
4
5
use Lifeboat\Exceptions\ApiException;
6
use Lifeboat\Exceptions\OAuthException;
7
use Lifeboat\Models\Collection;
8
use Lifeboat\Resource\ListResource;
9
10
/**
11
 * Class Collections
12
 * @package Lifeboat\Services
13
 */
14
class Collections extends ApiService {
15
16
    /**
17
     * @param int $id
18
     * @return Collection|null
19
     * @throws ApiException
20
     * @throws OAuthException
21
     */
22
    public function fetch(int $id): ?Collection
23
    {
24
        /** @var Collection|null $fetch */
25
        $fetch = $this->_get('api/collections/collection' . $id);
26
        return $fetch;
27
    }
28
29
    /**
30
     * @param array $data
31
     * @return Collection|null
32
     * @throws ApiException
33
     * @throws OAuthException
34
     */
35
    public function create(array $data): ?Collection
36
    {
37
        /** @var Collection|null $create */
38
        $create = $this->_post('api/collections/collection', $data);
39
        return $create;
40
    }
41
42
    /**
43
     * @param int $id
44
     * @param array $data
45
     * @return Collection|null
46
     * @throws ApiException
47
     * @throws OAuthException
48
     */
49
    public function update(int $id, array $data): ?Collection
50
    {
51
        /** @var Collection|null $post */
52
        $post = $this->_post('api/collections/collection/' . $id, $data);
53
        return $post;
54
    }
55
56
    /**
57
     * @param int $id
58
     * @return bool
59
     * @throws ApiException
60
     * @throws OAuthException
61
     */
62
    public function delete(int $id): bool
63
    {
64
        return $this->_delete('api/collections/collection/' . $id);
65
    }
66
67
    /**
68
     * @return ListResource
69
     */
70
    public function all(): ListResource {
71
        return new ListResource($this->getClient(), 'api/collections/all', [], 20);
72
    }
73
}
74