| Conditions | 11 |
| Paths | 13 |
| Total Lines | 93 |
| Code Lines | 59 |
| Lines | 27 |
| Ratio | 29.03 % |
| Changes | 10 | ||
| Bugs | 3 | 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 |
||
| 12 | public function playAction() |
||
| 13 | { |
||
| 14 | $redirectFb = $this->checkFbRegistration($this->zfcUserAuthentication()->getIdentity(), $this->game); |
||
|
|
|||
| 15 | if ($redirectFb) { |
||
| 16 | return $redirectFb; |
||
| 17 | } |
||
| 18 | |||
| 19 | $user = $this->zfcUserAuthentication()->getIdentity(); |
||
| 20 | |||
| 21 | View Code Duplication | if (!$user && !$this->game->getAnonymousAllowed()) { |
|
| 22 | $redirect = urlencode( |
||
| 23 | $this->frontendUrl()->fromRoute( |
||
| 24 | $this->game->getClassType() . '/play', |
||
| 25 | array('id' => $this->game->getIdentifier()), |
||
| 26 | array('force_canonical' => true) |
||
| 27 | ) |
||
| 28 | ); |
||
| 29 | |||
| 30 | return $this->redirect()->toUrl( |
||
| 31 | $this->frontendUrl()->fromRoute( |
||
| 32 | 'zfcuser/register', |
||
| 33 | array() |
||
| 34 | ) . '?redirect='.$redirect |
||
| 35 | ); |
||
| 36 | } |
||
| 37 | |||
| 38 | if ($this->game->getOccurrenceType()=='datetime') { |
||
| 39 | $entry = $this->getGameService()->play($this->game, $user); |
||
| 40 | View Code Duplication | if (!$entry) { |
|
| 41 | // the user has already taken part of this game and the participation limit has been reached |
||
| 42 | $this->flashMessenger()->addMessage('Vous avez déjà participé'); |
||
| 43 | |||
| 44 | return $this->redirect()->toUrl( |
||
| 45 | $this->frontendUrl()->fromRoute( |
||
| 46 | 'instantwin/result', |
||
| 47 | array('id' => $this->game->getIdentifier()) |
||
| 48 | ) |
||
| 49 | ); |
||
| 50 | } |
||
| 51 | |||
| 52 | // update the winner attribute in entry. |
||
| 53 | $occurrence = $this->getGameService()->IsInstantWinner($this->game, $user); |
||
| 54 | |||
| 55 | $viewVariables = array( |
||
| 56 | 'occurrence' => $occurrence, |
||
| 57 | 'entry' => $entry |
||
| 58 | ); |
||
| 59 | } elseif ($this->game->getOccurrenceType()=='code') { |
||
| 60 | $form = $this->getServiceLocator()->get('playgroundgame_instantwinoccurrencecode_form'); |
||
| 61 | $form->setAttribute( |
||
| 62 | 'action', |
||
| 63 | $this->frontendUrl()->fromRoute( |
||
| 64 | 'instantwin/play', |
||
| 65 | array('id' => $this->game->getIdentifier()), |
||
| 66 | array('force_canonical' => true) |
||
| 67 | ) |
||
| 68 | ); |
||
| 69 | |||
| 70 | if ($this->getRequest()->isPost()) { |
||
| 71 | $form->setData($this->getRequest()->getPost()); |
||
| 72 | if ($form->isValid()) { |
||
| 73 | $data = $form->getData('code-input'); |
||
| 74 | $code = filter_var($data['code-input'], FILTER_SANITIZE_STRING); |
||
| 75 | $occurrence = $this->getGameService()->isInstantWinner($this->game, $user, $code); |
||
| 76 | if (!$occurrence) { |
||
| 77 | $this->flashMessenger()->addMessage('Le code entré est invalide ou a déjà été utilisé !'); |
||
| 78 | return $this->redirect()->toUrl( |
||
| 79 | $this->frontendUrl()->fromRoute( |
||
| 80 | 'instantwin/play', |
||
| 81 | array('id' => $this->game->getIdentifier()), |
||
| 82 | array('force_canonical' => true) |
||
| 83 | ) |
||
| 84 | ); |
||
| 85 | } else { |
||
| 86 | return $this->redirect()->toUrl( |
||
| 87 | $this->frontendUrl()->fromRoute( |
||
| 88 | 'instantwin/result', |
||
| 89 | array('id' => $this->game->getIdentifier()) |
||
| 90 | ) |
||
| 91 | ); |
||
| 92 | } |
||
| 93 | } |
||
| 94 | } |
||
| 95 | $viewVariables = array('form' => $form); |
||
| 96 | } |
||
| 97 | |||
| 98 | $viewModel = $this->buildView($this->game); |
||
| 99 | if ($viewModel instanceof \Zend\View\Model\ViewModel) { |
||
| 100 | $viewModel->setVariables($viewVariables); |
||
| 101 | } |
||
| 102 | |||
| 103 | return $viewModel; |
||
| 104 | } |
||
| 105 | |||
| 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: