1 | <?php |
||
19 | trait TestsRequestHelperTrait |
||
20 | { |
||
21 | |||
22 | /** |
||
23 | * property to be set on the user test class |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $endpoint = ''; |
||
28 | |||
29 | /** |
||
30 | * property to be set on the user test class |
||
31 | * |
||
32 | * @var bool |
||
33 | */ |
||
34 | protected $auth = true; |
||
35 | |||
36 | /** |
||
37 | * property to be set before making a call to override the default class property |
||
38 | * |
||
39 | * @var string |
||
40 | */ |
||
41 | protected $overrideEndpoint; |
||
42 | |||
43 | /** |
||
44 | * property to be set before making a call to override the default class property |
||
45 | * |
||
46 | * @var string |
||
47 | */ |
||
48 | protected $overrideAuth; |
||
49 | |||
50 | /** |
||
51 | * the $endpoint property will be extracted to $endpointVerb and $endpointUrl after parsing |
||
52 | * |
||
53 | * @var string |
||
54 | */ |
||
55 | private $endpointVerb; |
||
56 | |||
57 | /** |
||
58 | * the $endpoint property will be extracted to $endpointVerb and $endpointUrl after parsing |
||
59 | * |
||
60 | * @var string |
||
61 | */ |
||
62 | private $endpointUrl; |
||
63 | |||
64 | /** |
||
65 | * @param $this ->endpointUrl |
||
66 | * @param string $this ->endpointVerb |
||
|
|||
67 | * @param array $data |
||
68 | * @param bool $protected |
||
69 | * @param array $headers |
||
70 | * |
||
71 | * @return mixed |
||
72 | * @throws \Symfony\Component\Debug\Exception\UndefinedMethodException |
||
73 | */ |
||
74 | public function makeCall(array $data = [], array $headers = []) |
||
82 | |||
83 | /** |
||
84 | * Inject the ID in the Endpoint URI before making the call by |
||
85 | * overriding the `$this->endpoint` property |
||
86 | * |
||
87 | * Example: you give it ('users/{id}/stores', 100) it returns 'users/100/stores' |
||
88 | * |
||
89 | * @param $this ->url |
||
90 | * @param $id |
||
91 | * @param bool $skipEncoding |
||
92 | * @param string $replace |
||
93 | * |
||
94 | * @return mixed |
||
95 | */ |
||
96 | public function injectId($id, $skipEncoding = false, $replace = '{id}') |
||
105 | |||
106 | /** |
||
107 | * Override the default class endpoint property before making the call |
||
108 | * |
||
109 | * to be used as follow: $this->endpoint('verb@url')->makeCall($data); |
||
110 | * |
||
111 | * @param $endpoint |
||
112 | * |
||
113 | * @return $this |
||
114 | */ |
||
115 | public function endpoint($endpoint) |
||
121 | |||
122 | /** |
||
123 | * Override the default class auth property before making the call |
||
124 | * |
||
125 | * to be used as follow: $this->auth('false')->makeCall($data); |
||
126 | * |
||
127 | * @param bool $auth |
||
128 | * |
||
129 | * @return $this |
||
130 | */ |
||
131 | public function auth(bool $auth) |
||
137 | |||
138 | /** |
||
139 | * @return string |
||
140 | */ |
||
141 | public function getEndpoint() |
||
145 | |||
146 | /** |
||
147 | * @return bool |
||
148 | */ |
||
149 | public function getAuth() |
||
153 | |||
154 | /** |
||
155 | * @param array $data |
||
156 | * @param array $headers |
||
157 | * |
||
158 | * @return mixed |
||
159 | */ |
||
160 | private function httpRequest(array $data = [], array $headers = []) |
||
185 | |||
186 | /** |
||
187 | * @param $responseObject |
||
188 | * |
||
189 | * @return mixed |
||
190 | */ |
||
191 | private function getResponse($responseObject) |
||
195 | |||
196 | /** |
||
197 | * Attach Authorization Bearer Token to the request headers |
||
198 | * if it doesn't exist already and the authentication is required |
||
199 | * for the endpoint `$this->auth = true`. |
||
200 | * |
||
201 | * @param $headers |
||
202 | * |
||
203 | * @return mixed |
||
204 | */ |
||
205 | private function injectAccessToken(array $headers = []) |
||
215 | |||
216 | /** |
||
217 | * just check if headers array has an `Authorization` as key. |
||
218 | * |
||
219 | * @param $headers |
||
220 | * |
||
221 | * @return bool |
||
222 | */ |
||
223 | private function headersContainAuthorization($headers) |
||
227 | |||
228 | /** |
||
229 | * @param $data |
||
230 | * @param $endpointUrl |
||
231 | * |
||
232 | * @return null|string |
||
233 | */ |
||
234 | private function dataArrayToQueryParam($data, $url) |
||
238 | |||
239 | |||
240 | /** |
||
241 | * @param $id |
||
242 | * @param bool $skipEncoding |
||
243 | * |
||
244 | * @return mixed |
||
245 | */ |
||
246 | private function hashEndpointId($id, $skipEncoding = false) |
||
250 | |||
251 | /** |
||
252 | * read `$this->endpoint` property (`verb@url`) and get `$this->endpointVerb` & `$this->endpointUrl` |
||
253 | */ |
||
254 | private function parseEndpoint() |
||
273 | |||
274 | /** |
||
275 | * @void |
||
276 | */ |
||
277 | private function validateEndpointExist() |
||
283 | |||
284 | /** |
||
285 | * @param $separator |
||
286 | */ |
||
287 | private function validateEndpointFormat($separator) |
||
294 | } |
||
295 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.