| Conditions | 5 |
| Paths | 12 |
| Total Lines | 39 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 24 |
| CRAP Score | 5 |
| Changes | 0 | ||
| 1 | <?php |
||
| 26 | 11 | public function generate() : SingleElimination { |
|
| 27 | |||
| 28 | 11 | $this->allowSkip(); |
|
| 29 | |||
| 30 | 11 | $countTeams = count($this->getTeams()); |
|
| 31 | |||
| 32 | // CALCULATE BYES |
||
| 33 | 11 | $byes = 0; |
|
| 34 | 11 | if (!Functions::isPowerOf2($countTeams)) { |
|
| 35 | 6 | $nextPow = Functions::nextPowerOf2($countTeams); |
|
| 36 | 6 | $byes = $nextPow - $countTeams; |
|
| 37 | } |
||
| 38 | |||
| 39 | 11 | $roundsNum = log($countTeams + $byes, 2); // NUMBER OF ROUNDS |
|
| 40 | |||
| 41 | 11 | $startRound = $this->round('Start'); |
|
| 42 | |||
| 43 | 11 | $previousGroups = []; |
|
| 44 | |||
| 45 | 11 | for ($i = 1; $i <= (($countTeams + $byes) / 2); $i++) { |
|
| 46 | 11 | $g = $startRound->group('Round 1 '.$i)->setInGame(2)->setType(Constants::ROUND_TWO); |
|
| 47 | 11 | $previousGroups[] = $g; |
|
| 48 | } |
||
| 49 | |||
| 50 | 11 | $this->splitTeams(); |
|
| 51 | |||
| 52 | 11 | for ($r = 2; $r <= $roundsNum; $r++) { |
|
| 53 | 11 | $groups = []; |
|
| 54 | 11 | $round = $this->round('Round '.$r); |
|
| 55 | 11 | for ($g = 1; $g <= (($countTeams + $byes) / (2 ** $r)); $g++) { |
|
| 56 | 11 | $group = $round->group('Round '.$r.' - '.$g)->setInGame(2)->setType(Constants::ROUND_TWO); |
|
| 57 | 11 | $groups[] = $group; |
|
| 58 | 11 | array_shift($previousGroups)->progression($group, 0, 1); // PROGRESS FROM GROUP BEFORE |
|
| 59 | 11 | array_shift($previousGroups)->progression($group, 0, 1); // PROGRESS FROM GROUP BEFORE |
|
| 60 | } |
||
| 61 | 11 | $previousGroups = $groups; |
|
| 62 | } |
||
| 63 | |||
| 64 | 11 | return $this; |
|
| 65 | |||
| 69 |