| Conditions | 6 |
| Paths | 6 |
| Total Lines | 61 |
| Lines | 36 |
| Ratio | 59.02 % |
| Changes | 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 |
||
| 18 | public function playAction() |
||
| 19 | { |
||
| 20 | $playError = null; |
||
| 21 | $entry = $this->getGameService()->play($this->game, $this->user, $playError); |
||
| 22 | View Code Duplication | if (!$entry) { |
|
|
|
|||
| 23 | $reason = ""; |
||
| 24 | if ($playError === -1) { |
||
| 25 | // the user has already taken part to this game and the participation limit has been reached |
||
| 26 | $this->flashMessenger()->addMessage('Vous avez déjà participé'); |
||
| 27 | $reason = '?playLimitReached=1'; |
||
| 28 | $noEntryRedirect = $this->frontendUrl()->fromRoute( |
||
| 29 | $this->game->getClassType().'/result', |
||
| 30 | array( |
||
| 31 | 'id' => $this->game->getIdentifier(), |
||
| 32 | ) |
||
| 33 | ) .$reason; |
||
| 34 | } elseif ($playError === -2) { |
||
| 35 | // the user has not accepted the mandatory rules of the game |
||
| 36 | $this->flashMessenger()->addMessage('Vous devez accepter le réglement'); |
||
| 37 | $reason = '?NoOptin=1'; |
||
| 38 | $noEntryRedirect = $this->frontendUrl()->fromRoute( |
||
| 39 | $this->game->getClassType(), |
||
| 40 | array( |
||
| 41 | 'id' => $this->game->getIdentifier(), |
||
| 42 | ) |
||
| 43 | ) .$reason; |
||
| 44 | } elseif ($playError === -3) { |
||
| 45 | // the user has enough points to buy an entry to this game |
||
| 46 | $this->flashMessenger()->addMessage("Vous ne pouvez pas acheter la partie"); |
||
| 47 | $reason = '?NotPaid=1'; |
||
| 48 | $noEntryRedirect = $this->frontendUrl()->fromRoute( |
||
| 49 | $this->game->getClassType(), |
||
| 50 | array( |
||
| 51 | 'id' => $this->game->getIdentifier(), |
||
| 52 | ) |
||
| 53 | ) .$reason; |
||
| 54 | } |
||
| 55 | |||
| 56 | return $this->redirect()->toUrl($noEntryRedirect); |
||
| 57 | } |
||
| 58 | |||
| 59 | if ($this->getRequest()->isPost()) { |
||
| 60 | $data = $this->getRequest()->getPost()->toArray(); |
||
| 61 | $attempts = filter_var($data['attempts'], FILTER_SANITIZE_NUMBER_INT); |
||
| 62 | $mistakes = filter_var($data['mistakes'], FILTER_SANITIZE_NUMBER_INT); |
||
| 63 | $duration = filter_var($data['duration'], FILTER_SANITIZE_NUMBER_INT); |
||
| 64 | $dataSanitized = ['attempts' => $attempts, 'mistakes' => $mistakes, 'duration' => $duration]; |
||
| 65 | $this->getGameService()->memoryScore($this->game, $this->user, $dataSanitized); |
||
| 66 | |||
| 67 | return $this->redirect()->toUrl( |
||
| 68 | $this->frontendUrl()->fromRoute( |
||
| 69 | 'memory/result', |
||
| 70 | array('id' => $this->game->getIdentifier()) |
||
| 71 | ) |
||
| 72 | ); |
||
| 73 | } |
||
| 74 | |||
| 75 | $viewModel = $this->buildView($this->game); |
||
| 76 | |||
| 77 | return $viewModel; |
||
| 78 | } |
||
| 79 | |||
| 227 |
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.