Completed
Push — master ( 7949ab...b0b972 )
by Tomáš
02:22
created
src/TournamentGenerator/TeamFilter.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -43,14 +43,14 @@
 block discarded – undo
43 43
 
44 44
 	private $groups = [];
45 45
 
46
-	function __construct(string $what = 'points', string $how = '>', $val = 0, array $groups = []){
46
+	function __construct(string $what = 'points', string $how = '>', $val = 0, array $groups = []) {
47 47
 		if (!in_array(strtolower($what), ['points', 'score', 'wins', 'draws', 'losses', 'second', 'third', 'team', 'notprogressed', 'progressed'])) throw new \Exception('Trying to filter unexisting type ('.$what.')');
48 48
 		$this->what = strtolower($what);
49 49
 		if (!in_array($how, ['>', '<', '>=', '<=', '=', '!='])) throw new \Exception('Trying to filter with unexisting operator ('.$how.')');
50 50
 		$this->how = $how;
51 51
 		if (!(gettype($val) === 'integer' && strtolower($what) !== 'team') && !($val instanceof Team && strtolower($what) === 'team')) throw new \Exception('Unsupported filter value type ('.gettype($val).')');
52 52
 		$this->val = $val;
53
-		$this->groups = array_map(function($a) { return $a->getId(); }, array_filter($groups, function($a) {return ($a instanceof Group);}));
53
+		$this->groups = array_map(function($a) { return $a->getId(); }, array_filter($groups, function($a) {return ($a instanceof Group); }));
54 54
 	}
55 55
 	public function __toString() {
56 56
 		return 'Filter: '.$this->what.' '.($this->what !== 'notprogressed' && $this->what !== 'progressed' ? $this->how.' '.$this->val : '');
Please login to merge, or discard this patch.
Braces   +25 added lines, -9 removed lines patch added patch discarded remove patch
@@ -44,11 +44,17 @@  discard block
 block discarded – undo
44 44
 	private $groups = [];
45 45
 
46 46
 	function __construct(string $what = 'points', string $how = '>', $val = 0, array $groups = []){
47
-		if (!in_array(strtolower($what), ['points', 'score', 'wins', 'draws', 'losses', 'second', 'third', 'team', 'notprogressed', 'progressed'])) throw new \Exception('Trying to filter unexisting type ('.$what.')');
47
+		if (!in_array(strtolower($what), ['points', 'score', 'wins', 'draws', 'losses', 'second', 'third', 'team', 'notprogressed', 'progressed'])) {
48
+			throw new \Exception('Trying to filter unexisting type ('.$what.')');
49
+		}
48 50
 		$this->what = strtolower($what);
49
-		if (!in_array($how, ['>', '<', '>=', '<=', '=', '!='])) throw new \Exception('Trying to filter with unexisting operator ('.$how.')');
51
+		if (!in_array($how, ['>', '<', '>=', '<=', '=', '!='])) {
52
+			throw new \Exception('Trying to filter with unexisting operator ('.$how.')');
53
+		}
50 54
 		$this->how = $how;
51
-		if (!(gettype($val) === 'integer' && strtolower($what) !== 'team') && !($val instanceof Team && strtolower($what) === 'team')) throw new \Exception('Unsupported filter value type ('.gettype($val).')');
55
+		if (!(gettype($val) === 'integer' && strtolower($what) !== 'team') && !($val instanceof Team && strtolower($what) === 'team')) {
56
+			throw new \Exception('Unsupported filter value type ('.gettype($val).')');
57
+		}
52 58
 		$this->val = $val;
53 59
 		$this->groups = array_map(function($a) { return $a->getId(); }, array_filter($groups, function($a) {return ($a instanceof Group);}));
54 60
 	}
@@ -57,11 +63,17 @@  discard block
 block discarded – undo
57 63
 	}
58 64
 
59 65
 	public function validate(Team $team, $groupsId, string $operation = 'sum', Group $from = null) {
60
-		if (count($this->groups) > 0) $groupsId = array_unique(array_merge($this->groups, (gettype($groupsId) === 'array' ? $groupsId : [$groupsId])), SORT_REGULAR);
66
+		if (count($this->groups) > 0) {
67
+			$groupsId = array_unique(array_merge($this->groups, (gettype($groupsId) === 'array' ? $groupsId : [$groupsId])), SORT_REGULAR);
68
+		}
61 69
 
62
-		if ($this->what == 'team') return ($this->how === '!=' ? !$this->validateTeam($team) : $this->validateTeam($team));
63
-		elseif ($this->what == 'notprogressed') return !$this->validateProgressed($team, $from);
64
-		elseif ($this->what == 'progressed') return $this->validateProgressed($team, $from);
70
+		if ($this->what == 'team') {
71
+			return ($this->how === '!=' ? !$this->validateTeam($team) : $this->validateTeam($team));
72
+		} elseif ($this->what == 'notprogressed') {
73
+			return !$this->validateProgressed($team, $from);
74
+		} elseif ($this->what == 'progressed') {
75
+			return $this->validateProgressed($team, $from);
76
+		}
65 77
 
66 78
 		return $this->validateCalc($team, $groupsId, $operation);
67 79
 	}
@@ -70,11 +82,15 @@  discard block
 block discarded – undo
70 82
 		return $this->val === $team;
71 83
 	}
