@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | |
23 | 23 | private $allowSkip = false; |
24 | 24 | |
25 | - function __construct(string $name = ''){ |
|
25 | + function __construct(string $name = '') { |
|
26 | 26 | $this->name = $name; |
27 | 27 | } |
28 | 28 | public function __toString() { |
@@ -57,16 +57,16 @@ discard block |
||
57 | 57 | public function getCategoryWait() { |
58 | 58 | return $this->expectedCategoryWait; |
59 | 59 | } |
60 | - public function getTournamentTime(){ |
|
60 | + public function getTournamentTime() { |
|
61 | 61 | $games = count($this->getGames()); |
62 | 62 | return $games*$this->expectedPlay+$games*$this->expectedGameWait+count($this->getRounds())*$this->expectedRoundWait+count($this->getCategories())*$this->expectedCategoryWait; |
63 | 63 | } |
64 | 64 | |
65 | - public function allowSkip(){ |
|
65 | + public function allowSkip() { |
|
66 | 66 | $this->allowSkip = true; |
67 | 67 | return $this; |
68 | 68 | } |
69 | - public function disallowSkip(){ |
|
69 | + public function disallowSkip() { |
|
70 | 70 | $this->allowSkip = false; |
71 | 71 | return $this; |
72 | 72 | } |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | return $this->allowSkip; |
79 | 79 | } |
80 | 80 | |
81 | - public function addCategory(Category ...$categories){ |
|
81 | + public function addCategory(Category ...$categories) { |
|
82 | 82 | foreach ($categories as $category) { |
83 | 83 | if ($category instanceof Category) $this->categories[] = $category; |
84 | 84 | else throw new \Exception('Trying to add category which is not an instance of the Category class.'); |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | |
120 | 120 | public function addTeam(...$teams) { |
121 | 121 | foreach ($teams as $team) { |
122 | - if ($team instanceof Team) { |
|
122 | + if ($team instanceof Team) { |
|
123 | 123 | $this->teams[] = $team; |
124 | 124 | } |
125 | 125 | elseif (gettype($team) === 'array') { |
@@ -78,8 +78,11 @@ discard block |
||
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 |
||
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 | } |
@@ -119,13 +125,15 @@ discard block |
||
119 | 125 | foreach ($teams as $team) { |
120 | 126 | if ($team instanceof Team) { |
121 | 127 | $this->teams[] = $team; |
122 | - } |
|
123 | - elseif (gettype($team) === 'array') { |
|
128 | + } elseif (gettype($team) === 'array') { |
|
124 | 129 | foreach ($team as $team2) { |
125 | - if ($team2 instanceof Team) $this->teams[] = $team2; |
|
130 | + if ($team2 instanceof Team) { |
|
131 | + $this->teams[] = $team2; |
|
132 | + } |
|
126 | 133 | } |
134 | + } else { |
|
135 | + throw new \Exception('Trying to add team which is not an instance of Team class'); |
|
127 | 136 | } |
128 | - else throw new \Exception('Trying to add team which is not an instance of Team class'); |
|
129 | 137 | } |
130 | 138 | return $this; |
131 | 139 | } |
@@ -170,18 +178,24 @@ discard block |
||
170 | 178 | |
171 | 179 | public function splitTeams(...$wheres) { |
172 | 180 | |
173 | - if (count($wheres) === 0) $wheres = array_merge($this->getRounds(), $this->getCategories()); |
|
181 | + if (count($wheres) === 0) { |
|
182 | + $wheres = array_merge($this->getRounds(), $this->getCategories()); |
|
183 | + } |
|
174 | 184 | |
175 | 185 | foreach ($wheres as $key => $value) { |
176 | 186 | if (gettype($value) === 'array') { |
177 | 187 | unset($wheres[$key]); |
178 | 188 | foreach ($value as $key2 => $value2) { |
179 | - if (!$value2 instanceof Round && !$value2 instanceof Category) throw new \Exception('Trying to split teams to another object, that is not instance of Category or Round.'); |
|
189 | + if (!$value2 instanceof Round && !$value2 instanceof Category) { |
|
190 | + throw new \Exception('Trying to split teams to another object, that is not instance of Category or Round.'); |
|
191 | + } |
|
180 | 192 | } |
181 | 193 | $wheres = array_merge($wheres, $value); |
182 | 194 | continue; |
183 | 195 | } |
184 | - if (!$value instanceof Round && !$value instanceof Category) throw new \Exception('Trying to split teams to another object, that is not instance of Category or Round.'); |
|
196 | + if (!$value instanceof Round && !$value instanceof Category) { |
|
197 | + throw new \Exception('Trying to split teams to another object, that is not instance of Category or Round.'); |
|
198 | + } |
|
185 | 199 | } |
186 | 200 | |
187 | 201 | $teams = $this->getTeams(); |
@@ -189,7 +203,9 @@ discard block |
||
189 | 203 | |
190 | 204 | while (count($teams) > 0) { |
191 | 205 | foreach ($wheres as $where) { |
192 | - if (count($teams) > 0) $where->addTeam(array_shift($teams)); |
|
206 | + if (count($teams) > 0) { |
|
207 | + $where->addTeam(array_shift($teams)); |
|
208 | + } |
|
193 | 209 | } |
194 | 210 | } |
195 | 211 | foreach ($wheres as $where) { |
@@ -204,8 +220,7 @@ discard block |
||
204 | 220 | foreach ($this->categories as $category) { |
205 | 221 | $games = array_merge($games, $category->genGamesSimulate()); |
206 | 222 | } |
207 | - } |
|
208 | - elseif (count($this->rounds) > 0) { |
|
223 | + } elseif (count($this->rounds) > 0) { |
|
209 | 224 | foreach ($this->rounds as $round) { |
210 | 225 | $games = array_merge($games, $round->genGames()); |
211 | 226 | $round->simulate()->progress(true); |
@@ -213,9 +228,12 @@ discard block |
||
213 | 228 | foreach ($this->rounds as $round) { |
214 | 229 | $round->resetGames(); |
215 | 230 | } |
231 | + } else { |
|
232 | + throw new \Exception('There are no rounds or categories to simulate games from.'); |
|
233 | + } |
|
234 | + if ($returnTime) { |
|
235 | + return $this->getTournamentTime(); |
|
216 | 236 | } |
217 | - else throw new \Exception('There are no rounds or categories to simulate games from.'); |
|
218 | - if ($returnTime) return $this->getTournamentTime(); |
|
219 | 237 | return $games; |
220 | 238 | } |
221 | 239 | public function genGamesSimulateReal(bool $returnTime = false) { |
@@ -224,16 +242,18 @@ discard block |
||
224 | 242 | foreach ($this->categories as $category) { |
225 | 243 | $games = array_merge($games, $category->genGamesSimulate()); |
226 | 244 | } |
227 | - } |
|
228 | - elseif (count($this->rounds) > 0) { |
|
245 | + } elseif (count($this->rounds) > 0) { |
|
229 | 246 | foreach ($this->rounds as $round) { |
230 | 247 | $games = array_merge($games, $round->genGames()); |
231 | 248 | $round->simulate(); |
232 | 249 | $round->progress(); |
233 | 250 | } |
251 | + } else { |
|
252 | + throw new \Exception('There are no rounds or categories to simulate games from.'); |
|
253 | + } |
|
254 | + if ($returnTime) { |
|
255 | + return $this->getTournamentTime(); |
|
234 | 256 | } |
235 | - else throw new \Exception('There are no rounds or categories to simulate games from.'); |
|
236 | - if ($returnTime) return $this->getTournamentTime(); |
|
237 | 257 | return $games; |
238 | 258 | } |
239 | 259 |
@@ -21,8 +21,11 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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(); |
@@ -19,11 +19,11 @@ discard block |
||
19 | 19 | $this->group = $group; |
20 | 20 | } |
21 | 21 | |
22 | - public function allowSkip(){ |
|
22 | + public function allowSkip() { |
|
23 | 23 | $this->allowSkip = true; |
24 | 24 | return $this; |
25 | 25 | } |
26 | - public function disallowSkip(){ |
|
26 | + public function disallowSkip() { |
|
27 | 27 | $this->allowSkip = false; |
28 | 28 | return $this; |
29 | 29 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | } |
47 | 47 | |
48 | 48 | public function setInGame(int $inGame) { |
49 | - if ($inGame < 2 || $inGame > 4) throw new \Exception('Expected 2,3 or 4 as inGame '.$inGame.' given'); |
|
49 | + if ($inGame < 2 || $inGame > 4) throw new \Exception('Expected 2,3 or 4 as inGame '.$inGame.' given'); |
|
50 | 50 | $this->inGame = $inGame; |
51 | 51 | return $this; |
52 | 52 | } |
@@ -67,17 +67,17 @@ discard block |
||
67 | 67 | switch ($this->type) { |
68 | 68 | case R_R:{ |
69 | 69 | $this->group->addGame($this->r_rGames()); |
70 | - break;} |
|
70 | + break; } |
|
71 | 71 | case TWO_TWO: |
72 | 72 | $teams = $this->group->getTeams(); |
73 | 73 | $discard = []; |
74 | 74 | shuffle($teams); |
75 | 75 | $count = count($teams); |
76 | - while (count($teams) % $this->inGame !== 0) { $discard[] = array_shift($teams); } |
|
76 | + while (count($teams)%$this->inGame !== 0) { $discard[] = array_shift($teams); } |
|
77 | 77 | |
78 | 78 | while (count($teams) > 0) { |
79 | 79 | $tInGame = []; |
80 | - for ($i=0; $i < $this->inGame; $i++) { $tInGame[] = array_shift($teams); } |
|
80 | + for ($i = 0; $i < $this->inGame; $i++) { $tInGame[] = array_shift($teams); } |
|
81 | 81 | $this->group->game($tInGame); |
82 | 82 | } |
83 | 83 | |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | } |
124 | 124 | $games = array_merge($games, $gamesTemp); |
125 | 125 | } |
126 | - break;} |
|
126 | + break; } |
|
127 | 127 | case 4:{ |
128 | 128 | $teamsB = $teams; |
129 | 129 | $lockedTeam1 = array_shift($teamsB); |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | $lockedTeam1 = array_shift($teamsB); |
141 | 141 | } |
142 | 142 | $games[] = new Game(array_merge([$lockedTeam1], $teamsB), $this->group); |
143 | - break;} |
|
143 | + break; } |
|
144 | 144 | } |
145 | 145 | return $games; |
146 | 146 | } |
@@ -172,8 +172,8 @@ discard block |
||
172 | 172 | // CYCLE 1 |
173 | 173 | // TEAM WHICH DIDN'T PLAY IN LAST GAME (< 4) |
174 | 174 | foreach ($games as $key => $game) { |
175 | - if ($this->orderCheckTeamsVal($game, $teams, [4,5,6,7])) { |
|
176 | - $this->moveCalculatedGames($game,$teams); |
|
175 | + if ($this->orderCheckTeamsVal($game, $teams, [4, 5, 6, 7])) { |
|
176 | + $this->moveCalculatedGames($game, $teams); |
|
177 | 177 | unset($games[$key]); |
178 | 178 | $found = true; |
179 | 179 | break; |
@@ -184,8 +184,8 @@ discard block |
||
184 | 184 | // CYCLE 2 |
185 | 185 | // ! TEAM WHICH PLAYED IN LAST TWO GAMES (NOT 6 or 7) |
186 | 186 | foreach ($games as $key => $game) { |
187 | - if ($this->orderCheckTeamsVal($game, $teams, [6,7])) { |
|
188 | - $this->moveCalculatedGames($game,$teams); |
|
187 | + if ($this->orderCheckTeamsVal($game, $teams, [6, 7])) { |
|
188 | + $this->moveCalculatedGames($game, $teams); |
|
189 | 189 | unset($games[$key]); |
190 | 190 | $found = true; |
191 | 191 | break; |
@@ -197,8 +197,8 @@ discard block |
||
197 | 197 | // NOT TEAM WHICH PLAYED IN LAST THREE GAMES (NOT 7) |
198 | 198 | // TEAMS THAT DIDN'T PLAY IN LAST GAME WILL PLAY THIS GAME (< 4) |
199 | 199 | foreach ($games as $key => $game) { |
200 | - if ($this->orderCheckTeamsVal($game, $teams, [7], [1,2,3])) { |
|
201 | - $this->moveCalculatedGames($game,$teams); |
|
200 | + if ($this->orderCheckTeamsVal($game, $teams, [7], [1, 2, 3])) { |
|
201 | + $this->moveCalculatedGames($game, $teams); |
|
202 | 202 | unset($games[$key]); |
203 | 203 | $found = true; |
204 | 204 | break; |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | // NOT TEAM WHICH PLAYED IN LAST THREE GAMES (NOT 7) |
211 | 211 | foreach ($games as $key => $game) { |
212 | 212 | if ($this->orderCheckTeamsVal($game, $teams, [7])) { |
213 | - $this->moveCalculatedGames($game,$teams); |
|
213 | + $this->moveCalculatedGames($game, $teams); |
|
214 | 214 | unset($games[$key]); |
215 | 215 | $found = true; |
216 | 216 | break; |
@@ -221,8 +221,8 @@ discard block |
||
221 | 221 | // CYCLE 5 |
222 | 222 | // TEAMS THAT DIDN'T PLAY IN LAST GAME WILL PLAY THIS GAME (< 4) |
223 | 223 | foreach ($games as $key => $game) { |
224 | - if ($this->orderCheckTeamsVal($game, $teams, [], [1,2,3])) { |
|
225 | - $this->moveCalculatedGames($game,$teams); |
|
224 | + if ($this->orderCheckTeamsVal($game, $teams, [], [1, 2, 3])) { |
|
225 | + $this->moveCalculatedGames($game, $teams); |
|
226 | 226 | unset($games[$key]); |
227 | 227 | $found = true; |
228 | 228 | break; |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | |
233 | 233 | // CYCLE 6 |
234 | 234 | // FIRST AVAILABLE GAME |
235 | - $this->moveCalculatedGames(array_shift($games),$teams); |
|
235 | + $this->moveCalculatedGames(array_shift($games), $teams); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | return $this->games; |
@@ -283,11 +283,11 @@ discard block |
||
283 | 283 | public static function circle_genGames2(array $teams = [], Group $group = null) { |
284 | 284 | $bracket = []; // ARRAY OF GAMES |
285 | 285 | |
286 | - if (count($teams) % 2 != 0) $teams[] = DUMMY_TEAM; // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY |
|
286 | + if (count($teams)%2 != 0) $teams[] = DUMMY_TEAM; // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY |
|
287 | 287 | |
288 | 288 | shuffle($teams); // SHUFFLE TEAMS FOR MORE RANDOMNESS |
289 | 289 | |
290 | - for ($i=0; $i < count($teams)-1; $i++) { |
|
290 | + for ($i = 0; $i < count($teams)-1; $i++) { |
|
291 | 291 | $bracket = array_merge($bracket, Generator::circle_saveBracket($teams, $group)); // SAVE CURRENT ROUND |
292 | 292 | |
293 | 293 | $teams = Generator::circle_rotateBracket($teams); // ROTATE TEAMS IN BRACKET |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | |
302 | 302 | $bracket = []; |
303 | 303 | |
304 | - for ($i=0; $i < count($teams)/2; $i++) { // GO THROUGH HALF OF THE TEAMS |
|
304 | + for ($i = 0; $i < count($teams)/2; $i++) { // GO THROUGH HALF OF THE TEAMS |
|
305 | 305 | |
306 | 306 | $home = $teams[$i]; |
307 | 307 | $reverse = array_reverse($teams); |
@@ -37,8 +37,11 @@ discard block |
||
37 | 37 | |
38 | 38 | |
39 | 39 | public function setType(/** @scrutinizer ignore-all */ string $type = R_R) { |
40 | - if (in_array($type, groupTypes)) $this->type = $type; |
|
41 | - else throw new \Exception('Unknown group type: '.$type); |
|
40 | + if (in_array($type, groupTypes)) { |
|
41 | + $this->type = $type; |
|
42 | + } else { |
|
43 | + throw new \Exception('Unknown group type: '.$type); |
|
44 | + } |
|
42 | 45 | return $this; |
43 | 46 | } |
44 | 47 | public function getType() { |
@@ -46,7 +49,9 @@ discard block |
||
46 | 49 | } |
47 | 50 | |
48 | 51 | public function setInGame(int $inGame) { |
49 | - if ($inGame < 2 || $inGame > 4) throw new \Exception('Expected 2,3 or 4 as inGame '.$inGame.' given'); |
|
52 | + if ($inGame < 2 || $inGame > 4) { |
|
53 | + throw new \Exception('Expected 2,3 or 4 as inGame '.$inGame.' given'); |
|
54 | + } |
|
50 | 55 | $this->inGame = $inGame; |
51 | 56 | return $this; |
52 | 57 | } |
@@ -55,7 +60,9 @@ discard block |
||
55 | 60 | } |
56 | 61 | |
57 | 62 | public function setMaxSize(int $maxSize) { |
58 | - if ($maxSize < 2) throw new \Exception('Max group size has to be at least 2, '.$maxSize.' given'); |
|
63 | + if ($maxSize < 2) { |
|
64 | + throw new \Exception('Max group size has to be at least 2, '.$maxSize.' given'); |
|
65 | + } |
|
59 | 66 | $this->maxSize = $maxSize; |
60 | 67 | return $this; |
61 | 68 | } |
@@ -81,7 +88,9 @@ discard block |
||
81 | 88 | $this->group->game($tInGame); |
82 | 89 | } |
83 | 90 | |
84 | - 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.' - allow skip '.($this->allowSkip ? 'True' : 'False')); |
|
91 | + if (count($discard) > 0 && !$this->allowSkip) { |
|
92 | + 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.' - allow skip '.($this->allowSkip ? 'True' : 'False')); |
|
93 | + } |
|
85 | 94 | break; |
86 | 95 | case COND_SPLIT: |
87 | 96 | $games = []; |
@@ -96,19 +105,24 @@ discard block |
||
96 | 105 | while ($g > 0) { |
97 | 106 | foreach ($games as $key => $group) { |
98 | 107 | $this->group->addGame(array_shift($games[$key])); |
99 | - if (count($games[$key]) === 0) unset($games[$key]); |
|
108 | + if (count($games[$key]) === 0) { |
|
109 | + unset($games[$key]); |
|
110 | + } |
|
100 | 111 | $g--; |
101 | 112 | } |
102 | 113 | } |
114 | + } else { |
|
115 | + $this->group->addGame($this->r_rGames()); |
|
103 | 116 | } |
104 | - else $this->group->addGame($this->r_rGames()); |
|
105 | 117 | break; |
106 | 118 | } |
107 | 119 | return $this->group->getGames(); |
108 | 120 | } |
109 | 121 | public function r_rGames(array $teams = []) { |
110 | 122 | $games = []; |
111 | - if (count($teams) === 0) $teams = $this->group->getTeams(); |
|
123 | + if (count($teams) === 0) { |
|
124 | + $teams = $this->group->getTeams(); |
|
125 | + } |
|
112 | 126 | switch ($this->inGame) { |
113 | 127 | case 2: |
114 | 128 | $games = Generator::circle_genGames2($teams, $this->group); |
@@ -149,7 +163,9 @@ discard block |
||
149 | 163 | |
150 | 164 | $games = $this->group->getGames(); |
151 | 165 | |
152 | - if (count($games) <= 4) return $games; |
|
166 | + if (count($games) <= 4) { |
|
167 | + return $games; |
|
168 | + } |
|
153 | 169 | |
154 | 170 | $this->games = []; |
155 | 171 | |
@@ -179,7 +195,9 @@ discard block |
||
179 | 195 | break; |
180 | 196 | } |
181 | 197 | } |
182 | - if ($found) continue; |
|
198 | + if ($found) { |
|
199 | + continue; |
|
200 | + } |
|
183 | 201 | |
184 | 202 | // CYCLE 2 |
185 | 203 | // ! TEAM WHICH PLAYED IN LAST TWO GAMES (NOT 6 or 7) |
@@ -191,7 +209,9 @@ discard block |
||
191 | 209 | break; |
192 | 210 | } |
193 | 211 | } |
194 | - if ($found) continue; |
|
212 | + if ($found) { |
|
213 | + continue; |
|
214 | + } |
|
195 | 215 | |
196 | 216 | // CYCLE 3 |
197 | 217 | // NOT TEAM WHICH PLAYED IN LAST THREE GAMES (NOT 7) |
@@ -204,7 +224,9 @@ discard block |
||
204 | 224 | break; |
205 | 225 | } |
206 | 226 | } |
207 | - if ($found) continue; |
|
227 | + if ($found) { |
|
228 | + continue; |
|
229 | + } |
|
208 | 230 | |
209 | 231 | // CYCLE 4 |
210 | 232 | // NOT TEAM WHICH PLAYED IN LAST THREE GAMES (NOT 7) |
@@ -216,7 +238,9 @@ discard block |
||
216 | 238 | break; |
217 | 239 | } |
218 | 240 | } |
219 | - if ($found) continue; |
|
241 | + if ($found) { |
|
242 | + continue; |
|
243 | + } |
|
220 | 244 | |
221 | 245 | // CYCLE 5 |
222 | 246 | // TEAMS THAT DIDN'T PLAY IN LAST GAME WILL PLAY THIS GAME (< 4) |
@@ -228,7 +252,9 @@ discard block |
||
228 | 252 | break; |
229 | 253 | } |
230 | 254 | } |
231 | - if ($found) continue; |
|
255 | + if ($found) { |
|
256 | + continue; |
|
257 | + } |
|
232 | 258 | |
233 | 259 | // CYCLE 6 |
234 | 260 | // FIRST AVAILABLE GAME |
@@ -269,11 +295,17 @@ discard block |
||
269 | 295 | $requiredTeams = array_filter($teams, function($a) use ($required) { return in_array($a, $required); }); |
270 | 296 | |
271 | 297 | foreach ($game->getTeamsIds() as $tid) { |
272 | - if (in_array($teams[$tid], $checkVals)) return false; |
|
273 | - if (isset($requiredTeams[$tid])) unset($requiredTeams[$tid]); |
|
298 | + if (in_array($teams[$tid], $checkVals)) { |
|
299 | + return false; |
|
300 | + } |
|
301 | + if (isset($requiredTeams[$tid])) { |
|
302 | + unset($requiredTeams[$tid]); |
|
303 | + } |
|
274 | 304 | } |
275 | 305 | |
276 | - if (count($requiredTeams) > 0) return false; |
|
306 | + if (count($requiredTeams) > 0) { |
|
307 | + return false; |
|
308 | + } |
|
277 | 309 | |
278 | 310 | return true; |
279 | 311 | |
@@ -283,7 +315,10 @@ discard block |
||
283 | 315 | public static function circle_genGames2(array $teams = [], Group $group = null) { |
284 | 316 | $bracket = []; // ARRAY OF GAMES |
285 | 317 | |
286 | - if (count($teams) % 2 != 0) $teams[] = DUMMY_TEAM; // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY |
|
318 | + if (count($teams) % 2 != 0) { |
|
319 | + $teams[] = DUMMY_TEAM; |
|
320 | + } |
|
321 | + // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY |
|
287 | 322 | |
288 | 323 | shuffle($teams); // SHUFFLE TEAMS FOR MORE RANDOMNESS |
289 | 324 | |
@@ -307,7 +342,10 @@ discard block |
||
307 | 342 | $reverse = array_reverse($teams); |
308 | 343 | $away = $reverse[$i]; |
309 | 344 | |
310 | - if (($home == DUMMY_TEAM || $away == DUMMY_TEAM)) continue; // SKIP WHEN DUMMY_TEAM IS PRESENT |
|
345 | + if (($home == DUMMY_TEAM || $away == DUMMY_TEAM)) { |
|
346 | + continue; |
|
347 | + } |
|
348 | + // SKIP WHEN DUMMY_TEAM IS PRESENT |
|
311 | 349 | |
312 | 350 | $bracket[] = new Game([$home, $away], $group); |
313 | 351 |
@@ -44,11 +44,19 @@ discard block |
||
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 | foreach ($groups as $group) { |
51 | - if ($group instanceof Group) $this->groups[] = $group->id; |
|
57 | + if ($group instanceof Group) { |
|
58 | + $this->groups[] = $group->id; |
|
59 | + } |
|
52 | 60 | } |
53 | 61 | } |
54 | 62 | public function __toString() { |
@@ -56,37 +64,54 @@ discard block |
||
56 | 64 | } |
57 | 65 | |
58 | 66 | public function validate(Team $team, $groupsId, string $operation = 'sum', Group $from = null) { |
59 | - if (count($this->groups) > 0) $groupsId = array_unique(array_merge($this->groups, (gettype($groupsId) === 'array' ? $groupsId : [$groupsId])), SORT_REGULAR); |
|
67 | + if (count($this->groups) > 0) { |
|
68 | + $groupsId = array_unique(array_merge($this->groups, (gettype($groupsId) === 'array' ? $groupsId : [$groupsId])), SORT_REGULAR); |
|
69 | + } |
|
60 | 70 | if ($this->what == 'team') { |
61 | 71 | switch ($this->how) { |
62 | 72 | case '=': |
63 | - if ($this->val === $team) return true; |
|
73 | + if ($this->val === $team) { |
|
74 | + return true; |
|
75 | + } |
|
64 | 76 | break; |
65 | 77 | case '!=': |
66 | - if ($this->val !== $team) return true; |
|
78 | + if ($this->val !== $team) { |
|
79 | + return true; |
|
80 | + } |
|
67 | 81 | break; |
68 | 82 | } |
69 | 83 | return false; |
70 | - } |
|
71 | - elseif ($this->what == 'notprogressed') { |
|
72 | - if ($from === null) throw new \Exception('Group $from was not defined.'); |
|
84 | + } elseif ($this->what == 'notprogressed') { |
|
85 | + if ($from === null) { |
|
86 | + throw new \Exception('Group $from was not defined.'); |
|
87 | + } |
|
73 | 88 | return !$from->isProgressed($team); |
74 | - } |
|
75 | - elseif ($this->what == 'progressed') { |
|
76 | - if ($from === null) throw new \Exception('Group $from was not defined.'); |
|
89 | + } elseif ($this->what == 'progressed') { |
|
90 | + if ($from === null) { |
|
91 | + throw new \Exception('Group $from was not defined.'); |
|
92 | + } |
|
77 | 93 | return $from->isProgressed($team); |
78 | 94 | } |
79 | - 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.'); |
|
95 | + if (gettype($groupsId) === 'array' && !in_array(strtolower($operation), ['sum', 'avg', 'max', 'min'])) { |
|
96 | + throw new \Exception('Unknown operation of '.$operation.'. Only "sum", "avg", "min", "max" possible.'); |
|
97 | + } |
|
80 | 98 | $comp = 0; |
81 | 99 | if (gettype($groupsId) === 'array' && count($groupsId) > 0) { |
82 | 100 | $sum = 0; |
83 | 101 | $max = null; |
84 | 102 | $min = null; |
85 | 103 | foreach ($groupsId as $id) { |
86 | - if (!isset($team->groupResults[$id])) continue; // IF TEAM DIDN'T PLAY IN THAT GROUP -> SKIP |
|
104 | + if (!isset($team->groupResults[$id])) { |
|
105 | + continue; |
|
106 | + } |
|
107 | + // IF TEAM DIDN'T PLAY IN THAT GROUP -> SKIP |
|
87 | 108 | $sum += $team->groupResults[$id][$this->what]; |
88 | - if ($team->groupResults[$id][$this->what] > $max || $max === null) $max = $team->groupResults[$id][$this->what]; |
|
89 | - if ($team->groupResults[$id][$this->what] < $min || $min === null) $min = $team->groupResults[$id][$this->what]; |
|
109 | + if ($team->groupResults[$id][$this->what] > $max || $max === null) { |
|
110 | + $max = $team->groupResults[$id][$this->what]; |
|
111 | + } |
|
112 | + if ($team->groupResults[$id][$this->what] < $min || $min === null) { |
|
113 | + $min = $team->groupResults[$id][$this->what]; |
|
114 | + } |
|
90 | 115 | } |
91 | 116 | switch (strtolower($operation)) { |
92 | 117 | case 'sum': |
@@ -102,11 +127,9 @@ discard block |
||
102 | 127 | $comp = $min; |
103 | 128 | break; |
104 | 129 | } |
105 | - } |
|
106 | - elseif (gettype($groupsId) === 'string' && isset($team->groupResults[$groupsId])) { |
|
130 | + } elseif (gettype($groupsId) === 'string' && isset($team->groupResults[$groupsId])) { |
|
107 | 131 | $comp = $team->groupResults[$groupsId][$this->what]; |
108 | - } |
|
109 | - else { |
|
132 | + } else { |
|
110 | 133 | throw new \Exception("Couldn't find group of id ".print_r($groupsId, true)); |
111 | 134 | } |
112 | 135 |
@@ -66,11 +66,11 @@ |
||
66 | 66 | if (count($error) > 0) throw new \Exception('Trying to add teams ('.count($error).') that are not instance of Team class'.PHP_EOL.print_r($error, true)); |
67 | 67 | return $this; |
68 | 68 | } |
69 | - public function getTeams(){ |
|
69 | + public function getTeams() { |
|
70 | 70 | return $this->teams; |
71 | 71 | } |
72 | - public function getTeamsIds(){ |
|
73 | - return array_map(function($a){ return $a->id; }, $this->teams); |
|
72 | + public function getTeamsIds() { |
|
73 | + return array_map(function($a) { return $a->id; }, $this->teams); |
|
74 | 74 | } |
75 | 75 | public function getTeam(string $id) { |
76 | 76 | foreach ($this->teams as $team) { |
@@ -33,11 +33,15 @@ discard block |
||
33 | 33 | $this->teams = $teams; |
34 | 34 | foreach ($this->teams as $team) { |
35 | 35 | foreach ($this->teams as $team2) { |
36 | - if ($team === $team2) continue; |
|
36 | + if ($team === $team2) { |
|
37 | + continue; |
|
38 | + } |
|
37 | 39 | $team->addGameWith($team2, $group); |
38 | 40 | } |
39 | 41 | } |
40 | - if (count($error) > 0) throw new \Exception('Trying to add teams ('.count($error).') that are not instance of Team class'.PHP_EOL.print_r($error, true)); |
|
42 | + if (count($error) > 0) { |
|
43 | + throw new \Exception('Trying to add teams ('.count($error).') that are not instance of Team class'.PHP_EOL.print_r($error, true)); |
|
44 | + } |
|
41 | 45 | } |
42 | 46 | |
43 | 47 | public function getGroup() { |
@@ -56,14 +60,18 @@ discard block |
||
56 | 60 | $team->addGame($this); |
57 | 61 | |
58 | 62 | foreach ($this->teams as $team2) { |
59 | - if ($team === $team2) continue; |
|
63 | + if ($team === $team2) { |
|
64 | + continue; |
|
65 | + } |
|
60 | 66 | if ($team instanceof Team) { |
61 | 67 | $team->addGameWith($team2, $this->group); |
62 | 68 | $team2->addGameWith($team, $this->group); |
63 | 69 | } |
64 | 70 | } |
65 | 71 | } |
66 | - if (count($error) > 0) throw new \Exception('Trying to add teams ('.count($error).') that are not instance of Team class'.PHP_EOL.print_r($error, true)); |
|
72 | + if (count($error) > 0) { |
|
73 | + throw new \Exception('Trying to add teams ('.count($error).') that are not instance of Team class'.PHP_EOL.print_r($error, true)); |
|
74 | + } |
|
67 | 75 | return $this; |
68 | 76 | } |
69 | 77 | public function getTeams(){ |
@@ -74,7 +82,9 @@ discard block |
||
74 | 82 | } |
75 | 83 | public function getTeam(string $id) { |
76 | 84 | foreach ($this->teams as $team) { |
77 | - if ($team->id === $id) return $team; |
|
85 | + if ($team->id === $id) { |
|
86 | + return $team; |
|
87 | + } |
|
78 | 88 | } |
79 | 89 | return false; |
80 | 90 | } |
@@ -85,13 +95,17 @@ discard block |
||
85 | 95 | * ) |
86 | 96 | */ |
87 | 97 | public function setResults(array $results = []) { |
88 | - if (count($this->results) === 0) $this->resetResults(); |
|
98 | + if (count($this->results) === 0) { |
|
99 | + $this->resetResults(); |
|
100 | + } |
|
89 | 101 | arsort($results); |
90 | 102 | $inGame = /** @scrutinizer ignore-call */ $this->group->getInGame(); |
91 | 103 | $i = 1; |
92 | 104 | foreach ($results as $id => $score) { |
93 | 105 | $team = $this->getTeam($id); |
94 | - if ($team === false) throw new \Exception('Couldn\'t find team with id of "'.$id.'"'); |
|
106 | + if ($team === false) { |
|
107 | + throw new \Exception('Couldn\'t find team with id of "'.$id.'"'); |
|
108 | + } |
|
95 | 109 | $this->results[$team->id] = ['score' => $score]; |
96 | 110 | $team->sumScore += $score; |
97 | 111 | $prev = prev($results); |
@@ -118,13 +132,11 @@ discard block |
||
118 | 132 | $this->drawIds[] = $team->id; |
119 | 133 | $team->addDraw($this->group->id); |
120 | 134 | $this->results[$team->id] += ['points' => $this->group->drawPoints, 'type' => 'draw']; |
121 | - } |
|
122 | - elseif ($i === 1) { |
|
135 | + } elseif ($i === 1) { |
|
123 | 136 | $this->winId = $team->id; |
124 | 137 | $team->addWin($this->group->id); |
125 | 138 | $this->results[$team->id] += ['points' => $this->group->winPoints, 'type' => 'win']; |
126 | - } |
|
127 | - else { |
|
139 | + } else { |
|
128 | 140 | $this->lossId = $team->id; |
129 | 141 | $team->addLoss($this->group->id); |
130 | 142 | $this->results[$team->id] += ['points' => $this->group->lostPoints, 'type' => 'loss']; |
@@ -220,7 +232,9 @@ discard block |
||
220 | 232 | } |
221 | 233 | |
222 | 234 | public function isPlayed() { |
223 | - if (count($this->results) > 0) return true; |
|
235 | + if (count($this->results) > 0) { |
|
236 | + return true; |
|
237 | + } |
|
224 | 238 | return false; |
225 | 239 | } |
226 | 240 | } |
@@ -57,11 +57,11 @@ discard block |
||
57 | 57 | return 'Group '.$this->name; |
58 | 58 | } |
59 | 59 | |
60 | - public function allowSkip(){ |
|
60 | + public function allowSkip() { |
|
61 | 61 | $this->generator->allowSkip(); |
62 | 62 | return $this; |
63 | 63 | } |
64 | - public function disallowSkip(){ |
|
64 | + public function disallowSkip() { |
|
65 | 65 | $this->generator->disallowSkip(); |
66 | 66 | return $this; |
67 | 67 | } |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | |
76 | 76 | public function addTeam(...$teams) { |
77 | 77 | foreach ($teams as $team) { |
78 | - if ($team instanceof Team) { |
|
78 | + if ($team instanceof Team) { |
|
79 | 79 | $this->teams[] = $team; |
80 | 80 | $team->groupResults[$this->id] = [ |
81 | 81 | 'group' => $this, |
@@ -169,13 +169,13 @@ discard block |
||
169 | 169 | if ($a->groupResults[$this->id]["points"] === $b->groupResults[$this->id]["points"]) return ($a->groupResults[$this->id]["score"] > $b->groupResults[$this->id]["score"] ? -1 : 1); |
170 | 170 | return ($a->groupResults[$this->id]["points"] > $b->groupResults[$this->id]["points"] ? -1 : 1); |
171 | 171 | }); |
172 | - break;} |
|
172 | + break; } |
|
173 | 173 | case SCORE:{ |
174 | 174 | usort($this->teams, function($a, $b) { |
175 | 175 | if ($a->groupResults[$this->id]["score"] === $b->groupResults[$this->id]["score"]) return 0; |
176 | 176 | return ($a->groupResults[$this->id]["score"] > $b->groupResults[$this->id]["score"] ? -1 : 1); |
177 | 177 | }); |
178 | - break;} |
|
178 | + break; } |
|
179 | 179 | } |
180 | 180 | return $this->getTeams($filters); |
181 | 181 | } |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | $this->games[] = $g; |
307 | 307 | return $g; |
308 | 308 | } |
309 | - public function addGame(...$games){ |
|
309 | + public function addGame(...$games) { |
|
310 | 310 | foreach ($games as $key => $game) { |
311 | 311 | if (gettype($game) === 'array') { |
312 | 312 | unset($games[$key]); |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | } |
351 | 351 | return $this; |
352 | 352 | } |
353 | - public function isPlayed(){ |
|
353 | + public function isPlayed() { |
|
354 | 354 | foreach ($this->games as $game) { |
355 | 355 | if ((isset($game) || !$this->getSkip()) && !$game->isPlayed()) return false; |
356 | 356 | } |
@@ -30,14 +30,18 @@ discard block |
||
30 | 30 | foreach ($settings as $key => $value) { |
31 | 31 | switch ($key) { |
32 | 32 | case 'name': |
33 | - if (gettype($value) !== 'string') throw new \Exception('Expected string as group name '.gettype($value).' given'); |
|
33 | + if (gettype($value) !== 'string') { |
|
34 | + throw new \Exception('Expected string as group name '.gettype($value).' given'); |
|
35 | + } |
|
34 | 36 | $this->name = $value; |
35 | 37 | break; |
36 | 38 | case 'type': |
37 | 39 | $this->generator->setType($value); |
38 | 40 | break; |
39 | 41 | case 'ordering': |
40 | - if (!in_array($value, orderingTypes)) throw new \Exception('Unknown group ordering: '.$value); |
|
42 | + if (!in_array($value, orderingTypes)) { |
|
43 | + throw new \Exception('Unknown group ordering: '.$value); |
|
44 | + } |
|
41 | 45 | $this->ordering = $value; |
42 | 46 | break; |
43 | 47 | case 'inGame': |
@@ -45,7 +49,9 @@ discard block |
||
45 | 49 | break; |
46 | 50 | case 'maxSize': |
47 | 51 | $value = (int) $value; |
48 | - if ($value > 1) $this->generator->setMaxSize($value); |
|
52 | + if ($value > 1) { |
|
53 | + $this->generator->setMaxSize($value); |
|
54 | + } |
|
49 | 55 | break; |
50 | 56 | case 'order': |
51 | 57 | $this->order = (int) $value; |
@@ -87,10 +93,11 @@ discard block |
||
87 | 93 | 'second' => 0, |
88 | 94 | 'third' => 0 |
89 | 95 | ]; |
90 | - } |
|
91 | - elseif (gettype($team) === 'array') { |
|
96 | + } elseif (gettype($team) === 'array') { |
|
92 | 97 | foreach ($team as $team2) { |
93 | - if ($team2 instanceof Team) $this->teams[] = $team2; |
|
98 | + if ($team2 instanceof Team) { |
|
99 | + $this->teams[] = $team2; |
|
100 | + } |
|
94 | 101 | $team2->groupResults[$this->id] = [ |
95 | 102 | 'group' => $this, |
96 | 103 | 'points' => 0, |
@@ -102,16 +109,20 @@ discard block |
||
102 | 109 | 'third' => 0 |
103 | 110 | ]; |
104 | 111 | } |
112 | + } else { |
|
113 | + throw new \Exception('Trying to add team which is not an instance of Team class'); |
|
105 | 114 | } |
106 | - else throw new \Exception('Trying to add team which is not an instance of Team class'); |
|
107 | 115 | } |
108 | 116 | return $this; |
109 | 117 | } |
110 | 118 | public function getTeams($filters = []) { |
111 | 119 | $teams = $this->teams; |
112 | 120 | |
113 | - if (gettype($filters) !== 'array' && $filters instanceof TeamFilter) $filters = [$filters]; |
|
114 | - elseif (gettype($filters) !== 'array') $filters = []; |
|
121 | + if (gettype($filters) !== 'array' && $filters instanceof TeamFilter) { |
|
122 | + $filters = [$filters]; |
|
123 | + } elseif (gettype($filters) !== 'array') { |
|
124 | + $filters = []; |
|
125 | + } |
|
115 | 126 | |
116 | 127 | // APPLY FILTERS |
117 | 128 | foreach ($filters as $key => $filter) { |
@@ -119,27 +130,31 @@ discard block |
||
119 | 130 | switch (strtolower($key)) { |
120 | 131 | case 'and': |
121 | 132 | foreach ($teams as $tkey => $team) { |
122 | - if (!$this->filterAnd($team, $filter)) unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
133 | + if (!$this->filterAnd($team, $filter)) { |
|
134 | + unset($teams[$tkey]); |
|
135 | + } |
|
136 | + // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
123 | 137 | } |
124 | 138 | break; |
125 | 139 | case 'or': |
126 | 140 | foreach ($teams as $tkey => $team) { |
127 | - if (!$this->filterOr($team, $filter)) unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
141 | + if (!$this->filterOr($team, $filter)) { |
|
142 | + unset($teams[$tkey]); |
|
143 | + } |
|
144 | + // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
128 | 145 | } |
129 | 146 | break; |
130 | 147 | default: |
131 | 148 | throw new \Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".'); |
132 | 149 | break; |
133 | 150 | } |
134 | - } |
|
135 | - elseif ($filter instanceof TeamFilter) { |
|
151 | + } elseif ($filter instanceof TeamFilter) { |
|
136 | 152 | foreach ($teams as $tkey => $team) { |
137 | 153 | if (!$filter->validate($team, $this->id, 'sum', $this)) { |
138 | 154 | unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
139 | 155 | } |
140 | 156 | } |
141 | - } |
|
142 | - else { |
|
157 | + } else { |
|
143 | 158 | throw new \Exception('Filer ['.$key.'] is not an instance of TeamFilter class'); |
144 | 159 | } |
145 | 160 | } |
@@ -161,18 +176,26 @@ discard block |
||
161 | 176 | return $t; |
162 | 177 | } |
163 | 178 | public function sortTeams($filters = [], $ordering = null) { |
164 | - if (!isset($ordering)) $ordering = $this->ordering; |
|
179 | + if (!isset($ordering)) { |
|
180 | + $ordering = $this->ordering; |
|
181 | + } |
|
165 | 182 | switch ($ordering) { |
166 | 183 | case POINTS:{ |
167 | 184 | usort($this->teams, function($a, $b) { |
168 | - if ($a->groupResults[$this->id]["points"] === $b->groupResults[$this->id]["points"] && $a->groupResults[$this->id]["score"] === $b->groupResults[$this->id]["score"]) return 0; |
|
169 | - if ($a->groupResults[$this->id]["points"] === $b->groupResults[$this->id]["points"]) return ($a->groupResults[$this->id]["score"] > $b->groupResults[$this->id]["score"] ? -1 : 1); |
|
185 | + if ($a->groupResults[$this->id]["points"] === $b->groupResults[$this->id]["points"] && $a->groupResults[$this->id]["score"] === $b->groupResults[$this->id]["score"]) { |
|
186 | + return 0; |
|
187 | + } |
|
188 | + if ($a->groupResults[$this->id]["points"] === $b->groupResults[$this->id]["points"]) { |
|
189 | + return ($a->groupResults[$this->id]["score"] > $b->groupResults[$this->id]["score"] ? -1 : 1); |
|
190 | + } |
|
170 | 191 | return ($a->groupResults[$this->id]["points"] > $b->groupResults[$this->id]["points"] ? -1 : 1); |
171 | 192 | }); |
172 | 193 | break;} |
173 | 194 | case SCORE:{ |
174 | 195 | usort($this->teams, function($a, $b) { |
175 | - if ($a->groupResults[$this->id]["score"] === $b->groupResults[$this->id]["score"]) return 0; |
|
196 | + if ($a->groupResults[$this->id]["score"] === $b->groupResults[$this->id]["score"]) { |
|
197 | + return 0; |
|
198 | + } |
|
176 | 199 | return ($a->groupResults[$this->id]["score"] > $b->groupResults[$this->id]["score"] ? -1 : 1); |
177 | 200 | }); |
178 | 201 | break;} |
@@ -185,20 +208,24 @@ discard block |
||
185 | 208 | if (gettype($value) === 'array') { |
186 | 209 | switch (strtolower($key)) { |
187 | 210 | case 'and': |
188 | - if ($this->filterAnd($team, $value)) return false; |
|
211 | + if ($this->filterAnd($team, $value)) { |
|
212 | + return false; |
|
213 | + } |
|
189 | 214 | break; |
190 | 215 | case 'or': |
191 | - if ($this->filterOr($team, $value)) return false; |
|
216 | + if ($this->filterOr($team, $value)) { |
|
217 | + return false; |
|
218 | + } |
|
192 | 219 | break; |
193 | 220 | default: |
194 | 221 | throw new \Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".'); |
195 | 222 | break; |
196 | 223 | } |
197 | - } |
|
198 | - elseif ($value instanceof TeamFilter) { |
|
199 | - if (!$value->validate($team, $this->id, 'sum', $this)) return false; |
|
200 | - } |
|
201 | - else { |
|
224 | + } elseif ($value instanceof TeamFilter) { |
|
225 | + if (!$value->validate($team, $this->id, 'sum', $this)) { |
|
226 | + return false; |
|
227 | + } |
|
228 | + } else { |
|
202 | 229 | throw new \Exception('Filer ['.$key.'] is not an instance of TeamFilter class'); |
203 | 230 | } |
204 | 231 | } |
@@ -209,20 +236,24 @@ discard block |
||
209 | 236 | if (gettype($value) === 'array') { |
210 | 237 | switch (strtolower($key)) { |
211 | 238 | case 'and': |
212 | - if ($this->filterAnd($team, $value)) return true; |
|
239 | + if ($this->filterAnd($team, $value)) { |
|
240 | + return true; |
|
241 | + } |
|
213 | 242 | break; |
214 | 243 | case 'or': |
215 | - if ($this->filterOr($team, $value)) return true; |
|
244 | + if ($this->filterOr($team, $value)) { |
|
245 | + return true; |
|
246 | + } |
|
216 | 247 | break; |
217 | 248 | default: |
218 | 249 | throw new \Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".'); |
219 | 250 | break; |
220 | 251 | } |
221 | - } |
|
222 | - elseif ($value instanceof TeamFilter) { |
|
223 | - if (!$value->validate($team, $this->id, 'sum', $this)) return true; |
|
224 | - } |
|
225 | - else { |
|
252 | + } elseif ($value instanceof TeamFilter) { |
|
253 | + if (!$value->validate($team, $this->id, 'sum', $this)) { |
|
254 | + return true; |
|
255 | + } |
|
256 | + } else { |
|
226 | 257 | throw new \Exception('Filer ['.$key.'] is not an instance of TeamFilter class'); |
227 | 258 | } |
228 | 259 | } |
@@ -238,8 +269,11 @@ discard block |
||
238 | 269 | } |
239 | 270 | |
240 | 271 | public function setOrdering(string $ordering = POINTS) { |
241 | - if (in_array($ordering, orderingTypes)) $this->ordering = $ordering; |
|
242 | - else throw new \Exception('Unknown group ordering: '.$ordering); |
|
272 | + if (in_array($ordering, orderingTypes)) { |
|
273 | + $this->ordering = $ordering; |
|
274 | + } else { |
|
275 | + throw new \Exception('Unknown group ordering: '.$ordering); |
|
276 | + } |
|
243 | 277 | return $this; |
244 | 278 | } |
245 | 279 | public function getOrdering() { |
@@ -272,16 +306,13 @@ discard block |
||
272 | 306 | foreach ($teams as $team) { |
273 | 307 | if ($team instanceOf Team) { |
274 | 308 | $this->progressed[] = $team->id; |
275 | - } |
|
276 | - elseif (gettype($team) === 'string' || gettype($team) === 'integer') { |
|
309 | + } elseif (gettype($team) === 'string' || gettype($team) === 'integer') { |
|
277 | 310 | $this->progressed[] = $team; |
278 | - } |
|
279 | - elseif (gettype($team) === 'array') { |
|
311 | + } elseif (gettype($team) === 'array') { |
|
280 | 312 | foreach ($team as $teamInner) { |
281 | 313 | if ($teamInner instanceOf Team) { |
282 | 314 | $this->progressed[] = $teamInner->id; |
283 | - } |
|
284 | - elseif (gettype($teamInner) === 'string' || gettype($teamInner) === 'integer') { |
|
315 | + } elseif (gettype($teamInner) === 'string' || gettype($teamInner) === 'integer') { |
|
285 | 316 | $this->progressed[] = $teamInner; |
286 | 317 | } |
287 | 318 | } |
@@ -314,8 +345,11 @@ discard block |
||
314 | 345 | } |
315 | 346 | } |
316 | 347 | foreach ($games as $game) { |
317 | - if ($game instanceof Game) $this->games[] = $game; |
|
318 | - else throw new \Exception('Trying to add game which is not instance of Game object.'); |
|
348 | + if ($game instanceof Game) { |
|
349 | + $this->games[] = $game; |
|
350 | + } else { |
|
351 | + throw new \Exception('Trying to add game which is not instance of Game object.'); |
|
352 | + } |
|
319 | 353 | } |
320 | 354 | return $this; |
321 | 355 | } |
@@ -323,7 +357,9 @@ discard block |
||
323 | 357 | return $this->games; |
324 | 358 | } |
325 | 359 | public function orderGames() { |
326 | - if (count($this->games) <= 4) return $this->games; |
|
360 | + if (count($this->games) <= 4) { |
|
361 | + return $this->games; |
|
362 | + } |
|
327 | 363 | $this->games = $this->generator->orderGames(); |
328 | 364 | return $this->games; |
329 | 365 | } |
@@ -338,7 +374,9 @@ discard block |
||
338 | 374 | $game->setResults($results); |
339 | 375 | } |
340 | 376 | $return = $this->sortTeams($filters); |
341 | - if (!$reset) return $return; |
|
377 | + if (!$reset) { |
|
378 | + return $return; |
|
379 | + } |
|
342 | 380 | foreach ($this->getGames() as $game) { |
343 | 381 | $game->resetResults(); |
344 | 382 | } |
@@ -346,13 +384,17 @@ discard block |
||
346 | 384 | } |
347 | 385 | public function resetGames() { |
348 | 386 | foreach ($this->getGames() as $game) { |
349 | - if (isset($game)) $game->resetResults(); |
|
387 | + if (isset($game)) { |
|
388 | + $game->resetResults(); |
|
389 | + } |
|
350 | 390 | } |
351 | 391 | return $this; |
352 | 392 | } |
353 | 393 | public function isPlayed(){ |
354 | 394 | foreach ($this->games as $game) { |
355 | - if ((isset($game) || !$this->getSkip()) && !$game->isPlayed()) return false; |
|
395 | + if ((isset($game) || !$this->getSkip()) && !$game->isPlayed()) { |
|
396 | + return false; |
|
397 | + } |
|
356 | 398 | } |
357 | 399 | return true; |
358 | 400 | } |
@@ -27,18 +27,26 @@ discard block |
||
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 |
||
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 |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | return $this->name; |
24 | 24 | } |
25 | 25 | |
26 | - public function addGroup(Group ...$groups){ |
|
26 | + public function addGroup(Group ...$groups) { |
|
27 | 27 | foreach ($groups as $group) { |
28 | 28 | if ($group instanceof Group) $this->groups[] = $group; |
29 | 29 | else throw new \Exception('Trying to add group which is not an instance of Group class.'); |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | $this->groups[] = $g->setSkip($this->allowSkip); |
36 | 36 | return $g; |
37 | 37 | } |
38 | - public function getGroups(){ |
|
38 | + public function getGroups() { |
|
39 | 39 | $this->orderGroups(); |
40 | 40 | return $this->groups; |
41 | 41 | } |
@@ -44,16 +44,16 @@ discard block |
||
44 | 44 | return array_map(function($a) { return $a->id; }, $this->groups); |
45 | 45 | } |
46 | 46 | public function orderGroups() { |
47 | - usort($this->groups, function($a, $b){ |
|
48 | - return $a->order - $b->order; |
|
47 | + usort($this->groups, function($a, $b) { |
|
48 | + return $a->order-$b->order; |
|
49 | 49 | }); |
50 | 50 | } |
51 | 51 | |
52 | - public function allowSkip(){ |
|
52 | + public function allowSkip() { |
|
53 | 53 | $this->allowSkip = true; |
54 | 54 | return $this; |
55 | 55 | } |
56 | - public function disallowSkip(){ |
|
56 | + public function disallowSkip() { |
|
57 | 57 | $this->allowSkip = false; |
58 | 58 | return $this; |
59 | 59 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | return $this->allowSkip; |
66 | 66 | } |
67 | 67 | |
68 | - public function genGames(){ |
|
68 | + public function genGames() { |
|
69 | 69 | $g = 0; |
70 | 70 | foreach ($this->groups as $group) { |
71 | 71 | $group->genGames(); |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | public function getGames() { |
77 | 77 | return $this->games; |
78 | 78 | } |
79 | - public function isPlayed(){ |
|
79 | + public function isPlayed() { |
|
80 | 80 | foreach ($this->groups as $group) { |
81 | 81 | if (!$group->isPlayed()) return false; |
82 | 82 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | |
86 | 86 | public function addTeam(...$teams) { |
87 | 87 | foreach ($teams as $team) { |
88 | - if ($team instanceof Team) { |
|
88 | + if ($team instanceof Team) { |
|
89 | 89 | $this->teams[] = $team; |
90 | 90 | } |
91 | 91 | elseif (gettype($team) === 'array') { |
@@ -135,13 +135,13 @@ discard block |
||
135 | 135 | if ($a->sumPoints($groupsIds) === $b->sumPoints($groupsIds)) return ($a->sumScore($groupsIds) > $b->sumScore($groupsIds) ? -1 : 1); |
136 | 136 | return ($a->sumPoints($groupsIds) > $b->sumPoints($groupsIds) ? -1 : 1); |
137 | 137 | }); |
138 | - break;} |
|
138 | + break; } |
|
139 | 139 | case SCORE:{ |
140 | 140 | uasort($this->teams, function($a, $b) use ($groupsIds) { |
141 | 141 | if ($a->sumScore($groupsIds) === $b->sumScore($groupsIds)) return 0; |
142 | 142 | return ($a->sumScore($groupsIds) > $b->sumScore($groupsIds) ? -1 : 1); |
143 | 143 | }); |
144 | - break;} |
|
144 | + break; } |
|
145 | 145 | } |
146 | 146 | return $this->teams; |
147 | 147 | } |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | return $this; |
171 | 171 | } |
172 | 172 | |
173 | - public function progress(bool $blank = false){ |
|
173 | + public function progress(bool $blank = false) { |
|
174 | 174 | foreach ($this->groups as $group) { |
175 | 175 | $group->progress($blank); |
176 | 176 | } |
@@ -25,8 +25,11 @@ discard block |
||
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 | } |
@@ -78,7 +81,9 @@ discard block |
||
78 | 81 | } |
79 | 82 | public function isPlayed(){ |
80 | 83 | foreach ($this->groups as $group) { |
81 | - if (!$group->isPlayed()) return false; |
|
84 | + if (!$group->isPlayed()) { |
|
85 | + return false; |
|
86 | + } |
|
82 | 87 | } |
83 | 88 | return true; |
84 | 89 | } |
@@ -87,10 +92,11 @@ discard block |
||
87 | 92 | foreach ($teams as $team) { |
88 | 93 | if ($team instanceof Team) { |
89 | 94 | $this->teams[] = $team; |
90 | - } |
|
91 | - elseif (gettype($team) === 'array') { |
|
95 | + } elseif (gettype($team) === 'array') { |
|
92 | 96 | foreach ($team as $team2) { |
93 | - if ($team2 instanceof Team) $this->teams[] = $team2; |
|
97 | + if ($team2 instanceof Team) { |
|
98 | + $this->teams[] = $team2; |
|
99 | + } |
|
94 | 100 | $team2->groupResults[$this->id] = [ |
95 | 101 | 'group' => $this, |
96 | 102 | 'points' => 0, |
@@ -102,8 +108,9 @@ discard block |
||
102 | 108 | 'third' => 0 |
103 | 109 | ]; |
104 | 110 | } |
111 | + } else { |
|
112 | + throw new \Exception('Trying to add team which is not an instance of Team class'); |
|
105 | 113 | } |
106 | - else throw new \Exception('Trying to add team which is not an instance of Team class'); |
|
107 | 114 | } |
108 | 115 | return $this; |
109 | 116 | } |
@@ -131,14 +138,20 @@ discard block |
||
131 | 138 | switch ($ordering) { |
132 | 139 | case POINTS:{ |
133 | 140 | uasort($this->teams, function($a, $b) use ($groupsIds) { |
134 | - if ($a->sumPoints($groupsIds) === $b->sumPoints($groupsIds) && $a->sumScore($groupsIds) === $b->sumScore($groupsIds)) return 0; |
|
135 | - if ($a->sumPoints($groupsIds) === $b->sumPoints($groupsIds)) return ($a->sumScore($groupsIds) > $b->sumScore($groupsIds) ? -1 : 1); |
|
141 | + if ($a->sumPoints($groupsIds) === $b->sumPoints($groupsIds) && $a->sumScore($groupsIds) === $b->sumScore($groupsIds)) { |
|
142 | + return 0; |
|
143 | + } |
|
144 | + if ($a->sumPoints($groupsIds) === $b->sumPoints($groupsIds)) { |
|
145 | + return ($a->sumScore($groupsIds) > $b->sumScore($groupsIds) ? -1 : 1); |
|
146 | + } |
|
136 | 147 | return ($a->sumPoints($groupsIds) > $b->sumPoints($groupsIds) ? -1 : 1); |
137 | 148 | }); |
138 | 149 | break;} |
139 | 150 | case SCORE:{ |
140 | 151 | uasort($this->teams, function($a, $b) use ($groupsIds) { |
141 | - if ($a->sumScore($groupsIds) === $b->sumScore($groupsIds)) return 0; |
|
152 | + if ($a->sumScore($groupsIds) === $b->sumScore($groupsIds)) { |
|
153 | + return 0; |
|
154 | + } |
|
142 | 155 | return ($a->sumScore($groupsIds) > $b->sumScore($groupsIds) ? -1 : 1); |
143 | 156 | }); |
144 | 157 | break;} |
@@ -148,7 +161,9 @@ discard block |
||
148 | 161 | |
149 | 162 | public function splitTeams(...$groups) { |
150 | 163 | |
151 | - if (count($groups) === 0) $groups = $this->getGroups(); |
|
164 | + if (count($groups) === 0) { |
|
165 | + $groups = $this->getGroups(); |
|
166 | + } |
|
152 | 167 | |
153 | 168 | foreach ($groups as $key => $value) { |
154 | 169 | if (gettype($value) === 'array') { |
@@ -163,7 +178,9 @@ discard block |
||
163 | 178 | while (count($teams) > 0) { |
164 | 179 | foreach ($groups as $group) { |
165 | 180 | if ($group instanceof Group) { |
166 | - if (count($teams) > 0) $group->addTeam(array_shift($teams)); |
|
181 | + if (count($teams) > 0) { |
|
182 | + $group->addTeam(array_shift($teams)); |
|
183 | + } |
|
167 | 184 | } |
168 | 185 | } |
169 | 186 | } |
@@ -179,7 +196,9 @@ discard block |
||
179 | 196 | |
180 | 197 | public function simulate() { |
181 | 198 | foreach ($this->groups as $group) { |
182 | - if ($group->isPlayed()) continue; |
|
199 | + if ($group->isPlayed()) { |
|
200 | + continue; |
|
201 | + } |
|
183 | 202 | $group->simulate([], false); |
184 | 203 | } |
185 | 204 | return $this; |
@@ -59,70 +59,70 @@ |
||
59 | 59 | return $this; |
60 | 60 | } |
61 | 61 | |
62 | - public function addWin(string $groupId = ''){ |
|
62 | + public function addWin(string $groupId = '') { |
|
63 | 63 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
64 | 64 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->winPoints; |
65 | 65 | $this->sumPoints += $this->groupResults[$groupId]['group']->winPoints; |
66 | 66 | $this->groupResults[$groupId]['wins']++; |
67 | 67 | return $this; |
68 | 68 | } |
69 | - public function removeWin(string $groupId = ''){ |
|
69 | + public function removeWin(string $groupId = '') { |
|
70 | 70 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
71 | 71 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->winPoints; |
72 | 72 | $this->sumPoints -= $this->groupResults[$groupId]['group']->winPoints; |
73 | 73 | $this->groupResults[$groupId]['wins']--; |
74 | 74 | return $this; |
75 | 75 | } |
76 | - public function addDraw(string $groupId = ''){ |
|
76 | + public function addDraw(string $groupId = '') { |
|
77 | 77 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
78 | 78 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->drawPoints; |
79 | 79 | $this->sumPoints += $this->groupResults[$groupId]['group']->drawPoints; |
80 | 80 | $this->groupResults[$groupId]['draws']++; |
81 | 81 | return $this; |
82 | 82 | } |
83 | - public function removeDraw(string $groupId = ''){ |
|
83 | + public function removeDraw(string $groupId = '') { |
|
84 | 84 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
85 | 85 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->drawPointsPoints; |
86 | 86 | $this->sumPoints -= $this->groupResults[$groupId]['group']->drawPoints; |
87 | 87 | $this->groupResults[$groupId]['draws']--; |
88 | 88 | return $this; |
89 | 89 | } |
90 | - public function addLoss(string $groupId = ''){ |
|
90 | + public function addLoss(string $groupId = '') { |
|
91 | 91 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
92 | 92 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->lostPoints; |
93 | 93 | $this->sumPoints += $this->groupResults[$groupId]['group']->lostPoints; |
94 | 94 | $this->groupResults[$groupId]['losses']++; |
95 | 95 | return $this; |
96 | 96 | } |
97 | - public function removeLoss(string $groupId = ''){ |
|
97 | + public function removeLoss(string $groupId = '') { |
|
98 | 98 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
99 | 99 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->lostPoints; |
100 | 100 | $this->sumPoints -= $this->groupResults[$groupId]['group']->lostPoints; |
101 | 101 | $this->groupResults[$groupId]['losses']--; |
102 | 102 | return $this; |
103 | 103 | } |
104 | - public function addSecond(string $groupId = ''){ |
|
104 | + public function addSecond(string $groupId = '') { |
|
105 | 105 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
106 | 106 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->secondPoints; |
107 | 107 | $this->sumPoints += $this->groupResults[$groupId]['group']->secondPoints; |
108 | 108 | $this->groupResults[$groupId]['second']++; |
109 | 109 | return $this; |
110 | 110 | } |
111 | - public function removeSecond(string $groupId = ''){ |
|
111 | + public function removeSecond(string $groupId = '') { |
|
112 | 112 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
113 | 113 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->secondPoints; |
114 | 114 | $this->sumPoints -= $this->groupResults[$groupId]['group']->secondPoints; |
115 | 115 | $this->groupResults[$groupId]['second']--; |
116 | 116 | return $this; |
117 | 117 | } |
118 | - public function addThird(string $groupId = ''){ |
|
118 | + public function addThird(string $groupId = '') { |
|
119 | 119 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
120 | 120 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->thirdPoints; |
121 | 121 | $this->sumPoints += $this->groupResults[$groupId]['group']->thirdPoints; |
122 | 122 | $this->groupResults[$groupId]['third']++; |
123 | 123 | return $this; |
124 | 124 | } |
125 | - public function removeThird(string $groupId = ''){ |
|
125 | + public function removeThird(string $groupId = '') { |
|
126 | 126 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
127 | 127 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->thirdPoints; |
128 | 128 | $this->sumPoints -= $this->groupResults[$groupId]['group']->thirdPoints; |
@@ -44,104 +44,138 @@ |
||
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 | } |