Passed
Push — master ( f2e9a4...5d9f44 )
by Tomáš
01:51
created
src/TournamentGenerator/TeamFilter.php 1 patch
Braces   +37 added lines, -13 removed lines patch added patch discarded remove patch
@@ -44,9 +44,15 @@  discard block
 block discarded – undo
44 44
 	private $groups = [];
45 45
 
46 46
 	function __construct(string $what = 'points', string $how = '>', $val = 0, $groups = []){
47
-		if (in_array(strtolower($what), ['points', 'score', 'wins', 'draws', 'losses', 'second', 'third', 'team', 'notprogressed', 'progressed'])) $this->what = strtolower($what);
48
-		if (in_array($how, ['>', '<', '>=', '<=', '=', '!='])) $this->how = $how;
49
-		if ((gettype($val) === 'integer' && strtolower($what) !== 'team') || ($val instanceof Team && strtolower($what) === 'team')) $this->val = $val;
47
+		if (in_array(strtolower($what), ['points', 'score', 'wins', 'draws', 'losses', 'second', 'third', 'team', 'notprogressed', 'progressed'])) {
48
+			$this->what = strtolower($what);
49
+		}
50
+		if (in_array($how, ['>', '<', '>=', '<=', '=', '!='])) {
51
+			$this->how = $how;
52
+		}
53
+		if ((gettype($val) === 'integer' && strtolower($what) !== 'team') || ($val instanceof Team && strtolower($what) === 'team')) {
54
+			$this->val = $val;
55
+		}
50 56
 		$this->groups = array_map(function($a) { return $a->id; }, array_filter($groups, function($a) {return ($a instanceof Group);}));
51 57
 	}
52 58
 	public function __toString() {
@@ -54,11 +60,17 @@  discard block
 block discarded – undo
54 60
 	}
55 61
 
56 62
 	public function validate(Team $team, $groupsId, string $operation = 'sum', Group $from = null) {
57
-		if (count($this->groups) > 0) $groupsId = array_unique(array_merge($this->groups, (gettype($groupsId) === 'array' ? $groupsId : [$groupsId])), SORT_REGULAR);
63
+		if (count($this->groups) > 0) {
64
+			$groupsId = array_unique(array_merge($this->groups, (gettype($groupsId) === 'array' ? $groupsId : [$groupsId])), SORT_REGULAR);
65
+		}
58 66
 
59
-		if ($this->what == 'team') return ($this->how === '!=' ? !$this->validateTeam($team) : $this->validateTeam($team));
60
-		elseif ($this->what == 'notprogressed') return !$this->validateProgressed($team, $from);
61
-		elseif ($this->what == 'progressed') return $this->validateProgressed($team, $from);
67
+		if ($this->what == 'team') {
68
+			return ($this->how === '!=' ? !$this->validateTeam($team) : $this->validateTeam($team));
69
+		} elseif ($this->what == 'notprogressed') {
70
+			return !$this->validateProgressed($team, $from);
71
+		} elseif ($this->what == 'progressed') {
72
+			return $this->validateProgressed($team, $from);
73
+		}
62 74
 
63 75
 		return $this->validateCalc($team, $groupsId, $operation);
64 76
 	}
@@ -67,13 +79,19 @@  discard block
 block discarded – undo
67 79
 		return $this->val === $team;
68 80
 	}
69 81
 	private function validateProgressed(Team $team, Group $from = null) {
70
-		if ($from === null) throw new \Exception('Group $from was not defined.');
82
+		if ($from === null) {
83
+			throw new \Exception('Group $from was not defined.');
84
+		}
71 85
 		return $from->isProgressed($team);
72 86
 	}
