Completed
Push — master ( d2c914...9aea1c )
by Tomáš
03:16
created
src/TournamentGenerator/Round.php 1 patch
Braces   +15 added lines, -5 removed lines patch added patch discarded remove patch
@@ -71,9 +71,13 @@  discard block
 block discarded – undo
71 71
 		return $this->games;
72 72
 	}
73 73
 	public function isPlayed(){
74
-		if (count($this->games) === 0) return false;
74
+		if (count($this->games) === 0) {
75
+			return false;
76
+		}
75 77
 		foreach ($this->groups as $group) {
76
-			if (!$group->isPlayed()) return false;
78
+			if (!$group->isPlayed()) {
79
+				return false;
80
+			}
77 81
 		}
78 82
 		return true;
79 83
 	}
@@ -97,7 +101,9 @@  discard block
 block discarded – undo
97 101
 			}
98 102
 			$this->teams = $teams;
99 103
 		}
100
-		if ($ordered) $teams = $this->sortTeams($ordering);
104
+		if ($ordered) {
105
+			$teams = $this->sortTeams($ordering);
106
+		}
101 107
 
102 108
 		// APPLY FILTERS
103 109
 		$filter = new Filter($this->getGroups(), $filters);
@@ -116,14 +122,18 @@  discard block
 block discarded – undo
116 122
 
117 123
 	public function splitTeams(Group ...$groups) {
118 124
 
119
-		if (count($groups) === 0) $groups = $this->getGroups();
125
+		if (count($groups) === 0) {
126
+			$groups = $this->getGroups();
127
+		}
120 128
 
121 129
 		$teams = $this->getTeams();
122 130
 		shuffle($teams);
123 131
 
124 132
 		while (count($teams) > 0) {
125 133
 			foreach ($groups as $group) {
126
-				if (count($teams) > 0) $group->addTeam(array_shift($teams));
134
+				if (count($teams) > 0) {
135
+					$group->addTeam(array_shift($teams));
136
+				}
127 137
 			}
128 138
 		}
129 139
 		return $this;
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   +29 added lines, -14 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
 			}
@@ -43,12 +42,18 @@  discard block
 block discarded – undo
43 42
 		switch (strtolower($how)) {
44 43
 			case 'and':
45 44
 				foreach ($teams as $tkey => $team) {
46
-					if (!$this->filterAnd($team, $filters)) unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY
45
+					if (!$this->filterAnd($team, $filters)) {
46
+						unset($teams[$tkey]);
47
+					}
48
+					// IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY
47 49
 				}
48 50
 				return true;
49 51
 			case 'or':
50 52
 				foreach ($teams as $tkey => $team) {
51
-					if (!$this->filterOr($team, $filters)) unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY
53
+					if (!$this->filterOr($team, $filters)) {
54
+						unset($teams[$tkey]);
55
+					}
56
+					// IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY
52 57
 				}
53 58
 				return true;
54 59
 		}
@@ -60,18 +65,23 @@  discard block
 block discarded – undo
60 65
 			if (is_array($value)) {
61 66
 				switch (strtolower($key)) {
62 67
 					case 'and':
63
-						if (!$this->filterAnd($team, $value)) return false;
68
+						if (!$this->filterAnd($team, $value)) {
69
+							return false;
70
+						}
64 71
 						break;
65 72
 					case 'or':
66
-						if (!$this->filterOr($team, $value)) return false;
73
+						if (!$this->filterOr($team, $value)) {
74
+							return false;
75
+						}
67 76
 						break;
68 77
 					default:
69 78
 						throw new \Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".');
70 79
 				}
71 80
 				continue;
72
-			}
73
-			elseif ($value instanceof TeamFilter) {
74
-				if (!$value->validate($team, $this->getGroupsIds(), 'sum', $this->groups[0])) return false;
81
+			} elseif ($value instanceof TeamFilter) {
82
+				if (!$value->validate($team, $this->getGroupsIds(), 'sum', $this->groups[0])) {
83
+					return false;
84
+				}
75 85
 				continue;
76 86
 			}
77 87
 			throw new \Exception('Filter ['.$key.'] is not an instance of TeamFilter class');
@@ -83,18 +93,23 @@  discard block
 block discarded – undo
83 93
 			if (is_array($value)) {
84 94
 				switch (strtolower($key)) {
85 95
 					case 'and':
86
-						if ($this->filterAnd($team, $value)) return true;
96
+						if ($this->filterAnd($team, $value)) {
97
+							return true;
98
+						}
87 99
 						break;
88 100
 					case 'or':
89
-						if ($this->filterOr($team, $value)) return true;
101
+						if ($this->filterOr($team, $value)) {
102
+							return true;
103
+						}
90 104
 						break;
91 105
 					default:
92 106
 						throw new \Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".');
93 107
 				}
94 108
 				continue;
95
-			}
96
-			elseif ($value instanceof TeamFilter) {
97
-				if ($value->validate($team, $this->getGroupsIds(), 'sum', $this->groups[0])) return true;
109
+			} elseif ($value instanceof TeamFilter) {
110
+				if ($value->validate($team, $this->getGroupsIds(), 'sum', $this->groups[0])) {
111
+					return true;
112
+				}
98 113
 				continue;
99 114
 			}
100 115
 			throw new \Exception('Filter ['.$key.'] is not an instance of TeamFilter class');
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(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
 
@@ -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/Tournament.php 1 patch
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.
src/TournamentGenerator/Group.php 1 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
 		Utilis\Sorter\Teams::sortGroup($this->teams, $this, $ordering);
84 88
 		return $this->getTeams(false, $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/Progression.php 1 patch
Braces   +15 added lines, -6 removed lines patch added patch discarded remove patch
@@ -33,11 +33,17 @@  discard block
 block discarded – undo
33 33
 	}
34 34
 
35 35
 	public function progress(bool $blank = false) {
36
-		if ($blank) $teams = $this->from->isPlayed() ? $this->from->sortTeams(null, $this->filters) : $this->from->simulate($this->filters);
37
-		else $teams = $this->from->sortTeams(null, $this->filters);
36
+		if ($blank) {
37
+			$teams = $this->from->isPlayed() ? $this->from->sortTeams(null, $this->filters) : $this->from->simulate($this->filters);
38
+		} else {
39
+			$teams = $this->from->sortTeams(null, $this->filters);
40
+		}
38 41
 
39
-		if (count($this->filters) === 0 || $this->len !== null || $this->start !== 0) $next = array_splice($teams, $this->start, ($this->len === null ? count($teams) : $this->len));
40
-		else $next = $teams;
42
+		if (count($this->filters) === 0 || $this->len !== null || $this->start !== 0) {
43
+			$next = array_splice($teams, $this->start, ($this->len === null ? count($teams) : $this->len));
44
+		} else {
45
+			$next = $teams;
46
+		}
41 47
 
42 48
 		$i = 1;
43 49
 
@@ -45,12 +51,15 @@  discard block
 block discarded – undo
45 51
 			if ($blank) {
46 52
 				$this->to->addTeam(new BlankTeam($this.' - '.$i, $team));
47 53
 				$i++;
54
+			} else {
55
+				$team->sumPoints += $this->from->progressPoints;
48 56
 			}
49
-			else $team->sumPoints += $this->from->progressPoints;
50 57
 		}
51 58
 
52 59
 		$this->from->addProgressed($next);
53
-		if (!$blank) $this->to->addTeam($next);
60
+		if (!$blank) {
61
+			$this->to->addTeam($next);
62
+		}
54 63
 		return $this;
55 64
 	}
56 65
 
Please login to merge, or discard this patch.