Conditions | 10 |
Paths | 8 |
Total Lines | 22 |
Code Lines | 13 |
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 |
||
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')) { |
||
52 | $report = [ |
||
53 | 'code' => (! $this->isHttpException($exception)) ?: $exception->getStatusCode(), |
||
54 | 'message' => class_basename($exception) . ' in ' . $exception->getFile() . ' on line ' . $exception->getLine(), |
||
55 | ]; |
||
56 | } |
||
57 | |||
58 | $response = response()->json([ |
||
59 | 'error' => (config('app.debug')) ? $exception->getMessage() : 'An unhandled exception was encountered with this request.', |
||
60 | 'exception' => ! isset($report) ?: $report, |
||
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.