| Conditions | 9 |
| Paths | 134 |
| Total Lines | 55 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 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 | $error = ['message' => $exception->getMessage()]; |
||
| 66 | |||
| 67 | if (Director::isDev()) { |
||
| 68 | $error['code'] = $exception->getCode(); |
||
| 69 | $error['file'] = $exception->getFile(); |
||
| 70 | $error['line'] = $exception->getLine(); |
||
| 71 | $error['trace'] = $exception->getTrace(); |
||
| 72 | } |
||
| 73 | |||
| 74 | $result = [ |
||
| 75 | 'errors' => [$error] |
||
| 76 | ]; |
||
| 77 | } |
||
| 78 | |||
| 79 | $response = $this->addCorsHeaders($request, new HTTPResponse(json_encode($result))); |
||
| 80 | return $response->addHeader('Content-Type', 'application/json'); |
||
| 81 | } |
||
| 164 |
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