Conditions | 10 |
Paths | 15 |
Total Lines | 50 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Tests | 6 |
CRAP Score | 63.6376 |
Changes | 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 |
||
27 | 69 | public function call(Micro $api) |
|
28 | { |
||
29 | 69 | $auth = $api->getService('auth'); |
|
30 | 69 | $router = $api->getService('router'); |
|
31 | 69 | $request = $api->getService('request'); |
|
32 | |||
33 | 69 | if (!$auth->isIgnoreUri()) { |
|
34 | // explode() by / , postiion #1 is always the controller , so its the resource ^.^ |
||
35 | $matchRouter = explode('/', $router->getMatchedRoute()->getCompiledPattern()); |
||
36 | $resource = ucfirst($matchRouter[2]); //2 is alwasy the controller of the router |
||
37 | $userData = $api->getService('userData'); |
||
38 | |||
39 | $action = null; |
||
40 | // GET -> read |
||
41 | // PUT -> update |
||
42 | // DELETE -> delete |
||
43 | // POST -> create |
||
44 | |||
45 | if (!Subscription::getPaymentStatus()) { |
||
46 | throw new ServerErrorHttpException('Subscription is not active.Please contact your admin'); |
||
47 | } |
||
48 | |||
49 | switch (strtolower($request->getMethod())) { |
||
50 | case 'get': |
||
51 | $action = 'list'; |
||
52 | if (preg_match("/\/([0-9]+)(?=[^\/]*$)/", $request->getURI())) { |
||
53 | $action = 'read'; |
||
54 | } |
||
55 | break; |
||
56 | case 'post': |
||
57 | $action = 'create'; |
||
58 | break; |
||
59 | case 'delete': |
||
60 | $action = 'delete'; |
||
61 | break; |
||
62 | case 'put': |
||
63 | case 'patch': |
||
64 | $action = 'update'; |
||
65 | break; |
||
66 | default: |
||
67 | throw new ServerErrorHttpException('No Permission define for this action'); |
||
68 | break; |
||
69 | } |
||
70 | //do you have permision |
||
71 | if (!$userData->can($resource . '.' . $action)) { |
||
72 | throw new PermissionException('You dont have permission to run this action ' . $action . ' at ' . $resource); |
||
73 | } |
||
74 | } |
||
75 | |||
76 | 69 | return true; |
|
77 | } |
||
79 |