Conditions | 10 |
Paths | 37 |
Total Lines | 29 |
Code Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
49 | public function report(ReportRequest $request) |
||
50 | { |
||
51 | /** @var Solution $solution */ |
||
52 | $solution = Solution::query()->find($request->getSolutionId()); |
||
53 | if ($solution) { |
||
|
|||
54 | $solution->result = $request->input('status'); |
||
55 | if ($request->input('memory_cost')) { |
||
56 | $solution->memory_cost = $request->input('memory_cost'); |
||
57 | } |
||
58 | if ($request->input('time_cost')) { |
||
59 | $solution->time_cost = $request->input('time_cost'); |
||
60 | } |
||
61 | if ($solution->isRuntimeError() && $request->input('runtime_info')) { |
||
62 | if ($info = $solution->runtimeInfo) { |
||
63 | $info->delete(); |
||
64 | } |
||
65 | $solution->runtimeInfo()->create(['content' => $request->input('runtime_info')]); |
||
66 | } |
||
67 | if ($solution->isCompileError() && $request->input('compile_info')) { |
||
68 | if ($info = $solution->compileInfo) { |
||
69 | $info->delete(); |
||
70 | } |
||
71 | $solution->compileInfo()->create(['content' => $request->input('compile_info')]); |
||
72 | } |
||
73 | $solution->save(); |
||
74 | } |
||
75 | |||
76 | return [ |
||
77 | 'code' => 0, |
||
78 | ]; |
||
95 |