72 84
 	private function validateProgressed(Team $team, Group $from = null) {
73
-		if ($from === null) throw new \Exception('Group $from was not defined.');
85
+		if ($from === null) {
86
+			throw new \Exception('Group $from was not defined.');
87
+		}
74 88
 		return $from->isProgressed($team);
75 89
 	}
76 90
 	private function validateCalc(Team $team, array $groupsId, string $operation = 'sum') {
77
-		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.');
91
+		if (gettype($groupsId) === 'array' && !in_array(strtolower($operation), ['sum', 'avg', 'max', 'min'])) {
92
+			throw new \Exception('Unknown operation of '.$operation.'. Only "sum", "avg", "min", "max" possible.');
93
+		}
78 94
 
79 95
 		return Utilis\FilterComparator::compare($operation, $this->val, $this->how, $this->what, $team, $groupsId);
80 96
 
Please login to merge, or discard this patch.
src/TournamentGenerator/Group.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -28,11 +28,11 @@  discard block
 block discarded – undo
28 28
 		$this->setId(isset($id) ? $id : uniqid());
29 29
 	}
30 30
 
31
-	public function allowSkip(){
31
+	public function allowSkip() {
32 32
 		$this->generator->allowSkip();
33 33
 		return $this;
34 34
 	}
35
-	public function disallowSkip(){
35
+	public function disallowSkip() {
36 36
 		$this->generator->disallowSkip();
37 37
 		return $this;
38 38
 	}
@@ -139,9 +139,9 @@  discard block
 block discarded – undo
139 139
 		}
140 140
 	}