73 87
 	private function validateCalc(Team $team, $groupsId, string $operation = 'sum') {
74
-		if (gettype($groupsId) === 'array' && !in_array(strtolower($operation), ['sum', 'avg', 'max', 'min'])) throw new \Exception('Unknown operation of '.$operation.'. Only "sum", "avg", "min", "max" possible.');
88
+		if (gettype($groupsId) === 'array' && !in_array(strtolower($operation), ['sum', 'avg', 'max', 'min'])) {
89
+			throw new \Exception('Unknown operation of '.$operation.'. Only "sum", "avg", "min", "max" possible.');
90
+		}
75 91
 		$comp = 0;
76
-		if (gettype($groupsId) === 'string') $groupsId = [$groupsId];
92
+		if (gettype($groupsId) === 'string') {
93
+			$groupsId = [$groupsId];
94
+		}
77 95
 		switch (strtolower($operation)) {
78 96
 			case 'sum': $comp = $this->calcSum($team, $groupsId); break;
79 97
 			case 'avg': $comp = $this->calcSum($team, $groupsId)/count($groupsId); break;
@@ -95,21 +113,27 @@  discard block
 block discarded – undo
95 113
 	private function calcSum(Team $team, $groupsId) {
96 114
 		$sum = 0;
97 115
 		foreach ($groupsId as $id) {
98
-			if (isset($team->groupResults[$id])) $sum += $team->groupResults[$id][$this->what];
116
+			if (isset($team->groupResults[$id])) {
117
+				$sum += $team->groupResults[$id][$this->what];
118
+			}
99 119
 		}
100 120
 		return $sum;
101 121
 	}
102 122
 	private function calcMax(Team $team, $groupsId) {
103 123
 		$max = null;
104 124
 		foreach ($groupsId as $id) {
105
-			if (isset($team->groupResults[$id]) && ($team->groupResults[$id][$this->what] > $max || $max === null)) $max = $team->groupResults[$id][$this->what];
125
+			if (isset($team->groupResults[$id]) && ($team->groupResults[$id][$this->what] > $max || $max === null)) {
126
+				$max = $team->groupResults[$id][$this->what];
127
+			}
106 128
 		}
107 129
 		return $max;
108 130
 	}
109 131
 	private function calcMin(Team $team, $groupsId) {
110 132
 		$min = null;
111 133
 		foreach ($groupsId as $id) {
112
-			if (isset($team->groupResults[$id]) && ($team->groupResults[$id][$this->what] < $min || $min === null)) $min = $team->groupResults[$id][$this->what];
134
+			if (isset($team->groupResults[$id]) && ($team->groupResults[$id][$this->what] < $min || $min === null)) {
135
+				$min = $team->groupResults[$id][$this->what];
136
+			}
113 137
 		}
114 138
 		return $min;
115 139
 	}
Please login to merge, or discard this patch.
src/TournamentGenerator/Progression.php 1 patch
Braces   +18 added lines, -7 removed lines patch added patch discarded remove patch
@@ -27,18 +27,26 @@  discard block
 block discarded – undo
27 27
 
28 28
 	public function addFilter(...$filters) {
29 29
 		foreach ($filters as $filter) {
30
-			if (!$filter instanceof TeamFilter) throw new \Exception('Trying to add filter which is not an instance of TeamFilter.');
30
+			if (!$filter instanceof TeamFilter) {
31
+				throw new \Exception('Trying to add filter which is not an instance of TeamFilter.');
32
+			}
31 33
 			$this->filters[] = $filter;
32 34
 		}
33 35
 		return $this;
34 36
 	}
35 37
 
36 38
 	public function progress(bool $blank = false) {
37
-		if ($blank) $teams = $this->from->isPlayed() ? $this->from->sortTeams($this->filters) : $this->from->simulate($this->filters);
38
-		else $teams = $this->from->sortTeams($this->filters);
39
+		if ($blank) {
40
+			$teams = $this->from->isPlayed() ? $this->from->sortTeams($this->filters) : $this->from->simulate($this->filters);
41
+		} else {
42
+			$teams = $this->from->sortTeams($this->filters);
43
+		}
39 44
 
40
-		if (count($this->filters) === 0 || $this->len !== null || $this->start !== 0) $next = array_splice($teams, $this->start, ($this->len === null ? count($teams) : $this->len));
41
-		else $next = $teams;
45
+		if (count($this->filters) === 0 || $this->len !== null || $this->start !== 0) {
46
+			$next = array_splice($teams, $this->start, ($this->len === null ? count($teams) : $this->len));
47
+		} else {
48
+			$next = $teams;
49
+		}
42 50
 
43 51
 		$i = 1;
44 52
 
@@ -46,12 +54,15 @@  discard block
 block discarded – undo
46 54
 			if ($blank) {
47 55
 				$this->to->addTeam(new BlankTeam($this.' - '.$i, $team));
48 56
 				$i++;
57
+			} else {
58
+				$team->sumPoints += $this->from->progressPoints;
49 59
 			}
50
-			else $team->sumPoints += $this->from->progressPoints;
51 60
 		}
52 61
 
53 62
 		$this->from->addProgressed($next);
54
-		if (!$blank) $this->to->addTeam($next);
63
+		if (!$blank) {
64
+			$this->to->addTeam($next);
65
+		}
55 66
 		return $this;
56 67
 	}
57 68
 
Please login to merge, or discard this patch.
src/TournamentGenerator/Utilis/Simulator.php 1 patch
Braces   +12 added lines, -4 removed lines patch added patch discarded remove patch
@@ -18,7 +18,9 @@  discard block
 block discarded – undo
18 18
 			$game->setResults($results);
19 19
 		}
20 20
 		$return = $group->sortTeams($filters);
21
-		if (!$reset) return $return;
21
+		if (!$reset) {
22
+			return $return;
23
+		}
22 24
 		foreach ($group->getGames() as $game) {
23 25
 			$game->resetResults();
24 26
 		}
@@ -27,14 +29,18 @@  discard block
 block discarded – undo
27 29
 
28 30
 	public static function simulateRound(\TournamentGenerator\Round $round) {
29 31
 		foreach ($round->getGroups() as $group) {
30
-			if ($group->isPlayed()) continue;
32
+			if ($group->isPlayed()) {
33
+				continue;
34
+			}
31 35
 			$group->simulate([], false);
32 36
 		}
33 37
 		return true;
34 38
 	}
