GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#20)
by
unknown
03:21
created

Resource   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 154
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 1
dl 0
loc 154
ccs 28
cts 28
cp 1
rs 10
c 0
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
endpoint() 0 1 ?
A url() 0 13 3
A all() 0 4 1
A create() 0 4 1
A retrieve() 0 4 1
A update() 0 4 1
A delete() 0 4 1
A get() 0 4 1
A post() 0 4 1
A current() 0 4 1
A getLastResponse() 0 3 1
1
<?php
2
3
namespace Vindi;
4
5
abstract class Resource
6
{
7
    /**
8
     * @var \Vindi\ApiRequester
9
     */
10
    public $apiRequester;
11
12
    /**
13
     * Resource constructor.
14
     */
15 414
    public function __construct()
16
    {
17 414
        $this->apiRequester = new ApiRequester;
18 414
    }
19
20
    /**
21
     * The endpoint at default state that will hit the API.
22
     *
23
     * @return string
24
     */
25
    abstract public function endpoint();
26
27
    /**
28
     * Build url that will hit the API.
29
     *
30
     * @param int    $id                 The resource's id.
31
     * @param string $additionalEndpoint Additional endpoint that will be appended to the URL.
32
     *
33
     * @return string
34
     */
35 294
    public function url($id = null, $additionalEndpoint = null)
36
    {
37 294
        $endpoint = $this->endpoint();
38
39 294
        if (! is_null($id)) {
40 214
            $endpoint .= '/' . $id;
41 214
        }
42 294
        if (! is_null($additionalEndpoint)) {
43 94
            $endpoint .= '/' . $additionalEndpoint;
44 94
        }
45
46 294
        return $endpoint;
47
    }
48
49
    /**
50
     * Retrieve all resources.
51
     *
52
     * @param array $params Pagination and Filter parameters.
53
     *
54
     * @return mixed
55
     */
56 40
    public function all(array $params = [])
57
    {
58 40
        return $this->apiRequester->request('GET', $this->url(), ['query' => $params]);
59
    }
60
61
    /**
62
     * Create a new resource.
63
     *
64
     * @param array $form_params The request body.
65
     *
66
     * @return mixed
67
     */
68 40
    public function create(array $form_params = [])
69
    {
70 40
        return $this->apiRequester->request('POST', $this->url(), ['json' => $form_params]);
71
    }
72
73
    /**
74
     * Retrieve a specific resource.
75
     *
76
     * @param int $id The resource's id.
77
     *
78
     * @return mixed
79
     */
80 40
    public function retrieve($id = null)
81
    {
82 40
        return $this->apiRequester->request('GET', $this->url($id));
83
    }
84
85
    /**
86
     * Update a specific resource.
87
     *
88
     * @param int   $id          The resource's id.
89
     * @param array $form_params The request body.
90
     *
91
     * @return mixed
92
     */
93 40
    public function update($id = null, array $form_params = [])
94
    {
95 40
        return $this->apiRequester->request('PUT', $this->url($id), ['json' => $form_params]);
96
    }
97
98
    /**
99
     * Delete a specific resource.
100
     *
101
     * @param int $id The resource's id.
102
     * @param array $form_params The request body.
103
     *
104
     * @return mixed
105
     */
106 40
    public function delete($id = null, array $form_params = [])
107
    {
108 40
        return $this->apiRequester->request('DELETE', $this->url($id), ['json' => $form_params]);
109
    }
110
111
    /**
112
     * Make a GET request to an additional endpoint for a specific resource.
113
     *
114
     * @param int    $id                 The resource's id.
115
     * @param string $additionalEndpoint Additional endpoint that will be appended to the URL.
116
     *
117
     * @return mixed
118
     */
119 42
    public function get($id = null, $additionalEndpoint = null)
120
    {
121 42
        return $this->apiRequester->request('GET', $this->url($id, $additionalEndpoint));
122
    }
123
124
    /**
125
     * Make a POST request to an additional endpoint for a specific resource.
126
     *
127
     * @param int    $id                 The resource's id.
128
     * @param string $additionalEndpoint Additional endpoint that will be appended to the URL.
129
     * @param array  $form_params        The request body.
130
     *
131
     * @return mixed
132
     */
133 52
    public function post($id = null, $additionalEndpoint = null, array $form_params = [])
134
    {
135 52
        return $this->apiRequester->request('POST', $this->url($id, $additionalEndpoint), ['json' => $form_params]);
136
    }
137
138
    /**
139
     * Make a GET request to an additional endpoint for a specific resource.
140
     *
141
     * @param string $additionalEndpoint Additional endpoint that will be appended to the URL.
142
     *
143 80
     * @return mixed
144 80
     */
145
    public function current($id = null, $additionalEndpoint = null)
146
    {
147
        return $this->apiRequester->request('GET', $this->url($id, $additionalEndpoint));
148
    }
149
150
    /**
151
     * Return the last response from a preview request
152
     *
153
     * @return mixed
154
     */
155
    public function getLastResponse(){
156
       return $this->apiRequester->lastResponse;
157
    }
158
}
159