Conditions | 3 |
Paths | 3 |
Total Lines | 46 |
Code Lines | 33 |
Lines | 0 |
Ratio | 0 % |
Tests | 34 |
CRAP Score | 3 |
Changes | 0 |
1 | <?php |
||
29 | 4 | public function generate() : R2G { |
|
30 | |||
31 | 4 | if (count($this->getTeams()) === 0) { |
|
32 | 1 | throw new Exception('Couldn\'t generate 2R2G tournament because there are no teams in the tournament.'); |
|
33 | } |
||
34 | |||
35 | |||
36 | 3 | $round1 = $this->round('Round 1'); |
|
37 | 3 | $round2 = $this->round('Round 2'); |
|
38 | 3 | $round3 = $this->round('Round 3'); |
|
39 | |||
40 | 3 | $group_0_0 = $round1->group('0/0')->setInGame(2)->setType(Constants::ROUND_TWO); |
|
41 | 3 | $group_0_1 = $round2->group('0/1')->setInGame(2)->setType(Constants::ROUND_TWO); |
|
42 | 3 | $group_1_0 = $round2->group('1/0')->setInGame(2)->setType(Constants::ROUND_TWO); |
|
43 | 3 | $group_1_1 = $round3->group('1/1')->setInGame(2)->setType(Constants::ROUND_SPLIT)->setMaxSize(3); |
|
44 | 3 | $group_0_2 = $round3->group('0/2')->setInGame(2); // Implicit Round-robin |
|
45 | 3 | $group_2_0 = $round3->group('2/0')->setInGame(2); // Implicit Round-robin |
|
46 | |||
47 | 3 | $filter_win_1 = new TeamFilter('wins', '=', 1); |
|
48 | 3 | $filter_loss_1 = new TeamFilter('losses', '=', 1); |
|
49 | 3 | $filter_notProgressed = new TeamFilter('not-progressed'); |
|
50 | |||
51 | 3 | $this->splitTeams($round1); |
|
52 | |||
53 | 3 | if (count($this->getTeams()) % 4 === 2) { |
|
54 | 1 | $group_top = $round2->group('TOP')->setType(Constants::ROUND_TWO); |
|
55 | |||
56 | 1 | $filter_win_2 = new TeamFilter('wins', '=', 2, [$group_0_0, $group_top]); |
|
57 | 1 | $filter_loss_2 = new TeamFilter('losses', '=', 2, [$group_0_0, $group_top]); |
|
58 | 1 | $filter_win_1_both = new TeamFilter('wins', '=', 1, [$group_0_0, $group_top]); |
|
59 | 1 | $filter_loss_1_both = new TeamFilter('losses', '=', 1, [$group_0_0, $group_top]); |
|
60 | 1 | $group_0_0->progression($group_top, 0, 1)->addFilter($filter_win_1); // PROGRESS THE BEST WINNING TEAM |
|
61 | 1 | $group_0_0->progression($group_top, 0, 1)->addFilter($filter_loss_1); // PROGRESS THE BEST LOSING TEAM |
|
62 | 1 | $group_top->progression($group_2_0)->addFilter($filter_win_2); |
|
63 | 1 | $group_top->progression($group_0_2)->addFilter($filter_loss_2); |
|
64 | 1 | $group_top->progression($group_1_1)->addFilter($filter_win_1_both, $filter_loss_1_both); |
|
65 | } |
||
66 | |||
67 | 3 | $group_0_0->progression($group_0_1)->addFilter($filter_loss_1)->addFilter($filter_notProgressed); |
|
68 | 3 | $group_0_0->progression($group_1_0)->addFilter($filter_win_1)->addFilter($filter_notProgressed); |
|
69 | 3 | $group_0_1->progression($group_0_2)->addFilter($filter_loss_1); |
|
70 | 3 | $group_0_1->progression($group_1_1)->addFilter($filter_win_1); |
|
71 | 3 | $group_1_0->progression($group_2_0)->addFilter($filter_win_1); |
|
72 | 3 | $group_1_0->progression($group_1_1)->addFilter($filter_loss_1); |
|
73 | |||
74 | 3 | return $this; |
|
75 | |||
79 |