| Conditions | 6 |
| Paths | 8 |
| Total Lines | 87 |
| Code Lines | 55 |
| Lines | 18 |
| Ratio | 20.69 % |
| 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 |
||
| 115 | public function resultAction($project, $type, $username) |
||
| 116 | { |
||
| 117 | $projectData = ProjectRepository::getProject($project, $this->container); |
||
| 118 | |||
| 119 | if (!$projectData->exists()) { |
||
| 120 | $this->addFlash('notice', ['invalid-project', $project]); |
||
| 121 | return $this->redirectToRoute('rfx'); |
||
| 122 | } |
||
| 123 | |||
| 124 | $db = $projectData->getDatabaseName(); |
||
| 125 | $domain = $projectData->getDomain(); |
||
| 126 | |||
| 127 | if ($this->getParameter('rfx')[$domain] === null) { |
||
| 128 | $this->addFlash('notice', ['invalid-project-cant-use', $project]); |
||
| 129 | return $this->redirectToRoute('rfx'); |
||
| 130 | } |
||
| 131 | |||
| 132 | // Construct the page name |
||
| 133 | if (!isset($this->getParameter('rfx')[$domain]['pages'][$type])) { |
||
| 134 | $pagename = ''; |
||
| 135 | } else { |
||
| 136 | $pagename = $this->getParameter('rfx')[$domain]['pages'][$type]; |
||
| 137 | } |
||
| 138 | |||
| 139 | $user = UserRepository::getUser($username, $this->container); |
||
|
1 ignored issue
–
show
|
|||
| 140 | |||
| 141 | $pagename .= '/'.$user->getUsername(); |
||
| 142 | $page = new Page($projectData, $pagename); |
||
| 143 | $pageRepo = new PagesRepository(); |
||
| 144 | $pageRepo->setContainer($this->container); |
||
|
1 ignored issue
–
show
|
|||
| 145 | $page->setRepository($pageRepo); |
||
| 146 | |||
| 147 | $text = $page->getWikitext(); |
||
| 148 | |||
| 149 | View Code Duplication | if (!isset($text)) { |
|
| 150 | $this->addFlash('notice', ['no-result', $pagename]); |
||
| 151 | return $this->redirectToRoute( |
||
| 152 | 'rfxAnalysisProject', |
||
| 153 | [ |
||
| 154 | 'project' => $projectData->getDatabaseName() |
||
| 155 | ] |
||
| 156 | ); |
||
| 157 | } |
||
| 158 | |||
| 159 | $rfx = new RFX( |
||
| 160 | $text, |
||
| 161 | $this->getParameter('rfx')[$domain]['sections'], |
||
| 162 | 'User' |
||
| 163 | ); |
||
| 164 | $support = $rfx->getSection('support'); |
||
| 165 | $oppose = $rfx->getSection('oppose'); |
||
| 166 | $neutral = $rfx->getSection('neutral'); |
||
| 167 | $dup = $rfx->getDuplicates(); |
||
| 168 | |||
| 169 | $total = count($support) + count($oppose) + count($neutral); |
||
| 170 | |||
| 171 | View Code Duplication | if ($total === 0) { |
|
| 172 | $this->addFlash('notice', ['no-result', $pagename]); |
||
| 173 | return $this->redirectToRoute( |
||
| 174 | 'rfxAnalysisProject', |
||
| 175 | [ |
||
| 176 | 'project' => $projectData->getDatabaseName(), |
||
| 177 | ] |
||
| 178 | ); |
||
| 179 | } |
||
| 180 | |||
| 181 | $end = $rfx->getEndDate(); |
||
| 182 | |||
| 183 | // replace this example code with whatever you need |
||
| 184 | return $this->render( |
||
| 185 | 'rfxAnalysis/result.html.twig', |
||
| 186 | [ |
||
| 187 | 'xtTitle' => $user->getUsername(), |
||
| 188 | 'xtPage' => 'rfx', |
||
| 189 | 'project' => $projectData, |
||
| 190 | 'user' => $user, |
||
| 191 | 'page' => $page, |
||
| 192 | 'type' => $type, |
||
| 193 | 'support' => $support, |
||
| 194 | 'oppose' => $oppose, |
||
| 195 | 'neutral' => $neutral, |
||
| 196 | 'total' => $total, |
||
| 197 | 'duplicates' => $dup, |
||
| 198 | 'enddate' => $end, |
||
| 199 | ] |
||
| 200 | ); |
||
| 201 | } |
||
| 202 | } |
||
| 203 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.