Completed
Push — master ( c4e89c...485366 )
by Tomáš
01:34
created
src/classes/class_tournament.php 2 patches
Spacing   +6 added lines, -6 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() {
@@ -55,16 +55,16 @@  discard block
 block discarded – undo
55 55
 	public function getCategoryWait() {
56 56
 		return $this->expectedCategoryWait;
57 57
 	}
58
-	public function getTournamentTime(){
58
+	public function getTournamentTime() {
59 59
 		$games = count($this->getGames());
60 60
 		return $games*$this->expectedPlay+$games*$this->expectedGameWait+count($this->getRounds())*$this->expectedRoundWait+count($this->getCategories())*$this->expectedCategoryWait;
61 61
 	}
62 62
 
63
-	public function allowSkip(){
63
+	public function allowSkip() {
64 64
 		$this->allowSkip = true;
65 65
 		return $this;
66 66
 	}
67
-	public function disallowSkip(){
67
+	public function disallowSkip() {
68 68
 		$this->allowSkip = false;
69 69
 		return $this;
70 70
 	}
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 		return $this->allowSkip;
77 77
 	}
78 78
 
79
-	public function addCategory(Category ...$categories){
79
+	public function addCategory(Category ...$categories) {
80 80
 		foreach ($categories as $category) {
81 81
 			if ($category instanceof Category) $this->categories[] = $category;
82 82
 			else throw new \Exception('Trying to add category which is not an instance of the Category class.');
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 
118 118
 	public function addTeam(...$teams) {
119 119
 		foreach ($teams as $team) {
120
-			if ($team instanceof Team)  {
120
+			if ($team instanceof Team) {
121 121
 				$this->teams[] = $team;
122 122
 				continue;
123 123
 			}
Please login to merge, or discard this patch.
Braces   +26 added lines, -11 removed lines patch added patch discarded remove patch
@@ -78,8 +78,11 @@  discard block
 block discarded – undo
78 78
 
79 79
 	public function addCategory(Category ...$categories){
80 80
 		foreach ($categories as $category) {
81
-			if ($category instanceof Category) $this->categories[] = $category;
82
-			else throw new \Exception('Trying to add category which is not an instance of the Category class.');
81
+			if ($category instanceof Category) {
82
+				$this->categories[] = $category;
83
+			} else {
84
+				throw new \Exception('Trying to add category which is not an instance of the Category class.');
85
+			}
83 86
 		}
84 87
 		return $this;
85 88
 	}
@@ -94,8 +97,11 @@  discard block
 block discarded – undo
94 97
 
95 98
 	public function addRound(Round ...$rounds) {
96 99
 		foreach ($rounds as $round) {
97
-			if ($round instanceof Round) $this->rounds[] = $round;
98
-			else throw new \Exception('Trying to add round which is not an instance of the Round class.');
100
+			if ($round instanceof Round) {
101
+				$this->rounds[] = $round;
102
+			} else {
103
+				throw new \Exception('Trying to add round which is not an instance of the Round class.');
104
+			}
99 105
 		}
100 106
 		return $this;
101 107
 	}
@@ -120,8 +126,7 @@  discard block
 block discarded – undo
120 126
 			if ($team instanceof Team)  {
121 127
 				$this->teams[] = $team;
122 128
 				continue;
123
-			}
124
-			elseif (gettype($team) === 'array') {
129
+			} elseif (gettype($team) === 'array') {
125 130
 				$teams = array_merge($teams, array_filter($team, function($a) {
126 131
 					return ($a instanceof Team);
127 132
 				}));
@@ -147,7 +152,9 @@  discard block
 block discarded – undo
147 152
 			}
148 153
 			$this->teams = $teams;
149 154
 		}
150
-		if ($ordered) $this->sortTeams($ordering);
155
+		if ($ordered) {
156
+			$this->sortTeams($ordering);
157
+		}
151 158
 		return $this->teams;
152 159
 	}
153 160
 	public function sortTeams($ordering = \POINTS) {
@@ -170,7 +177,9 @@  discard block
 block discarded – undo
170 177
 
171 178
 	public function splitTeams(Round ...$wheres) {
172 179
 
173
-		if (count($wheres) === 0) $wheres = $this->getRounds();
180
+		if (count($wheres) === 0) {
181
+			$wheres = $this->getRounds();
182
+		}
174 183
 
175 184
 		foreach ($wheres as $key => $value) {
176 185
 			if (gettype($value) === 'array') {
@@ -185,7 +194,9 @@  discard block
 block discarded – undo
185 194
 
186 195
 		while (count($teams) > 0) {
187 196
 			foreach ($wheres as $where) {
188
-				if (count($teams) > 0) $where->addTeam(array_shift($teams));
197
+				if (count($teams) > 0) {
198
+					$where->addTeam(array_shift($teams));
199
+				}
189 200
 			}
190 201
 		}
191 202
 		foreach ($wheres as $where) {
@@ -197,13 +208,17 @@  discard block
 block discarded – undo
197 208
 	public function genGamesSimulate(bool $returnTime = false) {
198 209
 		$games = Utilis\Simulator::simulateTournament($this);
199 210
 
200
-		if ($returnTime) return $this->getTournamentTime();
211
+		if ($returnTime) {
212
+			return $this->getTournamentTime();
213
+		}
201 214
 		return $games;
202 215
 	}
203 216
 	public function genGamesSimulateReal(bool $returnTime = false) {
204 217
 		$games = Utilis\Simulator::simulateTournamentReal($this);
205 218
 
206
-		if ($returnTime) return $this->getTournamentTime();
219
+		if ($returnTime) {
220
+			return $this->getTournamentTime();
221
+		}
207 222
 		return $games;
208 223
 	}
209 224
 
Please login to merge, or discard this patch.
src/classes/class_filter.php 1 patch
Braces   +32 added lines, -20 removed lines patch added patch discarded remove patch
@@ -26,27 +26,31 @@  discard block
 block discarded – undo
26 26
 				switch (strtolower($key)) {
27 27
 					case 'and':
28 28
 						foreach ($teams as $tkey => $team) {
29
-							if (!$this->filterAnd($team, $filter)) unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY
29
+							if (!$this->filterAnd($team, $filter)) {
30
+								unset($teams[$tkey]);
31
+							}
32
+							// IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY
30 33
 						}
31 34
 						break;
32 35
 					case 'or':
33 36
 						foreach ($teams as $tkey => $team) {
34
-							if (!$this->filterOr($team, $filter)) unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY
37
+							if (!$this->filterOr($team, $filter)) {
38
+								unset($teams[$tkey]);
39
+							}
40
+							// IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY
35 41
 						}
36 42
 						break;
37 43
 					default:
38 44
 						throw new \Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".');
39 45
 						break;
40 46
 				}
41
-			}
42
-			elseif ($filter instanceof TeamFilter) {
47
+			} elseif ($filter instanceof TeamFilter) {
43 48
 				foreach ($teams as $tkey => $team) {
44 49
 					if (!$filter->validate($team, $this->group->id, 'sum', $this->group)) {
45 50
 						unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY
46 51
 					}
47 52
 				}
48
-			}
49
-			else {
53
+			} else {
50 54
 				throw new \Exception('Filer ['.$key.'] is not an instance of TeamFilter class');
51 55
 			}
52 56
 		}
@@ -58,20 +62,24 @@  discard block
 block discarded – undo
58 62
 			if (gettype($value) === 'array') {
59 63
 				switch (strtolower($key)) {
60 64
 					case 'and':
61
-						if ($this->filterAnd($team, $value)) return false;
65
+						if ($this->filterAnd($team, $value)) {
66
+							return false;
67
+						}
62 68
 						break;
63 69
 					case 'or':
64
-						if ($this->filterOr($team, $value)) return false;
70
+						if ($this->filterOr($team, $value)) {
71
+							return false;
72
+						}
65 73
 						break;
66 74
 					default:
67 75
 						throw new \Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".');
68 76
 						break;
69 77
 				}
70
-			}
71
-			elseif ($value instanceof TeamFilter) {
72
-				if (!$value->validate($team, $this->group->id, 'sum', $this->group)) return false;
73
-			}
74
-			else {
78
+			} elseif ($value instanceof TeamFilter) {
79
+				if (!$value->validate($team, $this->group->id, 'sum', $this->group)) {
80
+					return false;
81
+				}
82
+			} else {
75 83
 				throw new \Exception('Filer ['.$key.'] is not an instance of TeamFilter class');
76 84
 			}
77 85
 		}
@@ -82,20 +90,24 @@  discard block
 block discarded – undo
82 90
 			if (gettype($value) === 'array') {
83 91
 				switch (strtolower($key)) {
84 92
 					case 'and':
85
-						if ($this->filterAnd($team, $value)) return true;
93
+						if ($this->filterAnd($team, $value)) {
94
+							return true;
95
+						}
86 96
 						break;
87 97
 					case 'or':
88
-						if ($this->filterOr($team, $value)) return true;
98
+						if ($this->filterOr($team, $value)) {
99
+							return true;
100
+						}
89 101
 						break;
90 102
 					default:
91 103
 						throw new \Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".');
92 104
 						break;
93 105
 				}
94
-			}
95
-			elseif ($value instanceof TeamFilter) {
96
-				if (!$value->validate($team, $this->group->id, 'sum', $this->group)) return true;
97
-			}
98
-			else {
106
+			} elseif ($value instanceof TeamFilter) {
107
+				if (!$value->validate($team, $this->group->id, 'sum', $this->group)) {
108
+					return true;
109
+				}
110
+			} else {
99 111
 				throw new \Exception('Filer ['.$key.'] is not an instance of TeamFilter class');
100 112
 			}
101 113
 		}
Please login to merge, or discard this patch.
src/classes/class_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/classes/class_group.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -54,11 +54,11 @@  discard block
 block discarded – undo
54 54
 		return 'Group '.$this->name;
55 55
 	}
56 56
 
57
-	public function allowSkip(){
57
+	public function allowSkip() {
58 58
 		$this->generator->allowSkip();
59 59
 		return $this;
60 60
 	}
61
-	public function disallowSkip(){
61
+	public function disallowSkip() {
62 62
 		$this->generator->disallowSkip();
63 63
 		return $this;
64 64
 	}
@@ -194,11 +194,11 @@  discard block
 block discarded – undo
194 194
 		$this->games[] = $g;
195 195
 		return $g;
196 196
 	}
197
-	public function addGame(...$games){
197
+	public function addGame(...$games) {
198 198
 		foreach ($games as $key => $game) {
199 199
 			if (gettype($game) === 'array') {
200 200
 				unset($games[$key]);
201
-				$games = array_merge($games, array_filter($game, function($a){ return ($a instanceof Game); }));
201
+				$games = array_merge($games, array_filter($game, function($a) { return ($a instanceof Game); }));
202 202
 				continue;
203 203
 			}
204 204
 			if (!$game instanceof Game) throw new \Exception('Trying to add game which is not instance of Game object.');
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
 		}
225 225
 		return $this;
226 226
 	}
227
-	public function isPlayed(){
227
+	public function isPlayed() {
228 228
 		foreach ($this->games as $game) {
229 229
 			if (!$game->isPlayed()) return false;
230 230
 		}
Please login to merge, or discard this patch.
Braces   +23 added lines, -9 removed lines patch added patch discarded remove patch
@@ -99,8 +99,11 @@  discard block
 block discarded – undo
99 99
 	public function getTeams($filters = []) {
100 100
 		$teams = $this->teams;
101 101
 
102
-		if (gettype($filters) !== 'array' && $filters instanceof TeamFilter) $filters = [$filters];
103
-		elseif (gettype($filters) !== 'array') $filters = [];
102
+		if (gettype($filters) !== 'array' && $filters instanceof TeamFilter) {
103
+			$filters = [$filters];
104
+		} elseif (gettype($filters) !== 'array') {
105
+			$filters = [];
106
+		}
104 107
 
105 108
 		// APPLY FILTERS
106 109
 		$filter = new Filter($this, $filters);
@@ -125,7 +128,9 @@  discard block
 block discarded – undo
125 128
 		return $t;
126 129
 	}
127 130
 	public function sortTeams($filters = [], $ordering = null) {
128
-		if (!isset($ordering)) $ordering = $this->ordering;
131
+		if (!isset($ordering)) {
132
+			$ordering = $this->ordering;
133
+		}
129 134
 		Utilis\Sorter\Teams::sortGroup($this->teams, $this, $ordering);
130 135
 		return $this->getTeams($filters);
131 136
 	}
@@ -139,7 +144,9 @@  discard block
 block discarded – undo
139 144
 	}
140 145
 
141 146
 	public function setOrdering(string $ordering = \POINTS) {
142
-		if (!in_array($ordering, orderingTypes)) throw new \Exception('Unknown group ordering: '.$ordering);
147
+		if (!in_array($ordering, orderingTypes)) {
148
+			throw new \Exception('Unknown group ordering: '.$ordering);
149
+		}
143 150
 		$this->ordering = $ordering;
144 151
 		return $this;
145 152
 	}
@@ -171,8 +178,9 @@  discard block
 block discarded – undo
171 178
 	}
172 179
 	public function addProgressed(...$teams) {
173 180
 		foreach ($teams as $team) {
174
-			if ($team instanceOf Team) $this->progressed[] = $team->id;
175
-			elseif (gettype($team) === 'array') {
181
+			if ($team instanceOf Team) {
182
+				$this->progressed[] = $team->id;
183
+			} elseif (gettype($team) === 'array') {
176 184
 				$this->progressed = array_merge($this->progressed, array_filter($team, function($a) {
177 185
 					return ($a instanceof Team);
178 186
 				}));
@@ -201,7 +209,9 @@  discard block
 block discarded – undo
201 209
 				$games = array_merge($games, array_filter($game, function($a){ return ($a instanceof Game); }));
202 210
 				continue;
203 211
 			}
204
-			if (!$game instanceof Game) throw new \Exception('Trying to add game which is not instance of Game object.');
212
+			if (!$game instanceof Game) {
213
+				throw new \Exception('Trying to add game which is not instance of Game object.');
214
+			}
205 215
 			$this->games[] = $game;
206 216
 		}
207 217
 		return $this;
@@ -210,7 +220,9 @@  discard block
 block discarded – undo
210 220
 		return $this->games;
211 221
 	}
212 222
 	public function orderGames() {
213
-		if (count($this->games) <= 4) return $this->games;
223
+		if (count($this->games) <= 4) {
224
+			return $this->games;
225
+		}
214 226
 		$this->games = $this->generator->orderGames();
215 227
 		return $this->games;
216 228
 	}
@@ -226,7 +238,9 @@  discard block
 block discarded – undo
226 238
 	}
227 239
 	public function isPlayed(){
228 240
 		foreach ($this->games as $game) {
229
-			if (!$game->isPlayed()) return false;
241
+			if (!$game->isPlayed()) {
242
+				return false;
243
+			}
230 244
 		}
231 245
 		return true;
232 246
 	}
Please login to merge, or discard this patch.
src/classes/tournament_presets/class_doubleElim.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 		$groupIds = [];
32 32
 		$allGroups = [];
33 33
 
34
-		for ($i=1; $i <= $startGroups; $i++) {
34
+		for ($i = 1; $i <= $startGroups; $i++) {
35 35
 			$g = $startRound->group([
36 36
 				'name' => 'Start group - '.$i,
37 37
 				'inGame' => 2,
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 		// SPLIT TEAMS EVENLY
46 46
 		$this->splitTeams();
47 47
 
48
-		for ($r=2; $r <= $roundsNum-1; $r++) {
48
+		for ($r = 2; $r <= $roundsNum-1; $r++) {
49 49
 			$groups = [];
50 50
 			$losingGroups = [];
51 51
 			$round = $this->round('Round '.$r);
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 	private function calcByes(int $countTeams, int &$nextPow) {
90 90
 		$byes = 0;
91 91
 		$nextPow = $countTeams;
92
-		if ( !\TournamentGenerator\isPowerOf2($countTeams) ) {
92
+		if (!\TournamentGenerator\isPowerOf2($countTeams)) {
93 93
 			$nextPow = bindec(str_pad(1, strlen(decbin($countTeams))+1, 0, STR_PAD_RIGHT));
94 94
 			$byes = $nextPow-$countTeams;
95 95
 		}
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 	}
98 98
 	private function generateWinSide(int &$r, int &$byes, int &$countTeams, \TournamentGenerator\Round &$round, array &$allGroups, array &$groups, \TournamentGenerator\Group &$lastWinningGroup = null, array &$previousGroups = []) {
99 99
 		$order = 1;
100
-		for ($g=1; $g <= (($countTeams+$byes)/pow(2, $r)); $g++) {
100
+		for ($g = 1; $g <= (($countTeams+$byes)/pow(2, $r)); $g++) {
101 101
 			$group = $round->group([
102 102
 				'name' => 'Round '.$r.' - win '.$g,
103 103
 				'inGame' => 2,
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 		$losingGroupTeamsCount = count($previousLosingGroups)+count($previousGroups);
118 118
 		$order = 2;
119 119
 		if (\TournamentGenerator\isPowerOf2($losingGroupTeamsCount)) { // IF THE NUMBER OF TEAMS IS A POWER OF 2, GENERATE GROUPS WITHOUT BYES
120
-			for ($g=1; $g <= $losingGroupTeamsCount/2; $g++) {
120
+			for ($g = 1; $g <= $losingGroupTeamsCount/2; $g++) {
121 121
 				$group = $round->group([
122 122
 					'name' => 'Round '.$r.' - loss '.$g,
123 123
 					'inGame' => 2,
@@ -145,11 +145,11 @@  discard block
 block discarded – undo
145 145
 			$n = (floor(count($previousLosingGroups)/2)+$losingByes);
146 146
 			$byesGroupsNums = [];
147 147
 			$byesProgressed = 0;
148
-			for ($i=0; $i < $losingByes; $i++) {
148
+			for ($i = 0; $i < $losingByes; $i++) {
149 149
 				$byesGroupsNums[] = $n-($i*2);
150 150
 			}
151 151
 			$lastGroup = 0;
152
-			for ($g=1; $g <= ((count($previousLosingGroups)/2)+$losingByes); $g++) {
152
+			for ($g = 1; $g <= ((count($previousLosingGroups)/2)+$losingByes); $g++) {
153 153
 				$group = $round->group([
154 154
 					'name' => 'Round '.$r.' - loss '.$g,
155 155
 					'inGame' => 2,
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 				}
167 167
 				else {
168 168
 					$previousLosingGroups[$lastGroup]->progression($group, 0, 1); // PROGRESS FROM LOSING GROUP BEFORE
169
-					if (isset($previousLosingGroups[$lastGroup + 1])) $previousLosingGroups[$lastGroup + 1]->progression($group, 0, 1); // PROGREESS FROM LOSING GROUP BEFORE
169
+					if (isset($previousLosingGroups[$lastGroup+1])) $previousLosingGroups[$lastGroup+1]->progression($group, 0, 1); // PROGREESS FROM LOSING GROUP BEFORE
170 170
 					$lastGroup += 2;
171 171
 				}
172 172
 			}
Please login to merge, or discard this patch.
Braces   +18 added lines, -10 removed lines patch added patch discarded remove patch
@@ -13,7 +13,9 @@  discard block
 block discarded – undo
13 13
 
14 14
 		$countTeams = count($this->getTeams());
15 15
 
16
-		if ($countTeams < 3) throw new \Exception('Double elimination is possible for minimum of 3 teams - '.$countTeams.' teams given.');
16
+		if ($countTeams < 3) {
17
+			throw new \Exception('Double elimination is possible for minimum of 3 teams - '.$countTeams.' teams given.');
18
+		}
17 19
 
18 20
 
19 21
 		// CALCULATE BYES
@@ -131,15 +133,19 @@  discard block
 block discarded – undo
131 133
 				if ($r === 2) { // FIRST LOSING ROUND
132 134
 					$previousGroups[2*($g-1)]->progression($group, 1, 1); // PROGRESS FROM STARTING GROUP
133 135
 					$previousGroups[(2*($g-1))+1]->progression($group, 1, 1); // PROGREESS FROM STARTING GROUP
134
-				}
135
-				elseif ($losingGroupTeamsCount >= 2) {
136
+				} elseif ($losingGroupTeamsCount >= 2) {
136 137
 					$previousLosingGroups[$g-1]->progression($group, 0, 1); // PROGRESS FROM LOSING GROUP BEFORE
137
-					if (isset(array_reverse($previousGroups)[$g-1])) array_reverse($previousGroups)[$g-1]->progression($group, 1, 1); // PROGREESS FROM WINNING GROUP BEFORE
138
-					else $previousLosingGroups[$g]->progression($group, 0, 1); // PROGRESS OTHER TEAM FROM LOSING GROUP BEEFORE
138
+					if (isset(array_reverse($previousGroups)[$g-1])) {
139
+						array_reverse($previousGroups)[$g-1]->progression($group, 1, 1);
140
+					}
141
+					// PROGREESS FROM WINNING GROUP BEFORE
142
+					else {
143
+						$previousLosingGroups[$g]->progression($group, 0, 1);
144
+					}
145
+					// PROGRESS OTHER TEAM FROM LOSING GROUP BEEFORE
139 146
 				}
140 147
 			}
141
-		}
142
-		else { // IF THE NUMBER OF TEAMS IS NOT A POWER OF 2, GENERATE GROUPS WITH BYES
148
+		} else { // IF THE NUMBER OF TEAMS IS NOT A POWER OF 2, GENERATE GROUPS WITH BYES
143 149
 			// LOOK FOR THE CLOSEST LOWER POWER OF 2
144 150
 			$losingByes = $losingGroupTeamsCount-bindec(str_pad(1, strlen(decbin($losingGroupTeamsCount)), 0, STR_PAD_RIGHT));
145 151
 			$n = (floor(count($previousLosingGroups)/2)+$losingByes);
@@ -163,10 +169,12 @@  discard block
 block discarded – undo
163 169
 				if (in_array($g, $byesGroupsNums) && isset($previousGroups[$byesProgressed])) { // EMPTY GROUP FROM BYE
164 170
 					$previousGroups[$byesProgressed]->progression($group, 1, 1); // PROGRESS FROM WINNING GROUP BEFORE
165 171
 					$byesProgressed++;
166
-				}
167
-				else {
172
+				} else {
168 173
 					$previousLosingGroups[$lastGroup]->progression($group, 0, 1); // PROGRESS FROM LOSING GROUP BEFORE
169
-					if (isset($previousLosingGroups[$lastGroup + 1])) $previousLosingGroups[$lastGroup + 1]->progression($group, 0, 1); // PROGREESS FROM LOSING GROUP BEFORE
174
+					if (isset($previousLosingGroups[$lastGroup + 1])) {
175
+						$previousLosingGroups[$lastGroup + 1]->progression($group, 0, 1);
176
+					}
177
+					// PROGREESS FROM LOSING GROUP BEFORE
170 178
 					$lastGroup += 2;
171 179
 				}
172 180
 			}
Please login to merge, or discard this patch.
src/classes/class_teamFilter.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -43,11 +43,11 @@
 block discarded – undo
43 43
 
44 44
 	private $groups = [];
45 45
 
46
-	function __construct(string $what = 'points', string $how = '>', $val = 0, $groups = []){
46
+	function __construct(string $what = 'points', string $how = '>', $val = 0, $groups = []) {
47 47
 		if (in_array(strtolower($what), ['points', 'score', 'wins', 'draws', 'losses', 'second', 'third', 'team', 'notprogressed', 'progressed'])) $this->what = strtolower($what);
48 48
 		if (in_array($how, ['>', '<', '>=', '<=', '=', '!='])) $this->how = $how;
49 49
 		if ((gettype($val) === 'integer' && strtolower($what) !== 'team') || ($val instanceof Team && strtolower($what) === 'team')) $this->val = $val;
50
-		$this->groups = array_map(function($a) { return $a->id; }, array_filter($groups, function($a) {return ($a instanceof Group);}));
50
+		$this->groups = array_map(function($a) { return $a->id; }, array_filter($groups, function($a) {return ($a instanceof Group); }));
51 51
 	}
52 52
 	public function __toString() {
53 53
 		return 'Filter: '.$this->what.' '.($this->what !== 'notprogressed' && $this->what !== 'progressed' ? $this->how.' '.$this->val : '');
Please login to merge, or discard this 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.