35 39
 
36 40
 	public static function simulateTournament(\TournamentGenerator\Tournament $tournament) {
37
-		if (count($tournament->getCategories()) === 0 && count($tournament->getRounds()) === 0) throw new \Exception('There are no rounds or categories to simulate games from.');
41
+		if (count($tournament->getCategories()) === 0 && count($tournament->getRounds()) === 0) {
42
+			throw new \Exception('There are no rounds or categories to simulate games from.');
43
+		}
38 44
 
39 45
 		$games = [];
40 46
 
@@ -55,7 +61,9 @@  discard block
 block discarded – undo
55 61
 
56 62
 	public static function simulateTournamentReal(\TournamentGenerator\Tournament $tournament) {
57 63
 		$games = [];
58
-		if (count($tournament->getCategories()) === 0 && count($tournament->getRounds()) === 0) throw new \Exception('There are no rounds or categories to simulate games from.');
64
+		if (count($tournament->getCategories()) === 0 && count($tournament->getRounds()) === 0) {
65
+			throw new \Exception('There are no rounds or categories to simulate games from.');
66
+		}
59 67
 
60 68
 		foreach ($tournament->getCategories() as $category) {
61 69
 			$games = array_merge($games, $category->genGamesSimulate());
Please login to merge, or discard this patch.
src/TournamentGenerator/Utilis/Sorter/Teams.php 1 patch
Braces   +24 added lines, -8 removed lines patch added patch discarded remove patch
@@ -9,19 +9,27 @@  discard block
 block discarded – undo
9 9
 {
10 10
 
11 11
 	public static function sortGroup(array &$teams, \TournamentGenerator\Group $group, string $ordering = \TournamentGenerator\Constants::POINTS) {
12
-		if (!in_array($ordering, \TournamentGenerator\Constants::OrderingTypes)) throw new \Exception('Unknown ordering type `'.$ordering.'`');
12
+		if (!in_array($ordering, \TournamentGenerator\Constants::OrderingTypes)) {
13
+			throw new \Exception('Unknown ordering type `'.$ordering.'`');
14
+		}
13 15
 
14 16
 		switch ($ordering) {
15 17
 			case \TournamentGenerator\Constants::POINTS:{
16 18
 				uasort($teams, function($a, $b) use ($group) {
17
-					if ($a->groupResults[$group->id]["points"] === $b->groupResults[$group->id]["points"] && $a->groupResults[$group->id]["score"] === $b->groupResults[$group->id]["score"]) return 0;
18
-					if ($a->groupResults[$group->id]["points"] === $b->groupResults[$group->id]["points"]) return ($a->groupResults[$group->id]["score"] > $b->groupResults[$group->id]["score"] ? -1 : 1);
19
+					if ($a->groupResults[$group->id]["points"] === $b->groupResults[$group->id]["points"] && $a->groupResults[$group->id]["score"] === $b->groupResults[$group->id]["score"]) {
20
+						return 0;
21
+					}
22
+					if ($a->groupResults[$group->id]["points"] === $b->groupResults[$group->id]["points"]) {
23
+						return ($a->groupResults[$group->id]["score"] > $b->groupResults[$group->id]["score"] ? -1 : 1);
24
+					}
19 25
 					return ($a->groupResults[$group->id]["points"] > $b->groupResults[$group->id]["points"] ? -1 : 1);
20 26
 				});
21 27
 				break;}
22 28
 			case \TournamentGenerator\Constants::SCORE:{
23 29
 				uasort($teams, function($a, $b) use ($group) {
24
-					if ($a->groupResults[$group->id]["score"] === $b->groupResults[$group->id]["score"]) return 0;
30
+					if ($a->groupResults[$group->id]["score"] === $b->groupResults[$group->id]["score"]) {
31
+						return 0;
32
+					}
25 33
 					return ($a->groupResults[$group->id]["score"] > $b->groupResults[$group->id]["score"] ? -1 : 1);
26 34
 				});
27 35
 				break;}
@@ -30,21 +38,29 @@  discard block
 block discarded – undo
30 38
 		return $teams;
31 39
 	}
32 40
 	public static function sortRound(array &$teams, \TournamentGenerator\Round $round, string $ordering = \TournamentGenerator\Constants::POINTS) {
33
-		if (!in_array($ordering, \TournamentGenerator\Constants::OrderingTypes)) throw new \Exception('Unknown ordering type `'.$ordering.'`');
41
+		if (!in_array($ordering, \TournamentGenerator\Constants::OrderingTypes)) {
42
+			throw new \Exception('Unknown ordering type `'.$ordering.'`');
43
+		}
34 44
 
35 45
 		$groupsIds = $round->getGroupsIds();
36 46
 
37 47
 		switch ($ordering) {
38 48
 			case \TournamentGenerator\Constants::POINTS:{
39 49
 				uasort($teams, function($a, $b) use ($groupsIds) {
40
-					if ($a->sumPoints($groupsIds) === $b->sumPoints($groupsIds) && $a->sumScore($groupsIds) === $b->sumScore($groupsIds)) return 0;
41
-					if ($a->sumPoints($groupsIds) === $b->sumPoints($groupsIds)) return ($a->sumScore($groupsIds) > $b->sumScore($groupsIds) ? -1 : 1);
50
+					if ($a->sumPoints($groupsIds) === $b->sumPoints($groupsIds) && $a->sumScore($groupsIds) === $b->sumScore($groupsIds)) {
51
+						return 0;
52
+					}
53
+					if ($a->sumPoints($groupsIds) === $b->sumPoints($groupsIds)) {
54
+						return ($a->sumScore($groupsIds) > $b->sumScore($groupsIds) ? -1 : 1);
55
+					}
42 56
 					return ($a->sumPoints($groupsIds) > $b->sumPoints($groupsIds) ? -1 : 1);
43 57
 				});
44 58
 				break;}
45 59
 			case \TournamentGenerator\Constants::SCORE:{
46 60
 				uasort($teams, function($a, $b) use ($groupsIds) {
47
-					if ($a->sumScore($groupsIds) === $b->sumScore($groupsIds)) return 0;
61
+					if ($a->sumScore($groupsIds) === $b->sumScore($groupsIds)) {
62
+						return 0;
63
+					}
48 64
 					return ($a->sumScore($groupsIds) > $b->sumScore($groupsIds) ? -1 : 1);
49 65
 				});
50 66
 				break;}
Please login to merge, or discard this patch.
src/TournamentGenerator/Utilis/Sorter/Games.php 1 patch
Braces   +27 added lines, -9 removed lines patch added patch discarded remove patch
@@ -36,7 +36,9 @@  discard block
 block discarded – undo
36 36
 
37 37
 		$games = $this->group->getGames();
38 38
 
39
-		if (count($games) <= 4) return $games;
39
+		if (count($games) <= 4) {
40
+			return $games;
41
+		}
40 42
 
41 43
 		$this->games = [];
42 44
 
@@ -48,24 +50,34 @@  discard block
 block discarded – undo
48 50
 		while (count($games) > 0) {
49 51
 			// CYCLE 1
50 52
 			// TEAM WHICH DIDN'T PLAY IN LAST GAME (< 4)
51
-			if ($this->cycle1($games, $teams)) continue;
53
+			if ($this->cycle1($games, $teams)) {
54
+				continue;
55
+			}
52 56
 
53 57
 			// CYCLE 2
54 58
 			// NOT TEAM WHICH PLAYED IN LAST TWO GAMES (NOT 6 or 7)
55
-			if ($this->cycle2($games, $teams)) continue;
59
+			if ($this->cycle2($games, $teams)) {
60
+				continue;
61
+			}
56 62
 
57 63
 			// CYCLE 3
58 64
 			// NOT TEAM WHICH PLAYED IN LAST THREE GAMES (NOT 7)
59 65
 			// TEAMS THAT DIDN'T PLAY IN LAST GAME WILL PLAY THIS GAME (< 4)
60
-			if ($this->cycle3($games, $teams)) continue;
66
+			if ($this->cycle3($games, $teams)) {
67
+				continue;
68
+			}
61 69
 
62 70
 			// CYCLE 4
63 71
 			// NOT TEAM WHICH PLAYED IN LAST THREE GAMES (NOT 7)
64
-			if ($this->cycle4($games, $teams)) continue;
72
+			if ($this->cycle4($games, $teams)) {
73
+				continue;
74
+			}
65 75
 
66 76
 			// CYCLE 5
67 77
 			// TEAMS THAT DIDN'T PLAY IN LAST GAME WILL PLAY THIS GAME (< 4)
68
-			if ($this->cycle5($games, $teams)) continue;
78
+			if ($this->cycle5($games, $teams)) {
79
+				continue;
80
+			}
69 81
 
70 82
 			// CYCLE 6
71 83
 			// FIRST AVAILABLE GAME
@@ -174,11 +186,17 @@  discard block
 block discarded – undo
174 186
 		$requiredTeams = array_filter($teams, function($a) use ($required) { return in_array($a, $required); });
175 187
 
176 188
 		foreach ($game->getTeamsIds() as $tid) {
177
-			if (in_array($teams[$tid], $checkVals)) return false;
178
-			if (isset($requiredTeams[$tid])) unset($requiredTeams[$tid]);
189
+			if (in_array($teams[$tid], $checkVals)) {
190
+				return false;
191
+			}
192
+			if (isset($requiredTeams[$tid])) {
193
+				unset($requiredTeams[$tid]);
194
+			}
179 195
 		}
180 196
 
181
-		if (count($requiredTeams) > 0) return false;
197
+		if (count($requiredTeams) > 0) {
198
+			return false;
199
+		}
182 200
 
183 201
 		return true;
184 202
 
Please login to merge, or discard this patch.
src/TournamentGenerator/Utilis/Generator.php 1 patch
Braces   +37 added lines, -12 removed lines patch added patch discarded remove patch
@@ -36,8 +36,11 @@  discard block
 block discarded – undo
36 36
 
37 37
 
38 38
 	public function setType(/** @scrutinizer ignore-all */ string $type = \TournamentGenerator\Constants::ROUND_ROBIN) {
39
-		if (in_array($type, \TournamentGenerator\Constants::GroupTypes)) $this->type = $type;
40
-		else throw new \Exception('Unknown group type: '.$type);
39
+		if (in_array($type, \TournamentGenerator\Constants::GroupTypes)) {
40
+			$this->type = $type;
41
+		} else {
42
+			throw new \Exception('Unknown group type: '.$type);
43
+		}
41 44
 		return $this;
42 45
 	}
43 46
 	public function getType() {
@@ -45,7 +48,9 @@  discard block
 block discarded – undo
45 48
 	}
46 49
 
47 50
 	public function setInGame(int $inGame) {
48
-		if ($inGame < 2 ||  $inGame > 4) throw new \Exception('Expected 2,3 or 4 as inGame '.$inGame.' given');
51
+		if ($inGame < 2 ||  $inGame > 4) {
52
+			throw new \Exception('Expected 2,3 or 4 as inGame '.$inGame.' given');
53
+		}
49 54
 		$this->inGame = $inGame;
50 55
 		return $this;
51 56
 	}
@@ -54,7 +59,9 @@  discard block
 block discarded – undo
54 59
 	}
55 60
 
56 61
 	public function setMaxSize(int $maxSize) {
57
-		if ($maxSize < 2) throw new \Exception('Max group size has to be at least 2, '.$maxSize.' given');
62
+		if ($maxSize < 2) {
63
+			throw new \Exception('Max group size has to be at least 2, '.$maxSize.' given');
64
+		}
58 65
 		$this->maxSize = $maxSize;
59 66
 		return $this;
60 67
 	}
@@ -78,7 +85,9 @@  discard block
 block discarded – undo
78 85
 	}
79 86
 	private function r_rGames(array $teams = []) {
80 87
 		$games = [];
81
-		if (count($teams) === 0) $teams = $this->group->getTeams();
88
+		if (count($teams) === 0) {
89
+			$teams = $this->group->getTeams();
90
+		}
82 91
 		switch ($this->inGame) {
83 92
 			case 2:
84 93
 				$games = Generator::circle_genGames2($teams, $this->group);
@@ -98,7 +107,9 @@  discard block
 block discarded – undo
98 107
 			$lockedTeam = array_shift($teamsB);
99 108
 			$gamesTemp = Generator::circle_genGames2($teamsB, $this->group);
100 109
 			foreach ($gamesTemp as $game) {
101
-				if (isset($lockedTeam1)) $game->addTeam($lockedTeam1);
110
+				if (isset($lockedTeam1)) {
111
+					$game->addTeam($lockedTeam1);
112
+				}
102 113
 				$game->addTeam($lockedTeam);
103 114
 			}
104 115
 			$games = array_merge($games, $gamesTemp);
@@ -116,7 +127,9 @@  discard block
 block discarded – undo
116 127
 		return $games;
117 128
 	}
118 129
 	private function two_twoGames(array $teams = []) {
119
-		if (count($teams) === 0) $teams = $this->group->getTeams();
130
+		if (count($teams) === 0) {
131
+			$teams = $this->group->getTeams();
132
+		}
120 133
 		$discard = [];
121 134
 		shuffle($teams);
122 135
 		$count = count($teams);
@@ -128,13 +141,17 @@  discard block
 block discarded – undo
128 141
 			$this->group->game($tInGame);
129 142
 		}
130 143
 
131
-		if (count($discard) > 0 && !$this->allowSkip) throw new \Exception('Couldn\'t make games with all teams. Expected k*'.$this->inGame.' teams '.$count.' teams given - discarting '.count($discard).' teams ('.implode(', ', $discard).') in group '.$this->group.' - allow skip '.($this->allowSkip ? 'True' : 'False'));
144
+		if (count($discard) > 0 && !$this->allowSkip) {
145
+			throw new \Exception('Couldn\'t make games with all teams. Expected k*'.$this->inGame.' teams '.$count.' teams given - discarting '.count($discard).' teams ('.implode(', ', $discard).') in group '.$this->group.' - allow skip '.($this->allowSkip ? 'True' : 'False'));
146
+		}
132 147
 
133 148
 		return $this;
134 149
 	}
135 150
 	private function cond_splitGames(array $teams = []) {
136 151
 		$games = [];
137
-		if (count($teams) === 0) $teams = $this->group->getTeams();
152
+		if (count($teams) === 0) {
153
+			$teams = $this->group->getTeams();
154
+		}
138 155
 
139 156
 		if (count($teams) > $this->maxSize) {
140 157
 			$groups = array_chunk($teams, /** @scrutinizer ignore-type */ ceil(count($teams)/ceil(count($teams)/$this->maxSize))); // SPLIT TEAMS INTO GROUP OF MAXIMUM SIZE OF $this->maxSize
@@ -144,7 +161,9 @@  discard block
 block discarded – undo
144 161
 			while ($g > 0) {
145 162
 				foreach ($games as $key => $group) {
146 163
 					$this->group->addGame(array_shift($games[$key]));
147
-					if (count($games[$key]) === 0) unset($games[$key]);
164
+					if (count($games[$key]) === 0) {
165
+						unset($games[$key]);
166
+					}
148 167
 					$g--;
149 168
 				}
150 169
 			}
@@ -165,7 +184,10 @@  discard block
 block discarded – undo
165 184
 	public static function circle_genGames2(array $teams = [], \tournamentGenerator\Group $group) {
166 185
 		$bracket = []; // ARRAY OF GAMES
167 186
 
168
-		if (count($teams) % 2 != 0) $teams[] = \TournamentGenerator\Constants::DUMMY_TEAM; // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY
187
+		if (count($teams) % 2 != 0) {
188
+			$teams[] = \TournamentGenerator\Constants::DUMMY_TEAM;
189
+		}
190
+		// IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY
169 191
 
170 192
 		shuffle($teams); // SHUFFLE TEAMS FOR MORE RANDOMNESS
171 193
 
@@ -189,7 +211,10 @@  discard block
 block discarded – undo
189 211
 			$reverse = array_reverse($teams);
190 212
 			$away = $reverse[$i];
191 213
 
192
-			if (($home == \TournamentGenerator\Constants::DUMMY_TEAM || $away == \TournamentGenerator\Constants::DUMMY_TEAM)) continue; // SKIP WHEN DUMMY_TEAM IS PRESENT
214
+			if (($home == \TournamentGenerator\Constants::DUMMY_TEAM || $away == \TournamentGenerator\Constants::DUMMY_TEAM)) {
215
+				continue;
216
+			}
217
+			// SKIP WHEN DUMMY_TEAM IS PRESENT
193 218
 
194 219
 			$bracket[] = new \TournamentGenerator\Game([$home, $away], $group);
195 220
 
Please login to merge, or discard this patch.
src/TournamentGenerator/Round.php 1 patch
Braces   +20 added lines, -9 removed lines patch added patch discarded remove patch
@@ -25,8 +25,11 @@  discard block
 block discarded – undo
25 25
 
26 26
 	public function addGroup(Group ...$groups){
27 27
 		foreach ($groups as $group) {
28
-			if ($group instanceof Group) $this->groups[] = $group;
29
-			else throw new \Exception('Trying to add group which is not an instance of Group class.');
28
+			if ($group instanceof Group) {
29
+				$this->groups[] = $group;
30
+			} else {
31
+				throw new \Exception('Trying to add group which is not an instance of Group class.');
32
+			}
30 33
 		}
31 34
 		return $this;
32 35
 	}
@@ -77,7 +80,9 @@  discard block
 block discarded – undo
77 80
 	}
78 81
 	public function isPlayed(){
79 82
 		foreach ($this->groups as $group) {
80
-			if (!$group->isPlayed()) return false;
83
+			if (!$group->isPlayed()) {
84
+				return false;
85
+			}
81 86
 		}
82 87
 		return true;
83 88
 	}
@@ -86,10 +91,11 @@  discard block
 block discarded – undo
86 91
 		foreach ($teams as $team) {
87 92
 			if ($team instanceof Team)  {
88 93
 				$this->teams[] = $team;
89
-			}
90
-			elseif (gettype($team) === 'array') {
94
+			} elseif (gettype($team) === 'array') {
91 95
 				foreach ($team as $team2) {
92
-					if ($team2 instanceof Team) $this->teams[] = $team2;
96
+					if ($team2 instanceof Team) {
97
+						$this->teams[] = $team2;
98
+					}
93 99
 					$team2->groupResults[$this->id] = [
94 100
 						'group' => $this,
95 101
 						'points' => 0,
@@ -101,8 +107,9 @@  discard block
 block discarded – undo
101 107
 						'third'  => 0
102 108
 					];
103 109
 				}
110
+			} else {
111
+				throw new \Exception('Trying to add team which is not an instance of Team class');
104 112
 			}
105
-			else throw new \Exception('Trying to add team which is not an instance of Team class');
106 113
 		}
107 114
 		return $this;
108 115
 	}
@@ -131,7 +138,9 @@  discard block
 block discarded – undo
131 138
 
132 139
 	public function splitTeams(...$groups) {
133 140
 
134
-		if (count($groups) === 0) $groups = $this->getGroups();
141
+		if (count($groups) === 0) {
142
+			$groups = $this->getGroups();
143
+		}
135 144
 
136 145
 		foreach ($groups as $key => $value) {
137 146
 			if (gettype($value) === 'array') {
@@ -146,7 +155,9 @@  discard block
 block discarded – undo
146 155
 		while (count($teams) > 0) {
147 156
 			foreach ($groups as $group) {
148 157
 				if ($group instanceof Group) {
149
-					if (count($teams) > 0) $group->addTeam(array_shift($teams));
158
+					if (count($teams) > 0) {
159
+						$group->addTeam(array_shift($teams));
160
+					}
150 161
 				}
151 162
 			}
152 163
 		}
Please login to merge, or discard this patch.
src/TournamentGenerator/Category.php 1 patch
Braces   +20 added lines, -9 removed lines patch added patch discarded remove patch
@@ -21,8 +21,11 @@  discard block
 block discarded – undo
21 21
 
22 22
 	public function addRound(Round ...$rounds){
23 23
 		foreach ($rounds as $round) {
24
-			if ($round instanceof Round) $this->rounds[] = $round;
25
-			else throw new \Exception('Trying to add round which is not an instance of Round class.');
24
+			if ($round instanceof Round) {
25
+				$this->rounds[] = $round;
26
+			} else {
27
+				throw new \Exception('Trying to add round which is not an instance of Round class.');
28
+			}
26 29
 		}
27 30
 		return $this;
28 31
 	}
@@ -55,13 +58,15 @@  discard block
 block discarded – undo
55 58
 		foreach ($teams as $team) {
56 59
 			if ($team instanceof Team)  {
57 60
 				$this->teams[] = $team;
58
-			}
59
-			elseif (gettype($team) === 'array') {
61
+			} elseif (gettype($team) === 'array') {
60 62
 				foreach ($team as $team2) {
61
-					if ($team2 instanceof Team) $this->teams[] = $team2;
63
+					if ($team2 instanceof Team) {
64
+						$this->teams[] = $team2;
65
+					}
62 66
 				}
67
+			} else {
68
+				throw new \Exception('Trying to add team which is not an instance of Team class');
63 69
 			}
64
-			else throw new \Exception('Trying to add team which is not an instance of Team class');
65 70
 		}
66 71
 		return $this;
67 72
 	}
@@ -71,7 +76,9 @@  discard block
 block discarded – undo
71 76
 		return $t;
72 77
 	}
73 78
 	public function getTeams() {
74
-		if (count($this->teams) > 0) return $this->teams;
79
+		if (count($this->teams) > 0) {
80
+			return $this->teams;
81
+		}
75 82
 		$teams = [];
76 83
 		foreach ($this->rounds as $round) {
77 84
 			$teams = array_merge($teams, $round->getTeams());
@@ -90,7 +97,9 @@  discard block
 block discarded – undo
90 97
 
91 98
 	public function splitTeams(...$rounds) {
92 99
 
93
-		if (count($rounds) === 0) $rounds = $this->getRounds();
100
+		if (count($rounds) === 0) {
101
+			$rounds = $this->getRounds();
102
+		}
94 103
 
95 104
 		$teams = $this->getTeams();
96 105
 		shuffle($teams);
@@ -110,7 +119,9 @@  discard block
 block discarded – undo
110 119
 
111 120
 	public function genGamesSimulate() {
112 121
 		$games = [];
113
-		if (count($this->rounds) <= 0) throw new \Exception('There are no rounds to simulate games from.');
122
+		if (count($this->rounds) <= 0) {
123
+			throw new \Exception('There are no rounds to simulate games from.');
124
+		}
114 125
 		foreach ($this->rounds as $round) {
115 126
 			$games = array_merge($games, $round->genGames());
116 127
 			$round->simulate()->progress(true)->resetGames();
Please login to merge, or discard this patch.
src/TournamentGenerator/Team.php 1 patch
Braces   +51 added lines, -17 removed lines patch added patch discarded remove patch
@@ -44,104 +44,138 @@
 block discarded – undo
44 44
 	}
45 45
 
46 46
 	public function addGameWith(Team $team, Group $group) {
47
-		if (!isset($this->gamesWith[$group->id][$team->id])) $this->gamesWith[$group->id][$team->id] = 0;
47
+		if (!isset($this->gamesWith[$group->id][$team->id])) {
48
+			$this->gamesWith[$group->id][$team->id] = 0;
49
+		}
48 50
 		$this->gamesWith[$group->id][$team->id]++;
49 51
 		return $this;
50 52
 	}
51 53
 	public function addGroup(Group $group) {
52
-		if (!isset($this->games[$group->id])) $this->games[$group->id] = [];
54
+		if (!isset($this->games[$group->id])) {
55
+			$this->games[$group->id] = [];
56
+		}
53 57
 		return $this;
54 58
 	}
55 59
 	public function addGame(Game $game) {
56 60
 		$group = $game->getGroup();
57
-		if (!isset($this->games[$group->id])) $this->games[$group->id] = [];
61
+		if (!isset($this->games[$group->id])) {
62
+			$this->games[$group->id] = [];
63
+		}
58 64
 		$this->games[$group->id][] = $game;
59 65
 		return $this;
60 66
 	}
61 67
 
62 68
 	public function addWin(string $groupId = ''){
63
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
69
+		if (!isset($this->groupResults[$groupId])) {
70
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
71
+		}
64 72
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->winPoints;
65 73
 		$this->sumPoints += $this->groupResults[$groupId]['group']->winPoints;
66 74
 		$this->groupResults[$groupId]['wins']++;
67 75
 		return $this;
68 76
 	}
69 77
 	public function removeWin(string $groupId = ''){
70
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
78
+		if (!isset($this->groupResults[$groupId])) {
79
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
80
+		}
71 81
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->winPoints;
72 82
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->winPoints;
73 83
 		$this->groupResults[$groupId]['wins']--;
74 84
 		return $this;
75 85
 	}
76 86
 	public function addDraw(string $groupId = ''){
77
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
87
+		if (!isset($this->groupResults[$groupId])) {
88
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
89
+		}
78 90
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->drawPoints;
79 91
 		$this->sumPoints += $this->groupResults[$groupId]['group']->drawPoints;
80 92
 		$this->groupResults[$groupId]['draws']++;
81 93
 		return $this;
82 94
 	}
83 95
 	public function removeDraw(string $groupId = ''){
84
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
96
+		if (!isset($this->groupResults[$groupId])) {
97
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
98
+		}
85 99
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->drawPointsPoints;
86 100
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->drawPoints;
87 101
 		$this->groupResults[$groupId]['draws']--;
88 102
 		return $this;
89 103
 	}
90 104
 	public function addLoss(string $groupId = ''){
91
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
105
+		if (!isset($this->groupResults[$groupId])) {
106
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
107
+		}
92 108
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->lostPoints;
93 109
 		$this->sumPoints += $this->groupResults[$groupId]['group']->lostPoints;
94 110
 		$this->groupResults[$groupId]['losses']++;
95 111
 		return $this;
96 112
 	}
97 113
 	public function removeLoss(string $groupId = ''){
98
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
114
+		if (!isset($this->groupResults[$groupId])) {
115
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
116
+		}
99 117
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->lostPoints;
100 118
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->lostPoints;
101 119
 		$this->groupResults[$groupId]['losses']--;
102 120
 		return $this;
103 121
 	}
104 122
 	public function addSecond(string $groupId = ''){
105
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
123
+		if (!isset($this->groupResults[$groupId])) {
124
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
125
+		}
106 126
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->secondPoints;
107 127
 		$this->sumPoints += $this->groupResults[$groupId]['group']->secondPoints;
108 128
 		$this->groupResults[$groupId]['second']++;
109 129
 		return $this;
110 130
 	}
111 131
 	public function removeSecond(string $groupId = ''){
112
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
132
+		if (!isset($this->groupResults[$groupId])) {
133
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
134
+		}
113 135
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->secondPoints;
114 136
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->secondPoints;
115 137
 		$this->groupResults[$groupId]['second']--;
116 138
 		return $this;
117 139
 	}
118 140
 	public function addThird(string $groupId = ''){
119
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
141
+		if (!isset($this->groupResults[$groupId])) {
142
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
143
+		}
120 144
 		$this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->thirdPoints;
121 145
 		$this->sumPoints += $this->groupResults[$groupId]['group']->thirdPoints;
122 146
 		$this->groupResults[$groupId]['third']++;
123 147
 		return $this;
124 148
 	}
125 149
 	public function removeThird(string $groupId = ''){
126
-		if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
150
+		if (!isset($this->groupResults[$groupId])) {
151
+			throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')');
152
+		}
127 153
 		$this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->thirdPoints;
128 154
 		$this->sumPoints -= $this->groupResults[$groupId]['group']->thirdPoints;
129 155
 		$this->groupResults[$groupId]['third']--;
130 156
 		return $this;
131 157
 	}
132 158
 	public function sumPoints(array $groupIds = []) {
133
-		if (count($groupIds) === 0) return $this->sumPoints;
159
+		if (count($groupIds) === 0) {
160
+			return $this->sumPoints;
161
+		}
134 162
 		$sum = 0;
135 163
 		foreach ($groupIds as $gid) {
136
-			if (isset($this->groupResults[$gid])) $sum += $this->groupResults[$gid]['points'];
164
+			if (isset($this->groupResults[$gid])) {
165
+				$sum += $this->groupResults[$gid]['points'];
166
+			}
137 167
 		}
138 168
 		return $sum;
139 169
 	}
140 170
 	public function sumScore(array $groupIds = []) {
141
-		if (count($groupIds) === 0) return $this->sumScore;
171
+		if (count($groupIds) === 0) {
172
+			return $this->sumScore;
173
+		}
142 174
 		$sum = 0;
143 175
 		foreach ($groupIds as $gid) {
144
-			if (isset($this->groupResults[$gid])) $sum += $this->groupResults[$gid]['score'];
176
+			if (isset($this->groupResults[$gid])) {
177
+				$sum += $this->groupResults[$gid]['score'];
178
+			}
145 179
 		}
146 180
 		return $sum;
147 181
 	}
Please login to merge, or discard this patch.