| Conditions | 10 |
| Paths | 32 |
| Total Lines | 45 |
| Code Lines | 27 |
| 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 |
||
| 54 | public static function getResource(Request $request, JsonResponse $response) |
||
| 55 | { |
||
| 56 | $parts = explode('/', $request->getPathInfo()); |
||
| 57 | $parts = array_filter($parts); |
||
| 58 | |||
| 59 | $resource = null; |
||
| 60 | |||
| 61 | if (count($parts) === 2 && 'lineitems' === $parts[2]) { |
||
| 62 | $resource = new LtiLineItemsResource( |
||
| 63 | $request->query->get('t'), |
||
| 64 | $parts[1] |
||
| 65 | ); |
||
| 66 | } |
||
| 67 | |||
| 68 | if (count($parts) === 3 && 'lineitems' === $parts[2]) { |
||
| 69 | $resource = new LtiLineItemResource( |
||
| 70 | $request->query->get('t'), |
||
| 71 | $parts[1], |
||
| 72 | $parts[3] |
||
| 73 | ); |
||
| 74 | } |
||
| 75 | |||
| 76 | if (isset($parts[4]) && 'results' === $parts[4]) { |
||
| 77 | $resource = new LtiResultsResource( |
||
| 78 | $request->query->get('t'), |
||
| 79 | $parts[1], |
||
| 80 | $parts[3] |
||
| 81 | ); |
||
| 82 | } |
||
| 83 | |||
| 84 | if (isset($parts[4]) && 'scores' === $parts[4]) { |
||
| 85 | $resource = new LtiScoresResource( |
||
| 86 | $request->query->get('t'), |
||
| 87 | $parts[1], |
||
| 88 | $parts[3] |
||
| 89 | ); |
||
| 90 | } |
||
| 91 | |||
| 92 | if (!$resource) { |
||
| 93 | throw new NotFoundHttpException('Line item resource not found.'); |
||
| 94 | } |
||
| 95 | |||
| 96 | return $resource |
||
| 97 | ->setRequest($request) |
||
| 98 | ->setResponse($response); |
||
| 99 | } |
||
| 156 |