Conditions | 10 |
Paths | 6 |
Total Lines | 22 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
46 | public function render($request, Exception $exception) |
||
47 | { |
||
48 | if ($request->expectsJson() || $request->isJson() || $request->is(...config('pterodactyl.json_routes'))) { |
||
49 | $exception = $this->prepareException($exception); |
||
50 | |||
51 | if (config('app.debug') || $this->isHttpException($exception)) { |
||
52 | $displayError = $exception->getMessage(); |
||
53 | } else { |
||
54 | $displayError = 'An unhandled exception was encountered with this request.'; |
||
55 | } |
||
56 | |||
57 | $response = response()->json([ |
||
58 | 'error' => $displayError, |
||
59 | 'http_code' => (! $this->isHttpException($exception)) ?: $exception->getStatusCode(), |
||
60 | 'trace' => (! config('app.debug')) ? null : class_basename($exception) . ' in ' . $exception->getFile() . ' on line ' . $exception->getLine(), |
||
61 | ], ($this->isHttpException($exception)) ? $exception->getStatusCode() : 500, [], JSON_UNESCAPED_SLASHES); |
||
62 | |||
63 | parent::report($exception); |
||
|
|||
64 | } |
||
65 | |||
66 | return (isset($response)) ? $response : parent::render($request, $exception); |
||
67 | } |
||
68 | |||
85 |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.