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}') |
||
104 | |||
105 | /** |
||
106 | * Override the default class endpoint property before making the call |
||
107 | * |
||
108 | * to be used as follow: $this->endpoint('verb@url')->makeCall($data); |
||
109 | * |
||
110 | * @param $endpoint |
||
111 | * |
||
112 | * @return $this |
||
113 | */ |
||
114 | public function endpoint($endpoint) |
||
120 | |||
121 | /** |
||
122 | * Override the default class auth property before making the call |
||
123 | * |
||
124 | * to be used as follow: $this->auth('false')->makeCall($data); |
||
125 | * |
||
126 | * @param bool $auth |
||
127 | * |
||
128 | * @return $this |
||
129 | */ |
||
130 | public function auth(bool $auth) |
||
136 | |||
137 | /** |
||
138 | * @return string |
||
139 | */ |
||
140 | public function getEndpoint() |
||
144 | |||
145 | /** |
||
146 | * @return bool |
||
147 | */ |
||
148 | public function getAuth() |
||
152 | |||
153 | /** |
||
154 | * @param array $data |
||
155 | * @param array $headers |
||
156 | * |
||
157 | * @return mixed |
||
158 | */ |
||
159 | private function httpRequest(array $data = [], array $headers = []) |
||
184 | |||
185 | /** |
||
186 | * @param $responseContent |
||
187 | * |
||
188 | * @return mixed |
||
189 | */ |
||
190 | private function getResponse($responseContent) |
||
194 | |||
195 | /** |
||
196 | * Attach Authorization Bearer Token to the request headers |
||
197 | * if it doesn't exist already and the authentication is required |
||
198 | * for the endpoint `$this->auth = true`. |
||
199 | * |
||
200 | * @param $headers |
||
201 | * |
||
202 | * @return mixed |
||
203 | */ |
||
204 | private function injectAccessToken(array $headers = []) |
||
214 | |||
215 | /** |
||
216 | * just check if headers array has an `Authorization` as key. |
||
217 | * |
||
218 | * @param $headers |
||
219 | * |
||
220 | * @return bool |
||
221 | */ |
||
222 | private function headersContainAuthorization($headers) |
||
226 | |||
227 | /** |
||
228 | * @param $data |
||
229 | * @param $endpointUrl |
||
230 | * |
||
231 | * @return null|string |
||
232 | */ |
||
233 | private function dataArrayToQueryParam($data, $url) |
||
237 | |||
238 | |||
239 | /** |
||
240 | * @param $id |
||
241 | * @param bool $skipEncoding |
||
242 | * |
||
243 | * @return mixed |
||
244 | */ |
||
245 | private function hashEndpointId($id, $skipEncoding = false) |
||
249 | |||
250 | /** |
||
251 | * read `$this->endpoint` property (`verb@url`) and get `$this->endpointVerb` & `$this->endpointUrl` |
||
252 | */ |
||
253 | private function parseEndpoint() |
||
272 | |||
273 | /** |
||
274 | * @void |
||
275 | */ |
||
276 | private function validateEndpointExist() |
||
282 | |||
283 | /** |
||
284 | * @param $separator |
||
285 | */ |
||
286 | private function validateEndpointFormat($separator) |
||
293 | } |
||
294 |
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.