Conditions | 11 |
Paths | 194 |
Total Lines | 67 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
26 | public function index(HTTPRequest $request) |
||
27 | { |
||
28 | $stage = $request->param('Stage'); |
||
29 | if ($stage && in_array($stage, [Versioned::DRAFT, Versioned::LIVE])) { |
||
30 | Versioned::set_stage($stage); |
||
31 | } |
||
32 | // Check for a possible CORS preflight request and handle if necessary |
||
33 | // Refer issue 66: https://github.com/silverstripe/silverstripe-graphql/issues/66 |
||
34 | if ($request->httpMethod() === 'OPTIONS') { |
||
35 | return $this->handleOptions($request); |
||
36 | } |
||
37 | |||
38 | // Main query handling |
||
39 | try { |
||
40 | $manager = $this->getManager(); |
||
41 | $manager->addContext('token', $this->getToken()); |
||
42 | $method = null; |
||
43 | if ($request->isGET()) { |
||
44 | $method = 'GET'; |
||
45 | } elseif ($request->isPOST()) { |
||
46 | $method = 'POST'; |
||
47 | } |
||
48 | $manager->addContext('httpMethod', $method); |
||
49 | |||
50 | // Check and validate user for this request |
||
51 | $member = $this->getRequestUser($request); |
||
52 | |||
53 | if ($member) { |
||
54 | $manager->setMember($member); |
||
55 | } |
||
56 | |||
57 | $this->addOauthContexts($request, $manager); |
||
58 | |||
59 | // Parse input |
||
60 | list($query, $variables) = $this->getRequestQueryVariables($request); |
||
61 | |||
62 | // Run query |
||
63 | $result = $manager->query($query, $variables); |
||
64 | } catch (Exception $exception) { |
||
65 | $errorCode = $exception->getCode(); |
||
66 | |||
67 | // check for an http error, if we have one, return it straight away with correct http status code |
||
68 | if ($errorCode >= 400 || $errorCode <= 599) { |
||
69 | $result = [ |
||
70 | 'errors' => ['message' => $exception->getMessage(), 'code' => $exception->getCode()] |
||
71 | ]; |
||
72 | |||
73 | $response = $this->addCorsHeaders($request, new HTTPResponse(json_encode($result), $exception->getCode())); |
||
74 | return $response->addHeader('Content-Type', 'application/json'); |
||
75 | } |
||
76 | |||
77 | $error = ['message' => $exception->getMessage()]; |
||
78 | |||
79 | if (Director::isDev()) { |
||
80 | $error['code'] = $exception->getCode(); |
||
81 | $error['file'] = $exception->getFile(); |
||
82 | $error['line'] = $exception->getLine(); |
||
83 | $error['trace'] = $exception->getTrace(); |
||
84 | } |
||
85 | |||
86 | $result = [ |
||
87 | 'errors' => [$error] |
||
88 | ]; |
||
89 | } |
||
90 | |||
91 | $response = $this->addCorsHeaders($request, new HTTPResponse(json_encode($result))); |
||
92 | return $response->addHeader('Content-Type', 'application/json'); |
||
93 | } |
||
181 |
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