Conditions | 9 |
Paths | 7 |
Total Lines | 46 |
Code Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 90 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
26 | public function call(Micro $api) |
||
27 | { |
||
28 | $router = $api->getService('router'); |
||
29 | $request = $api->getService('request'); |
||
30 | |||
31 | // explode() by / , postiion #1 is always the controller , so its the resource ^.^ |
||
32 | $matchRouter = explode('/', $router->getMatchedRoute()->getCompiledPattern()); |
||
33 | |||
34 | $resource = ucfirst(isset($matchRouter[2]) ? $matchRouter[2] : $matchRouter[1]); //2 is alwasy the controller of the router |
||
35 | $userData = $api->getService('userData'); |
||
36 | |||
37 | $action = null; |
||
38 | $method = strtolower($request->getMethod()); |
||
39 | |||
40 | // GET -> read |
||
41 | // PUT -> update |
||
42 | // DELETE -> delete |
||
43 | // POST -> create |
||
44 | switch ($method) { |
||
45 | case 'get': |
||
46 | $action = 'list'; |
||
47 | if (preg_match("/\/([0-9]+)(?=[^\/]*$)/", $request->getURI())) { |
||
48 | $action = 'read'; |
||
49 | } |
||
50 | break; |
||
51 | case 'post': |
||
52 | $action = 'create'; |
||
53 | break; |
||
54 | case 'delete': |
||
55 | $action = 'delete'; |
||
56 | break; |
||
57 | case 'put': |
||
58 | case 'patch': |
||
59 | $action = 'update'; |
||
60 | break; |
||
61 | default: |
||
62 | throw new InternalServerErrorException('No Permission define for this action ' . $method); |
||
63 | break; |
||
64 | } |
||
65 | |||
66 | //do you have permision |
||
67 | if (!$userData->can($resource . '.' . $action)) { |
||
68 | throw new UnauthorizedException('You dont have permission to run this action ' . $action . ' at ' . $resource); |
||
69 | } |
||
70 | |||
71 | return true; |
||
72 | } |
||
74 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths