Conditions | 4 |
Paths | 5 |
Total Lines | 61 |
Code Lines | 35 |
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 |
||
11 | public function generate() { |
||
12 | $this->allowSkip(); |
||
13 | |||
14 | $countTeams = count($this->getTeams()); |
||
15 | |||
16 | if ($countTeams < 3) throw new \Exception('Double elimination is possible for minimum of 3 teams - '.$countTeams.' teams given.'); |
||
17 | |||
18 | |||
19 | // CALCULATE BYES |
||
20 | $nextPow = 0; |
||
21 | $byes = $this->calcByes($countTeams, $nextPow); |
||
22 | |||
23 | $startRound = $this->round('Start round'); |
||
24 | |||
25 | $roundsNum = log($nextPow, 2)*2; |
||
26 | |||
27 | $startGroups = ($countTeams+$byes)/2; |
||
28 | |||
29 | $previousGroups = []; |
||
30 | $previousLosingGroups = []; |
||
31 | $groupIds = []; |
||
32 | $allGroups = []; |
||
33 | |||
34 | for ($i=1; $i <= $startGroups; $i++) { |
||
35 | $g = $startRound->group('Start group - '.$i)->setInGame(2)->setType(\TournamentGenerator\Constants::ROUND_TWO); |
||
36 | $allGroups[] = $g; |
||
37 | $groupIds[] = $g->id; |
||
38 | $previousGroups[] = $g; |
||
39 | } |
||
40 | |||
41 | // SPLIT TEAMS EVENLY |
||
42 | $this->splitTeams(); |
||
43 | |||
44 | for ($r=2; $r <= $roundsNum-1; $r++) { |
||
45 | $groups = []; |
||
46 | $losingGroups = []; |
||
47 | $round = $this->round('Round '.$r); |
||
48 | |||
49 | // GENERATE GROUPS AND PROGRESSIONS |
||
50 | |||
51 | // GENERATING LOSING AND WINNING SIDE |
||
52 | $lastLosingGroup = $this->generateLosingSide($r, $round, $allGroups, $previousLosingGroups, $previousGroups, $losingGroups); |
||
53 | $this->generateWinSide($r, $byes, $countTeams, $round, $allGroups, $groups, $lastWinningGroup, $previousGroups); |
||
54 | |||
55 | $previousGroups = $groups; |
||
56 | $previousLosingGroups = $losingGroups; |
||
57 | } |
||
58 | |||
59 | // LAST ROUND |
||
60 | $round = $this->round('Round '.$roundsNum.' - Finale'); |
||
61 | $groupFinal = $round->group('Round '.$r.' - finale')->setInGame(2)->setType(\TournamentGenerator\Constants::ROUND_TWO)->setOrder(1); |
||
62 | $allGroups[] = $groupFinal; |
||
63 | $lastLosingGroup->progression($groupFinal, 0, 1); |
||
64 | $lastWinningGroup->progression($groupFinal, 0, 1); |
||
65 | |||
66 | // REPEAT GROUP IF LOSING TEAM WON |
||
67 | $group = $round->group('Round '.$r.' - finale (2)')->setInGame(2)->setType(\TournamentGenerator\Constants::ROUND_TWO)->setOrder(1); |
||
68 | $twoLoss = new \TournamentGenerator\TeamFilter('losses', '=', 1, $allGroups); |
||
69 | $groupFinal->progression($group, 0, 2)->addFilter($twoLoss); |
||
70 | |||
71 | return $this; |
||
72 | |||
149 |