Conditions | 5 |
Paths | 12 |
Total Lines | 39 |
Code Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Tests | 24 |
CRAP Score | 5 |
Changes | 0 |
1 | <?php |
||
11 | 2 | public function generate() { |
|
12 | |||
13 | 2 | $this->allowSkip(); |
|
14 | |||
15 | 2 | $countTeams = count($this->getTeams()); |
|
16 | |||
17 | // CALCULATE BYES |
||
18 | 2 | $byes = 0; |
|
19 | 2 | if ( !\TournamentGenerator\isPowerOf2($countTeams) ) { |
|
20 | 1 | $nextPow = bindec(str_pad(1, strlen(decbin($countTeams))+1, 0, STR_PAD_RIGHT)); |
|
21 | 1 | $byes = $nextPow-$countTeams; |
|
22 | } |
||
23 | |||
24 | 2 | $roundsNum = log($countTeams+$byes, 2); // NUMBER OF ROUNDS |
|
25 | |||
26 | 2 | $startRound = $this->round('Start'); |
|
27 | |||
28 | 2 | $previousGroups = []; |
|
29 | |||
30 | 2 | for ($i=1; $i <= (($countTeams+$byes)/2); $i++) { |
|
31 | 2 | $g = $startRound->group('Round 1 '.$i)->setInGame(2)->setType(\TournamentGenerator\Constants::ROUND_TWO); |
|
32 | 2 | $previousGroups[] = $g; |
|
33 | } |
||
34 | |||
35 | 2 | $this->splitTeams(); |
|
36 | |||
37 | 2 | for ($r=2; $r <= $roundsNum; $r++) { |
|
38 | 2 | $groups = []; |
|
39 | 2 | $round = $this->round('Round '.$r); |
|
40 | 2 | for ($g=1; $g <= (($countTeams+$byes)/pow(2, $r)); $g++) { |
|
41 | 2 | $group = $round->group('Round '.$r.' - '.$g)->setInGame(2)->setType(\TournamentGenerator\Constants::ROUND_TWO); |
|
42 | 2 | $groups[] = $group; |
|
43 | 2 | array_shift($previousGroups)->progression($group, 0, 1); // PROGRESS FROM GROUP BEFORE |
|
44 | 2 | array_shift($previousGroups)->progression($group, 0, 1); // PROGREESS FROM GROUP BEFORE |
|
45 | } |
||
46 | 2 | $previousGroups = $groups; |
|
47 | } |
||
48 | |||
49 | 2 | return $this; |
|
50 | |||
54 |