141 141
 	public function addProgressed(...$teams) {
142
-		$this->progressed = array_merge($this->progressed, array_map(function ($a) {return $a->getId();}, array_filter($teams, function($a){return $a instanceof Team;})));
143
-		foreach (array_filter($teams, function($a){return is_array($a);}) as $team) {
144
-			$this->progressed = array_merge($this->progressed, array_map(function ($a) {return $a->getId();}, array_filter($team, function($a) {
142
+		$this->progressed = array_merge($this->progressed, array_map(function($a) {return $a->getId(); }, array_filter($teams, function($a) {return $a instanceof Team; })));
143
+		foreach (array_filter($teams, function($a) {return is_array($a); }) as $team) {
144
+			$this->progressed = array_merge($this->progressed, array_map(function($a) {return $a->getId(); }, array_filter($team, function($a) {
145 145
 				return ($a instanceof Team);
146 146
 			})));
147 147
 		}
@@ -161,11 +161,11 @@  discard block
 block discarded – undo
161 161
 		$this->games[] = $g;
162 162
 		return $g;
163 163
 	}
164
-	public function addGame(...$games){
165
-		$this->games = array_merge($this->games, array_filter($games, function($a){ return ($a instanceof Game); }));
164
+	public function addGame(...$games) {
165
+		$this->games = array_merge($this->games, array_filter($games, function($a) { return ($a instanceof Game); }));
166 166
 
167
-		foreach (array_filter($games, function($a){return is_array($a);}) as $key => $game) {
168
-			$this->games = array_merge($this->games, array_filter($game, function($a){ return ($a instanceof Game); }));
167
+		foreach (array_filter($games, function($a) {return is_array($a); }) as $key => $game) {
168
+			$this->games = array_merge($this->games, array_filter($game, function($a) { return ($a instanceof Game); }));
169 169
 		}
170 170
 		return $this;
171 171
 	}
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
 		}
188 188
 		return $this;
189 189
 	}
190
-	public function isPlayed(){
190
+	public function isPlayed() {
191 191
 		if (count($this->games) === 0) return false;
192 192
 		foreach ($this->games as $game) {
193 193
 			if (!$game->isPlayed()) return false;
Please login to merge, or discard this patch.
Braces   +18 added lines, -6 removed lines patch added patch discarded remove patch
@@ -64,7 +64,9 @@  discard block
 block discarded – undo
64 64
 	public function getTeams(bool $ordered = false, $ordering = \TournamentGenerator\Constants::POINTS, array $filters = []) {
65 65
 		$teams = $this->teams;
66 66
 
67
-		if ($ordered) return $this->sortTeams($ordering, $filters);
67
+		if ($ordered) {
68
+			return $this->sortTeams($ordering, $filters);
69
+		}
68 70
 
69 71
 		// APPLY FILTERS
70 72
 		$filter = new Filter([$this], $filters);
@@ -79,7 +81,9 @@  discard block
 block discarded – undo
79 81
 		return $t;
80 82
 	}
81 83
 	public function sortTeams($ordering = null, array $filters = []) {
82
-		if (!isset($ordering)) $ordering = $this->ordering;
84
+		if (!isset($ordering)) {
85
+			$ordering = $this->ordering;
86
+		}
83 87
 		$this->teams = Utilis\Sorter\Teams::sortGroup($this->teams, $this, $ordering);
84 88
 		return $this->getTeams(false, null, $filters);
85 89
 	}
@@ -109,7 +113,9 @@  discard block
 block discarded – undo
109 113
 	}
110 114
 
111 115
 	public function setOrdering(string $ordering = \TournamentGenerator\Constants::POINTS) {
112
-		if (!in_array($ordering, \TournamentGenerator\Constants::OrderingTypes)) throw new \Exception('Unknown group ordering: '.$ordering);
116
+		if (!in_array($ordering, \TournamentGenerator\Constants::OrderingTypes)) {
117
+			throw new \Exception('Unknown group ordering: '.$ordering);
118
+		}
113 119
 		$this->ordering = $ordering;
114 120
 		return $this;
115 121
 	}
@@ -174,7 +180,9 @@  discard block
 block discarded – undo
174 180
 		return $this->games;
175 181
 	}
176 182
 	public function orderGames() {
177
-		if (count($this->games) <= 4) return $this->games;
183
+		if (count($this->games) <= 4) {
184
+			return $this->games;
185
+		}
178 186
 		$this->games = $this->generator->orderGames();
179 187
 		return $this->games;
180 188
 	}
@@ -189,9 +197,13 @@  discard block
 block discarded – undo
189 197
 		return $this;
190 198
 	}
191 199
 	public function isPlayed(){
192
-		if (count($this->games) === 0) return false;
200
+		if (count($this->games) === 0) {
201
+			return false;
202
+		}
193 203
 		foreach ($this->games as $game) {
194
-			if (!$game->isPlayed()) return false;
204
+			if (!$game->isPlayed()) {
205
+				return false;
206
+			}
195 207
 		}
196 208
 		return true;
197 209
 	}
Please login to merge, or discard this patch.
src/TournamentGenerator/Filter.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -12,12 +12,12 @@
 block discarded – undo
12 12
 	private $filters = [];
13 13
 
14 14
 	function __construct(array $groups, array $filters) {
15
-		$this->groups = array_filter($groups, function($a) {return $a instanceof Group;});
15
+		$this->groups = array_filter($groups, function($a) {return $a instanceof Group; });
16 16
 		$this->filters = $filters;
17 17
 	}
18 18
 
19 19
 	private function getGroupsIds() {
20
-		return array_map(function($a){return $a->getId();}, $this->groups);
20
+		return array_map(function($a) {return $a->getId(); }, $this->groups);
21 21
 	}
22 22
 
23 23
 	/**
Please login to merge, or discard this patch.
Braces   +38 added lines, -17 removed lines patch added patch discarded remove patch
@@ -29,8 +29,7 @@  discard block
 block discarded – undo
29 29
 			if (gettype($filter) === 'array') {
30 30
 				$this->filterMulti($teams, $filter, $key);
31 31
 				continue;
32
-			}
33
-			elseif ($filter instanceof TeamFilter) {
32
+			} elseif ($filter instanceof TeamFilter) {
34 33
 				$teams = array_filter($teams, function($team) use ($filter) {return $filter->validate($team, $this->getGroupsIds(), 'sum', $this->groups[0]); });
35 34
 				continue;
36 35
 			}
@@ -40,16 +39,24 @@  discard block
 block discarded – undo
40 39
 	}
41 40
 
42 41
 	private function filterMulti(array &$teams, array $filters, string $how = 'and') {
43
-		if (is_int($how)) $how = 'and';
42
+		if (is_int($how)) {
43
+			$how = 'and';
44
+		}
44 45
 		switch (strtolower($how)) {
45 46
 			case 'and':
46 47
 				foreach ($teams as $tkey => $team) {
47
-					if (!$this->filterAnd($team, $filters)) unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY
48
+					if (!$this->filterAnd($team, $filters)) {
49
+						unset($teams[$tkey]);
50
+					}
51
+					// IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY
48 52
 				}
49 53
 				return true;
50 54
 			case 'or':
51 55
 				foreach ($teams as $tkey => $team) {
52
-					if (!$this->filterOr($team, $filters)) unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY
56
+					if (!$this->filterOr($team, $filters)) {
57
+						unset($teams[$tkey]);
58
+					}
59
+					// IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY
53 60
 				}
54 61
 				return true;
55 62
 		}
@@ -59,21 +66,28 @@  discard block
 block discarded – undo
59 66
 	private function filterAnd(Team $team, array $filters) {
60 67
 		foreach ($filters as $key => $value) {
61 68
 			if (is_array($value)) {
62
-				if (is_int($key)) $key = 'and';
69
+				if (is_int($key)) {
70
+					$key = 'and';
71
+				}
63 72
 				switch (strtolower($key)) {
64 73
 					case 'and':
65
-						if (!$this->filterAnd($team, $value)) return false;
74
+						if (!$this->filterAnd($team, $value)) {
75
+							return false;
76
+						}
66 77
 						break;
67 78
 					case 'or':
68
-						if (!$this->filterOr($team, $value)) return false;
79
+						if (!$this->filterOr($team, $value)) {
80
+							return false;
81
+						}
69 82
 						break;
70 83
 					default:
71 84
 						throw new \Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".');
72 85
 				}
73 86
 				continue;
74
-			}
75
-			elseif ($value instanceof TeamFilter) {
76
-				if (!$value->validate($team, $this->getGroupsIds(), 'sum', $this->groups[0])) return false;
87
+			} elseif ($value instanceof TeamFilter) {
88
+				if (!$value->validate($team, $this->getGroupsIds(), 'sum', $this->groups[0])) {
89
+					return false;
90
+				}
77 91
 				continue;
78 92
 			}
79 93
 			throw new \Exception('Filter ['.$key.'] is not an instance of TeamFilter class');
@@ -82,22 +96,29 @@  discard block
 block discarded – undo
82 96
 	}
83 97
 	private function filterOr(Team $team, array $filters) {
84 98
 		foreach ($filters as $key => $value) {
85
-			if (is_int($key)) $key = 'and';
99
+			if (is_int($key)) {
100
+				$key = 'and';
101
+			}
86 102
 			if (is_array($value)) {
87 103
 				switch (strtolower($key)) {
88 104
 					case 'and':
89
-						if ($this->filterAnd($team, $value)) return true;
105
+						if ($this->filterAnd($team, $value)) {
106
+							return true;
107
+						}
90 108
 						break;
91 109
 					case 'or':
92
-						if ($this->filterOr($team, $value)) return true;
110
+						if ($this->filterOr($team, $value)) {
111
+							return true;
112
+						}
93 113
 						break;
94 114
 					default:
95 115
 						throw new \Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".');
96 116
 				}
97 117
 				continue;
98
-			}
99
-			elseif ($value instanceof TeamFilter) {
100
-				if ($value->validate($team, $this->getGroupsIds(), 'sum', $this->groups[0])) return true;
118
+			} elseif ($value instanceof TeamFilter) {
119
+				if ($value->validate($team, $this->getGroupsIds(), 'sum', $this->groups[0])) {
120
+					return true;
121
+				}
101 122
 				continue;
102 123
 			}
103 124
 			throw new \Exception('Filter ['.$key.'] is not an instance of TeamFilter class');
Please login to merge, or discard this patch.
src/TournamentGenerator/Tournament.php 2 patches
Braces   +15 added lines, -5 removed lines patch added patch discarded remove patch
@@ -150,7 +150,9 @@  discard block
 block discarded – undo
150 150
 		}
151 151
 		$teams = \array_unique($teams);
152 152
 		$this->teams = $teams;
153
-		if ($ordered) $teams = $this->sortTeams($ordering);
153
+		if ($ordered) {
154
+			$teams = $this->sortTeams($ordering);
155
+		}
154 156
 
155 157
 		// APPLY FILTERS
156 158
 		$filter = new Filter($this->getGroups(), $filters);
@@ -183,14 +185,18 @@  discard block
 block discarded – undo
183 185
 
184 186
 	public function splitTeams(Round ...$wheres) {
185 187
 
186
-		if (count($wheres) === 0) $wheres = $this->getRounds();
188
+		if (count($wheres) === 0) {
189
+			$wheres = $this->getRounds();
190
+		}
187 191
 
188 192
 		$teams = $this->getTeams();
189 193
 		shuffle($teams);
190 194
 
191 195
 		while (count($teams) > 0) {
192 196
 			foreach ($wheres as $where) {
193
-				if (count($teams) > 0) $where->addTeam(array_shift($teams));
197
+				if (count($teams) > 0) {
198
+					$where->addTeam(array_shift($teams));
199
+				}
194 200
 			}
195 201
 		}
196 202
 		foreach ($wheres as $where) {
@@ -202,13 +208,17 @@  discard block
 block discarded – undo
202 208
 	public function genGamesSimulate(bool $returnTime = false) {
203 209
 		$games = Utilis\Simulator::simulateTournament($this);
204 210
 
205
-		if ($returnTime) return $this->getTournamentTime();
211
+		if ($returnTime) {
212
+			return $this->getTournamentTime();
213
+		}
206 214
 		return $games;
207 215
 	}
208 216
 	public function genGamesSimulateReal(bool $returnTime = false) {
209 217
 		$games = Utilis\Simulator::simulateTournamentReal($this);
210 218
 
211
-		if ($returnTime) return $this->getTournamentTime();
219
+		if ($returnTime) {
220
+			return $this->getTournamentTime();
221
+		}
212 222
 		return $games;
213 223
 	}
214 224
 
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 
21 21
 	private $allowSkip = false;
22 22
 
23
-	function __construct(string $name = ''){
23
+	function __construct(string $name = '') {
24 24
 		$this->name = $name;
25 25
 	}
26 26
 	public function __toString() {
@@ -63,16 +63,16 @@  discard block
 block discarded – undo
63 63
 	public function getCategoryWait() {
64 64
 		return $this->expectedCategoryWait;
65 65
 	}
66
-	public function getTournamentTime(){
66
+	public function getTournamentTime() {
67 67
 		$games = count($this->getGames());
68 68
 		return $games*$this->expectedPlay+($games-1)*$this->expectedGameWait+(count($this->getRounds())-1)*$this->expectedRoundWait+(count($this->getCategories())-1)*$this->expectedCategoryWait;
69 69
 	}
70 70
 
71
-	public function allowSkip(){
71
+	public function allowSkip() {
72 72
 		$this->allowSkip = true;
73 73
 		return $this;
74 74
 	}
75
-	public function disallowSkip(){
75
+	public function disallowSkip() {
76 76
 		$this->allowSkip = false;
77 77
 		return $this;
78 78
 	}
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 		return $this->allowSkip;
85 85
 	}
86 86
 
87
-	public function addCategory(Category ...$categories){
87
+	public function addCategory(Category ...$categories) {
88 88
 		foreach ($categories as $category) {
89 89
 			$this->categories[] = $category;
90 90
 		}
Please login to merge, or discard this patch.
src/TournamentGenerator/Utilis/Simulator.php 1 patch
Braces   +18 added lines, -6 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(null, $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
 
@@ -51,7 +57,9 @@  discard block
 block discarded – undo
51 57
 
52 58
 	public static function simulateTournamentReal(\TournamentGenerator\Tournament $tournament) {
53 59
 		$games = [];
54
-		if (count($tournament->getCategories()) === 0 && count($tournament->getRounds()) === 0) throw new \Exception('There are no rounds or categories to simulate games from.');
60
+		if (count($tournament->getCategories()) === 0 && count($tournament->getRounds()) === 0) {
61
+			throw new \Exception('There are no rounds or categories to simulate games from.');
62
+		}
55 63
 
56 64
 		foreach ($tournament->getRounds() as $round) {
57 65
 			$games = array_merge($games, $round->genGames());
@@ -62,7 +70,9 @@  discard block
 block discarded – undo
62 70
 	}
63 71
 
64 72
 	public static function simulateCategory(\TournamentGenerator\Category $category) {
65
-		if (count($category->getRounds()) === 0) throw new \Exception('There are no rounds to simulate games from.');
73
+		if (count($category->getRounds()) === 0) {
74
+			throw new \Exception('There are no rounds to simulate games from.');
75
+		}
66 76
 
67 77
 		$games = [];
68 78
 
@@ -79,7 +89,9 @@  discard block
 block discarded – undo
79 89
 
80 90
 	public static function simulateCategoryReal(\TournamentGenerator\Category $category) {
81 91
 		$games = [];
82
-		if (count($category->getRounds()) === 0) throw new \Exception('There are no rounds to simulate games from.');
92
+		if (count($category->getRounds()) === 0) {
93
+			throw new \Exception('There are no rounds to simulate games from.');
94
+		}
83 95
 
84 96
 		foreach ($category->getRounds() as $round) {
85 97
 			$games = array_merge($games, $round->genGames());
Please login to merge, or discard this patch.
src/TournamentGenerator/Category.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 		$this->setId(isset($id) ? $id : uniqid());
18 18
 	}
19 19
 
20
-	public function addRound(Round ...$rounds){
20
+	public function addRound(Round ...$rounds) {
21 21
 		foreach ($rounds as $round) {
22 22
 			$this->rounds[] = $round;
23 23
 		}
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 		$this->rounds[] = $r->setSkip($this->allowSkip);
29 29
 		return $r;
30 30
 	}
31
-	public function getRounds(){
31
+	public function getRounds() {
32 32
 		return $this->rounds;
33 33
 	}
34 34
 	public function getGroups() {
@@ -39,11 +39,11 @@  discard block
 block discarded – undo
39 39
 		return $groups;
40 40
 	}
41 41
 
42
-	public function allowSkip(){
42
+	public function allowSkip() {
43 43
 		$this->allowSkip = true;
44 44
 		return $this;
45 45
 	}
46
-	public function disallowSkip(){
46
+	public function disallowSkip() {
47 47
 		$this->allowSkip = false;
48 48
 		return $this;
49 49
 	}
Please login to merge, or discard this patch.
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -73,7 +73,9 @@  discard block
 block discarded – undo
73 73
 		}
74 74
 		$teams = \array_unique($teams);
75 75
 		$this->teams = $teams;
76
-		if ($ordered) $teams = $this->sortTeams($ordering);
76
+		if ($ordered) {
77
+			$teams = $this->sortTeams($ordering);
78
+		}
77 79
 
78 80
 		// APPLY FILTERS
79 81
 		$filter = new Filter($this->getGroups(), $filters);
@@ -106,14 +108,18 @@  discard block
 block discarded – undo
106 108
 
107 109
 	public function splitTeams(Round ...$wheres) {
108 110
 
109
-		if (count($wheres) === 0) $wheres = $this->getRounds();
111
+		if (count($wheres) === 0) {
112
+			$wheres = $this->getRounds();
113
+		}
110 114
 
111 115
 		$teams = $this->getTeams();
112 116
 		shuffle($teams);
113 117
 
114 118
 		while (count($teams) > 0) {
115 119
 			foreach ($wheres as $where) {
116
-				if (count($teams) > 0) $where->addTeam(array_shift($teams));
120
+				if (count($teams) > 0) {
121
+					$where->addTeam(array_shift($teams));
122
+				}
117 123
 			}
118 124
 		}
119 125
 		foreach ($wheres as $where) {
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
@@ -38,12 +38,20 @@  discard block
 block discarded – undo
38 38
 	}
39 39
 
40 40
 	public function progress(bool $blank = false) {
41
-		if ($this->progressed) return $this;
42
-		if ($blank) $teams = $this->from->isPlayed() ? $this->from->sortTeams(null, $this->filters) : $this->from->simulate($this->filters);
43
-		else $teams = $this->from->sortTeams(null, $this->filters);
41
+		if ($this->progressed) {
42
+			return $this;
43
+		}
44
+		if ($blank) {
45
+			$teams = $this->from->isPlayed() ? $this->from->sortTeams(null, $this->filters) : $this->from->simulate($this->filters);
46
+		} else {
47
+			$teams = $this->from->sortTeams(null, $this->filters);
48
+		}
44 49
 
45
-		if (count($this->filters) === 0 || $this->len !== null || $this->start !== 0) $next = array_splice($teams, $this->start, ($this->len === null ? count($teams) : $this->len));
46
-		else $next = $teams;
50
+		if (count($this->filters) === 0 || $this->len !== null || $this->start !== 0) {
51
+			$next = array_splice($teams, $this->start, ($this->len === null ? count($teams) : $this->len));
52
+		} else {
53
+			$next = $teams;
54
+		}
47 55
 
48 56
 		$i = 1;
49 57
 
@@ -51,12 +59,15 @@  discard block
 block discarded – undo
51 59
 			if ($blank) {
52 60
 				$this->to->addTeam(new BlankTeam($this.' - '.$i, $team, $this->from, $this));
53 61
 				$i++;
62
+			} else {
63
+				$team->sumPoints += $this->from->progressPoints;
54 64
 			}
55
-			else $team->sumPoints += $this->from->progressPoints;
56 65
 		}
57 66
 
58 67
 		$this->from->addProgressed($next);
59
-		if (!$blank) $this->to->addTeam($next);
68
+		if (!$blank) {
69
+			$this->to->addTeam($next);
70
+		}
60 71
 		$this->progressed = true;
61 72
 		return $this;
62 73
 	}
Please login to merge, or discard this patch.