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 (#26)
by
unknown
05:57
created

Resource::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1.037

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 3
cp 0.6667
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1.037
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
    }
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
    public function url($id = null, $additionalEndpoint = null)
36
    {
37
        $endpoint = $this->endpoint();
38
39
        if (! is_null($id)) {
40
            $endpoint .= '/' . $id;
41
        }
42
        if (! is_null($additionalEndpoint)) {
43
            $endpoint .= '/' . $additionalEndpoint;
44
        }
45
46
        return $endpoint;
47
    }
48
49
    /**
50
     * Retrieve all resources.
51
     *
52
     * @param array $params Pagination and Filter parameters.
53
     *
54
     * @return mixed
55
     */
56
    public function all(array $params = [])
57
    {
58
        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
    public function create(array $form_params = [])
69
    {
70
        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
    public function retrieve($id = null)
81
    {
82
        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
    public function update($id = null, array $form_params = [])
94
    {
95
        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
    public function delete($id = null, array $form_params = [])
107
    {
108
        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
    public function get($id = null, $additionalEndpoint = null)
120
    {
121
        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
    public function post($id = null, $additionalEndpoint = null, array $form_params = [])
134
    {
135
        return $this->apiRequester->request('POST', $this->url($id, $additionalEndpoint), ['json' => $form_params]);
136
    }
137
138
    /**
139
     * Return the last response from a preview request
140
     *
141
     * @return mixed
142
     */
143
    public function getLastResponse()
144
    {
145
        return $this->apiRequester->lastResponse;
146
    }
147
}
148