| Conditions | 6 |
| Paths | 17 |
| Total Lines | 60 |
| Code Lines | 33 |
| 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 |
||
| 86 | public function resultAction(Request $request, $namespace = 0, $start = null, $end = null) |
||
| 87 | { |
||
| 88 | // Will redirect back to index if the user has too high of an edit count. |
||
| 89 | $ret = $this->validateProjectAndUser($request, 'autoedits'); |
||
| 90 | if ($ret instanceof RedirectResponse) { |
||
| 91 | return $ret; |
||
| 92 | } else { |
||
| 93 | list($projectData, $user) = $ret; |
||
| 94 | } |
||
| 95 | |||
| 96 | // 'false' means the dates are optional and returned as 'false' if empty. |
||
| 97 | list($start, $end) = $this->getUTCFromDateParams($start, $end, false); |
||
| 98 | |||
| 99 | // We'll want to conditionally show some things in the view if there is a start date. |
||
| 100 | $hasStartDate = $start > 0; |
||
| 101 | |||
| 102 | // Format dates as needed by User model, if the date is present. |
||
| 103 | if ($start !== false) { |
||
| 104 | $start = date('Y-m-d', $start); |
||
| 105 | } |
||
| 106 | if ($end !== false) { |
||
| 107 | $end = date('Y-m-d', $end); |
||
| 108 | } |
||
| 109 | |||
| 110 | // Normalize default namespace. |
||
| 111 | if ($namespace == '') { |
||
| 112 | $namespace = 0; |
||
| 113 | } |
||
| 114 | |||
| 115 | $editCount = $user->countEdits($projectData, $namespace, $start, $end); |
||
| 116 | |||
| 117 | // Get individual counts of how many times each tool was used. |
||
| 118 | // This also includes a wikilink to the tool. |
||
| 119 | $toolCounts = $user->getAutomatedCounts($projectData, $namespace, $start, $end); |
||
| 120 | $toolsTotal = array_reduce($toolCounts, function ($a, $b) { |
||
| 121 | return $a + $b['count']; |
||
| 122 | }); |
||
| 123 | |||
| 124 | // Query to get combined (semi)automated using for all edits |
||
| 125 | // as some automated edits overlap. |
||
| 126 | $autoCount = $user->countAutomatedEdits($projectData, $namespace, $start, $end); |
||
| 127 | |||
| 128 | $ret = [ |
||
| 129 | 'xtPage' => 'autoedits', |
||
| 130 | 'user' => $user, |
||
| 131 | 'project' => $projectData, |
||
| 132 | 'toolCounts' => $toolCounts, |
||
| 133 | 'toolsTotal' => $toolsTotal, |
||
| 134 | 'autoCount' => $autoCount, |
||
| 135 | 'editCount' => $editCount, |
||
| 136 | 'autoPct' => $editCount ? ($autoCount / $editCount) * 100 : 0, |
||
| 137 | 'hasStartDate' => $hasStartDate, |
||
| 138 | 'start' => $start, |
||
| 139 | 'end' => $end, |
||
| 140 | 'namespace' => $namespace, |
||
| 141 | ]; |
||
| 142 | |||
| 143 | // Render the view with all variables set. |
||
| 144 | return $this->render('autoEdits/result.html.twig', $ret); |
||
| 145 | } |
||
| 146 | } |
||
| 147 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.