| Conditions | 4 |
| Paths | 6 |
| Total Lines | 51 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 35 | public function list() |
||
| 36 | { |
||
| 37 | $futureGamesFormBuilder = $this->getFutureGamesFormBuilder(); |
||
| 38 | |||
| 39 | |||
| 40 | $pastGames = $this->getDoctrine() |
||
| 41 | ->getRepository(Game::class) |
||
| 42 | ->findPastGames() |
||
| 43 | ; |
||
| 44 | |||
| 45 | $user = $this->getUser(); |
||
| 46 | |||
| 47 | $userBets = $this->getDoctrine() |
||
| 48 | ->getRepository(UserBettingEntity::class) |
||
| 49 | ->findUserBettingByUserId($user, $pastGames) |
||
| 50 | ; |
||
| 51 | |||
| 52 | $pastGamesForm = []; |
||
| 53 | /** @var UserBettingEntity[] $gameId2UserBets */ |
||
| 54 | $gameId2UserBets = []; |
||
| 55 | /** @var UserBettingEntity $userBet */ |
||
| 56 | foreach ($userBets as $userBet) { |
||
| 57 | $gameId2UserBets[$userBet->getGame()->getId()] = $userBet; |
||
| 58 | } |
||
| 59 | /** @var Game[] $pastGames */ |
||
| 60 | |||
| 61 | foreach ($pastGames as $pastGame) { |
||
| 62 | |||
| 63 | $firstTeamUserResult = null; |
||
| 64 | $secondTeamUserResult = null; |
||
| 65 | if (isset($gameId2UserBets[$pastGame->getId()])) { |
||
| 66 | $firstTeamUserResult = $gameId2UserBets[$pastGame->getId()]->getFirstTeamResult(); |
||
| 67 | $secondTeamUserResult = $gameId2UserBets[$pastGame->getId()]->getSecondTeamResult(); |
||
| 68 | } |
||
| 69 | |||
| 70 | $pastGamesForm[] = new GamePastBetting( |
||
| 71 | $pastGame->getTeamFirst()->getName(), |
||
| 72 | $pastGame->getTeamSecond()->getName(), |
||
| 73 | $pastGame->getDate(), |
||
| 74 | (int)$pastGame->getFirstTeamResult(), |
||
| 75 | (int)$pastGame->getSecondTeamResult(), |
||
| 76 | $firstTeamUserResult, |
||
| 77 | $secondTeamUserResult |
||
| 78 | ); |
||
| 79 | } |
||
| 80 | |||
| 81 | return $this->render( |
||
| 82 | 'gamebetting/betting/betting.html.twig', |
||
| 83 | [ |
||
| 84 | 'futureGamesForm' => $futureGamesFormBuilder, |
||
| 85 | 'pastGamesForm' => $pastGamesForm |
||
| 86 | ] |
||
| 170 | } |