| Conditions | 15 |
| Paths | 44 |
| Total Lines | 96 |
| Code Lines | 63 |
| Lines | 7 |
| Ratio | 7.29 % |
| Changes | 5 | ||
| Bugs | 1 | 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 |
||
| 169 | public function resultAction() |
||
| 170 | { |
||
| 171 | $identifier = $this->getEvent()->getRouteMatch()->getParam('id'); |
||
| 172 | $channel = $this->getEvent()->getRouteMatch()->getParam('channel'); |
||
| 173 | $user = $this->zfcUserAuthentication()->getIdentity(); |
||
| 174 | $sg = $this->getGameService(); |
||
| 175 | |||
| 176 | $game = $sg->checkGame($identifier); |
||
| 177 | if (!$game || $game->isClosed()) { |
||
| 178 | return $this->notFoundAction(); |
||
| 179 | } |
||
| 180 | |||
| 181 | $lastEntry = $sg->findLastInactiveEntry($game, $user); |
||
| 182 | View Code Duplication | if (!$lastEntry) { |
|
| 183 | return $this->redirect()->toUrl( |
||
| 184 | $this->frontendUrl()->fromRoute( |
||
| 185 | 'instantwin', |
||
| 186 | array('id' => $game->getIdentifier(), 'channel' => $channel), |
||
| 187 | array('force_canonical' => true) |
||
| 188 | ) |
||
| 189 | ); |
||
| 190 | } |
||
| 191 | $winner = $lastEntry->getWinner(); |
||
| 192 | $occurrence = null; |
||
| 193 | |||
| 194 | // On tente de récupèrer l'occurrence si elle existe pour avoir accés au lot associé |
||
| 195 | $occurrences = $sg->getInstantWinOccurrenceMapper()->findBy( |
||
| 196 | array('instantwin' => $game->getId(), 'entry' => $lastEntry->getId()) |
||
| 197 | ); |
||
| 198 | if (!empty($occurrences)) { |
||
| 199 | $occurrence = current($occurrences); |
||
| 200 | } |
||
| 201 | |||
| 202 | View Code Duplication | if (!$user && !$game->getAnonymousAllowed()) { |
|
| 203 | $redirect = urlencode( |
||
| 204 | $this->frontendUrl()->fromRoute( |
||
| 205 | 'instantwin/result', |
||
| 206 | array('id' => $game->getIdentifier(), 'channel' => $channel) |
||
| 207 | ) |
||
| 208 | ); |
||
| 209 | return $this->redirect()->toUrl( |
||
| 210 | $this->frontendUrl()->fromRoute( |
||
| 211 | 'zfcuser/register', |
||
| 212 | array('channel' => $channel) |
||
| 213 | ) . '?redirect='.$redirect |
||
| 214 | ); |
||
| 215 | } |
||
| 216 | |||
| 217 | $secretKey = strtoupper(substr(sha1(uniqid('pg_', true).'####'.time()), 0, 15)); |
||
| 218 | $socialLinkUrl = $this->frontendUrl()->fromRoute( |
||
| 219 | 'instantwin', |
||
| 220 | array('id' => $game->getIdentifier(), 'channel' => $channel), |
||
| 221 | array('force_canonical' => true) |
||
| 222 | ).'?key='.$secretKey; |
||
| 223 | // With core shortener helper |
||
| 224 | $socialLinkUrl = $this->shortenUrl()->shortenUrl($socialLinkUrl); |
||
| 225 | |||
| 226 | $form = $this->getServiceLocator()->get('playgroundgame_sharemail_form'); |
||
| 227 | $form->setAttribute('method', 'post'); |
||
| 228 | |||
| 229 | $statusMail = null; |
||
| 230 | if ($this->getRequest()->isPost()) { |
||
| 231 | $data = $this->getRequest()->getPost()->toArray(); |
||
| 232 | $form->setData($data); |
||
| 233 | if ($form->isValid()) { |
||
| 234 | if (isset($data['email1']) || isset($data['email2']) || isset($data['email3'])) { |
||
| 235 | $result = $this->getGameService()->sendShareMail($data, $game, $user, $lastEntry); |
||
| 236 | if ($result) { |
||
| 237 | $statusMail = true; |
||
| 238 | } |
||
| 239 | } |
||
| 240 | } |
||
| 241 | } |
||
| 242 | |||
| 243 | $prize = null; |
||
| 244 | if ($occurrence instanceof \PlaygroundGame\Entity\InstantWinOccurrence) { |
||
| 245 | $prize = $occurrence->getPrize(); |
||
| 246 | } |
||
| 247 | |||
| 248 | // buildView must be before sendMail because it adds the game template path to the templateStack |
||
| 249 | $viewModel = $this->buildView($game); |
||
| 250 | |||
| 251 | $this->getGameService()->sendMail($game, $user, $lastEntry, $prize); |
||
| 252 | |||
| 253 | if ($viewModel instanceof \Zend\View\Model\ViewModel) { |
||
| 254 | $viewModel->setVariables(array( |
||
| 255 | 'occurrence' => $occurrence, |
||
| 256 | 'statusMail' => $statusMail, |
||
| 257 | 'winner' => $winner, |
||
| 258 | 'form' => $form, |
||
| 259 | 'socialLinkUrl' => $socialLinkUrl, |
||
| 260 | 'secretKey' => $secretKey, |
||
| 261 | )); |
||
| 262 | } |
||
| 263 | return $viewModel; |
||
| 264 | } |
||
| 265 | |||
| 275 |
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: