R2G   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 34
c 0
b 0
f 0
dl 0
loc 55
ccs 34
cts 34
cp 1
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A generate() 0 46 3
1
<?php
2
3
namespace TournamentGenerator\Preset;
4
5
use Exception;
6
use TournamentGenerator\Constants;
7
use TournamentGenerator\TeamFilter;
8
use TournamentGenerator\Tournament;
9
10
/**
11
 * Special (testing) tournament type
12
 *
13
 * Split teams into 3 groups after 2 games based on how many games did they win - first group has teams with 2 wins and 0 losses, second: 1 win 1 loss, third: 0 wins 2 losses.
14
 * These groups then play round-robin.
15
 *
16
 * @author  Tomáš Vojík <[email protected]>
17
 * @package TournamentGenerator\Preset
18
 * @since   0.1
19
 */
20
class R2G extends Tournament implements Preset
21
{
22
23
	/**
24
	 * Generate all the games
25
	 *
26
	 * @return $this
27
	 * @throws Exception
28
	 */
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
76
	}
77
78
}
79