Conditions | 6 |
Paths | 24 |
Total Lines | 62 |
Code Lines | 41 |
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 |
||
31 | public function getTop(DateTime $date1Begin, DateTime $date1End, DateTime $date2Begin, DateTime $date2End, int $limit = 20): array |
||
32 | { |
||
33 | /** @var DwhPlayerRepository $dwhPlayerRepository */ |
||
34 | $dwhPlayerRepository = $this->dwhEntityManager->getRepository('VideoGamesRecords\DwhBundle\Entity\Player'); |
||
35 | |||
36 | /** @var CorePlayerRepository $dwhPlayerRepository */ |
||
37 | $corePlayerRepository = $this->defaultEntityManager->getRepository('VideoGamesRecords\CoreBundle\Entity\Player'); |
||
38 | |||
39 | $playerList1 = $dwhPlayerRepository->getTop( |
||
40 | $date1Begin, |
||
41 | $date1End, |
||
42 | $limit |
||
43 | ); |
||
44 | $playerList2 = $dwhPlayerRepository->getTop( |
||
45 | $date2Begin, |
||
46 | $date2End, |
||
47 | $limit |
||
48 | ); |
||
49 | |||
50 | // Get old rank |
||
51 | $oldRank = array(); |
||
52 | foreach ($playerList2 as $key => $row) { |
||
53 | $oldRank[$row['id']] = $key + 1; |
||
54 | } |
||
55 | |||
56 | $nbPostFromList = 0; |
||
57 | for ($i=0, $nb=count($playerList1) - 1; $i <= $nb; ++$i) { |
||
|
|||
58 | $idPlayer = $playerList1[$i]['id']; |
||
59 | if (isset($oldRank[$idPlayer])) { |
||
60 | $playerList1[$i]['oldRank'] = $oldRank[$idPlayer]; |
||
61 | } else { |
||
62 | $playerList1[$i]['oldRank'] = null; |
||
63 | } |
||
64 | $player = $corePlayerRepository->find($idPlayer); |
||
65 | $playerList1[$i]['player'] = $player; |
||
66 | $nbPostFromList += $playerList1[$i]['nb']; |
||
67 | } |
||
68 | |||
69 | $nbPlayer = 0; |
||
70 | try { |
||
71 | $nbPlayer = $dwhPlayerRepository->getTotalNbPlayer($date1Begin, $date1End); |
||
72 | } catch (NoResultException|NonUniqueResultException $e) { |
||
73 | } |
||
74 | |||
75 | $nbTotalPost = 0; |
||
76 | try { |
||
77 | $nbTotalPost = $dwhPlayerRepository->getTotalNbPostDay($date1Begin, $date1End); |
||
78 | } catch (NoResultException|NonUniqueResultException $e) { |
||
79 | } |
||
80 | |||
81 | $playerList = ToolsRanking::addRank( |
||
82 | $playerList1, |
||
83 | 'rank', |
||
84 | ['nb'], |
||
85 | true |
||
86 | ); |
||
87 | |||
88 | return array( |
||
89 | 'list' => $playerList, |
||
90 | 'nbPostFromList' => $nbPostFromList, |
||
91 | 'nb' => $nbPlayer, |
||
92 | 'nbTotalPost' => $nbTotalPost, |
||
93 | ); |
||
96 |