| Conditions | 13 |
| Paths | 43 |
| Total Lines | 88 |
| Code Lines | 57 |
| Lines | 23 |
| Ratio | 26.14 % |
| Changes | 7 | ||
| 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 |
||
| 106 | public function resultAction() |
||
| 107 | { |
||
| 108 | $user = $this->zfcUserAuthentication()->getIdentity(); |
||
| 109 | $lastEntry = $this->getGameService()->findLastInactiveEntry($this->game, $user); |
||
| 110 | |||
| 111 | View Code Duplication | if (!$lastEntry) { |
|
| 112 | return $this->redirect()->toUrl( |
||
| 113 | $this->frontendUrl()->fromRoute( |
||
| 114 | 'instantwin', |
||
| 115 | array('id' => $this->game->getIdentifier(), ), |
||
| 116 | array('force_canonical' => true) |
||
| 117 | ) |
||
| 118 | ); |
||
| 119 | } |
||
| 120 | $winner = $lastEntry->getWinner(); |
||
| 121 | $occurrence = null; |
||
| 122 | |||
| 123 | // On tente de récupèrer l'occurrence si elle existe pour avoir accés au lot associé |
||
| 124 | $occurrences = $this->getGameService()->getInstantWinOccurrenceMapper()->findBy( |
||
| 125 | array('instantwin' => $this->game->getId(), 'entry' => $lastEntry->getId()) |
||
| 126 | ); |
||
| 127 | if (!empty($occurrences)) { |
||
| 128 | $occurrence = current($occurrences); |
||
| 129 | } |
||
| 130 | |||
| 131 | View Code Duplication | if (!$user && !$this->game->getAnonymousAllowed()) { |
|
| 132 | $redirect = urlencode( |
||
| 133 | $this->frontendUrl()->fromRoute( |
||
| 134 | 'instantwin/result', |
||
| 135 | array('id' => $this->game->getIdentifier(), ) |
||
| 136 | ) |
||
| 137 | ); |
||
| 138 | return $this->redirect()->toUrl( |
||
| 139 | $this->frontendUrl()->fromRoute( |
||
| 140 | 'zfcuser/register', |
||
| 141 | array() |
||
| 142 | ) . '?redirect='.$redirect |
||
| 143 | ); |
||
| 144 | } |
||
| 145 | |||
| 146 | $secretKey = strtoupper(substr(sha1(uniqid('pg_', true).'####'.time()), 0, 15)); |
||
| 147 | $socialLinkUrl = $this->frontendUrl()->fromRoute( |
||
| 148 | 'instantwin', |
||
| 149 | array('id' => $this->game->getIdentifier(), ), |
||
| 150 | array('force_canonical' => true) |
||
| 151 | ).'?key='.$secretKey; |
||
| 152 | // With core shortener helper |
||
| 153 | $socialLinkUrl = $this->shortenUrl()->shortenUrl($socialLinkUrl); |
||
| 154 | |||
| 155 | $form = $this->getServiceLocator()->get('playgroundgame_sharemail_form'); |
||
| 156 | $form->setAttribute('method', 'post'); |
||
| 157 | |||
| 158 | $statusMail = null; |
||
| 159 | if ($this->getRequest()->isPost()) { |
||
| 160 | $data = $this->getRequest()->getPost()->toArray(); |
||
| 161 | $form->setData($data); |
||
| 162 | if ($form->isValid()) { |
||
| 163 | if (isset($data['email1']) || isset($data['email2']) || isset($data['email3'])) { |
||
| 164 | $result = $this->getGameService()->sendShareMail($data, $this->game, $user, $lastEntry); |
||
| 165 | if ($result) { |
||
| 166 | $statusMail = true; |
||
| 167 | } |
||
| 168 | } |
||
| 169 | } |
||
| 170 | } |
||
| 171 | |||
| 172 | $prize = null; |
||
| 173 | if ($occurrence instanceof \PlaygroundGame\Entity\InstantWinOccurrence) { |
||
| 174 | $prize = $occurrence->getPrize(); |
||
| 175 | } |
||
| 176 | |||
| 177 | // buildView must be before sendMail because it adds the game template path to the templateStack |
||
| 178 | $viewModel = $this->buildView($this->game); |
||
| 179 | |||
| 180 | $this->getGameService()->sendMail($this->game, $user, $lastEntry, $prize); |
||
| 181 | |||
| 182 | if ($viewModel instanceof \Zend\View\Model\ViewModel) { |
||
| 183 | $viewModel->setVariables(array( |
||
| 184 | 'occurrence' => $occurrence, |
||
| 185 | 'statusMail' => $statusMail, |
||
| 186 | 'winner' => $winner, |
||
| 187 | 'form' => $form, |
||
| 188 | 'socialLinkUrl' => $socialLinkUrl, |
||
| 189 | 'secretKey' => $secretKey, |
||
| 190 | )); |
||
| 191 | } |
||
| 192 | return $viewModel; |
||
| 193 | } |
||
| 194 | |||
| 204 |
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: