Conditions | 19 |
Paths | 24 |
Total Lines | 123 |
Code Lines | 57 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
204 | public function isEndpoint($api, $endpoint) |
||
205 | { |
||
206 | $endpointSettings = []; |
||
|
|||
207 | |||
208 | /** |
||
209 | * Return if it's a system endpoint |
||
210 | */ |
||
211 | if (null !== ($endpointSettings = $this->isSystemEndpoint($api, $endpoint))) { |
||
212 | return $endpointSettings; |
||
213 | } |
||
214 | |||
215 | $endpoint = htmlspecialchars($endpoint, ENT_QUOTES, 'UTF-8'); |
||
216 | $index = array_search($api, $this->BASE_ENDPOINTS); |
||
217 | |||
218 | if ($index !== false) { |
||
219 | if (isset($this->registry[$api])) { |
||
220 | $endpointSettings = array( |
||
221 | 'path' => $endpoint, |
||
222 | 'model' => array( |
||
223 | 'namespace' => $this->NAMESPACE_ENDPOINTS[$api], |
||
224 | 'class' => $this->BASE_ENDPOINTS[$index], |
||
225 | 'method' => basename($endpoint), |
||
226 | 'scope' => 'private', |
||
227 | ), |
||
228 | ); |
||
229 | |||
230 | /** |
||
231 | * Nothing dynamic, found an exact match |
||
232 | * @var array |
||
233 | */ |
||
234 | if (array_search($endpoint, $this->registry[$api]) !== false) { |
||
235 | if( method_exists($this->NAMESPACE_ENDPOINTS[$api], 'scope') ) { |
||
236 | $classScope = (new $this->NAMESPACE_ENDPOINTS[$api])->scope(); |
||
237 | $position = array_search($endpoint, $this->registry[$api]); |
||
238 | |||
239 | if( is_array($classScope) && isset($classScope[$position]) ) { |
||
240 | $endpointSettings['model']['scope'] = $classScope[$position]; |
||
241 | |||
242 | }else{ |
||
243 | |||
244 | if( !is_array($classScope) ) { |
||
245 | $endpointSettings['model']['scope'] = $classScope; |
||
246 | } |
||
247 | } |
||
248 | } |
||
249 | return (object) $endpointSettings; |
||
250 | } |
||
251 | |||
252 | /** |
||
253 | * Check for dynamic uri eg: {asset_id} |
||
254 | * Dynamic uri's must be wrapped in {} for a true return |
||
255 | */ |
||
256 | foreach ($this->registry[$api] as $i => $path) { |
||
257 | $endpointRegister = $path; |
||
258 | $methodArgs = []; |
||
259 | |||
260 | /** |
||
261 | * If comparing the two sizes are not equal |
||
262 | * then no use continuing through the loop |
||
263 | */ |
||
264 | if (!$this->uriCheckSize($endpointRegister, $endpoint)) { |
||
265 | continue; |
||
266 | } |
||
267 | |||
268 | /** |
||
269 | * This replacment will create a pattern to use as a match all expression |
||
270 | * @var [string] |
||
271 | */ |
||
272 | $endpointRegister = preg_replace('@/{(.*?)}@', '/(.*?)', $endpointRegister); |
||
273 | |||
274 | if (preg_match_all('@^' . $endpointRegister . '$@i', $endpoint, $dynamicParts)) { |
||
275 | $endpointFilter = $this->filterParts($endpoint, $dynamicParts); |
||
276 | $model = $this->getClassModel($path); |
||
277 | |||
278 | /** |
||
279 | * Find the dynamic parts and set them as argument key(s) |
||
280 | * then combine them with the endpoint request and set the request parts |
||
281 | * as argument value(s) |
||
282 | */ |
||
283 | if (preg_match_all("/(?<={).*?(?=})/", $path, $registerParts)) { |
||
284 | if (isset($registerParts[0][0])) { |
||
285 | $registerParts = $registerParts[0]; |
||
286 | |||
287 | if (sizeof($endpointFilter) == sizeof($registerParts)) { |
||
288 | $methodArgs = array_combine($registerParts, $endpointFilter); |
||
289 | } |
||
290 | } |
||
291 | } |
||
292 | |||
293 | $scope = 'private'; |
||
294 | |||
295 | if( method_exists($this->NAMESPACE_ENDPOINTS[$api], 'scope') ) { |
||
296 | $classScope = (new $this->NAMESPACE_ENDPOINTS[$api])->scope(); |
||
297 | $position = array_search($path, $this->registry[$api]); |
||
298 | |||
299 | if( is_array($classScope) && isset($classScope[$position]) ) { |
||
300 | $scope = $classScope[$position]; |
||
301 | |||
302 | }else{ |
||
303 | |||
304 | if( !is_array($classScope) ) { |
||
305 | $scope = $classScope; |
||
306 | } |
||
307 | } |
||
308 | } |
||
309 | |||
310 | $endpointSettings['model'] = array( |
||
311 | 'scope' => $scope, |
||
312 | 'namespace' => $this->NAMESPACE_ENDPOINTS[$api], |
||
313 | 'class' => $model['class'], |
||
314 | 'method' => $model['method'], |
||
315 | 'arguments' => $methodArgs, |
||
316 | ); |
||
317 | |||
318 | return (object) $endpointSettings; |
||
319 | } else { |
||
320 | continue; |
||
321 | } |
||
322 | } |
||
323 | } |
||
324 | } |
||
325 | |||
326 | return; |
||
327 | } |
||
385 |