@@ -68,11 +68,11 @@ discard block |
||
68 | 68 | return 'Group '.$this->name; |
69 | 69 | } |
70 | 70 | |
71 | - public function allowSkip(){ |
|
71 | + public function allowSkip() { |
|
72 | 72 | $this->allowSkip = true; |
73 | 73 | return $this; |
74 | 74 | } |
75 | - public function disallowSkip(){ |
|
75 | + public function disallowSkip() { |
|
76 | 76 | $this->allowSkip = false; |
77 | 77 | return $this; |
78 | 78 | } |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | |
87 | 87 | public function addTeam(...$teams) { |
88 | 88 | foreach ($teams as $team) { |
89 | - if ($team instanceof Team) { |
|
89 | + if ($team instanceof Team) { |
|
90 | 90 | $this->teams[] = $team; |
91 | 91 | $team->groupResults[$this->id] = [ |
92 | 92 | 'group' => $this, |
@@ -243,13 +243,13 @@ discard block |
||
243 | 243 | if ($a->groupResults[$this->id]["points"] === $b->groupResults[$this->id]["points"]) return ($a->groupResults[$this->id]["score"] > $b->groupResults[$this->id]["score"] ? -1 : 1); |
244 | 244 | return ($a->groupResults[$this->id]["points"] > $b->groupResults[$this->id]["points"] ? -1 : 1); |
245 | 245 | }); |
246 | - break;} |
|
246 | + break; } |
|
247 | 247 | case SCORE:{ |
248 | 248 | usort($this->teams, function($a, $b) { |
249 | 249 | if ($a->groupResults[$this->id]["score"] === $b->groupResults[$this->id]["score"]) return 0; |
250 | 250 | return ($a->groupResults[$this->id]["score"] > $b->groupResults[$this->id]["score"] ? -1 : 1); |
251 | 251 | }); |
252 | - break;} |
|
252 | + break; } |
|
253 | 253 | } |
254 | 254 | return $this->getTeams($filters); |
255 | 255 | } |
@@ -314,19 +314,19 @@ discard block |
||
314 | 314 | switch ($this->type) { |
315 | 315 | case R_R:{ |
316 | 316 | $this->games = $this->r_rGames(); |
317 | - break;} |
|
317 | + break; } |
|
318 | 318 | case TWO_TWO: |
319 | 319 | $teams = $this->teams; |
320 | 320 | $discard = []; |
321 | 321 | shuffle($teams); |
322 | 322 | $count = count($teams); |
323 | - while (count($teams) % $this->inGame !== 0) { |
|
323 | + while (count($teams)%$this->inGame !== 0) { |
|
324 | 324 | $discard[] = array_shift($teams); |
325 | 325 | } |
326 | 326 | |
327 | 327 | while (count($teams) > 0) { |
328 | 328 | $tInGame = []; |
329 | - for ($i=0; $i < $this->inGame; $i++) { |
|
329 | + for ($i = 0; $i < $this->inGame; $i++) { |
|
330 | 330 | $tInGame[] = array_shift($teams); |
331 | 331 | } |
332 | 332 | $this->game($tInGame); |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | $this->games[] = $g; |
366 | 366 | return $g; |
367 | 367 | } |
368 | - public function addGame(Game ...$games){ |
|
368 | + public function addGame(Game ...$games) { |
|
369 | 369 | foreach ($games as $game) { |
370 | 370 | if ($game instanceof Game) $this->games[] = $game; |
371 | 371 | else throw new \Exception('Trying to add game which is not instance of Game object.'); |
@@ -461,7 +461,7 @@ discard block |
||
461 | 461 | foreach ($games as $key => $game) { |
462 | 462 | $gTeams = $game->getTeamsIds(); |
463 | 463 | $suitable = true; |
464 | - $requiredTeams = array_filter($teams, function($a){ |
|
464 | + $requiredTeams = array_filter($teams, function($a) { |
|
465 | 465 | return $a < 4; |
466 | 466 | }); |
467 | 467 | foreach ($gTeams as $tid) { |
@@ -512,7 +512,7 @@ discard block |
||
512 | 512 | foreach ($games as $key => $game) { |
513 | 513 | $gTeams = $game->getTeamsIds(); |
514 | 514 | $suitable = false; |
515 | - $requiredTeams = array_filter($teams, function($a){ |
|
515 | + $requiredTeams = array_filter($teams, function($a) { |
|
516 | 516 | return $a < 4; |
517 | 517 | }); |
518 | 518 | foreach ($gTeams as $tid) { |
@@ -557,7 +557,7 @@ discard block |
||
557 | 557 | $games = array_merge($games, $games); |
558 | 558 | } |
559 | 559 | // $this->orderGames(); |
560 | - break;} |
|
560 | + break; } |
|
561 | 561 | case 4:{ |
562 | 562 | $teamsB = $teams; |
563 | 563 | $lockedTeam1 = array_shift($teamsB); |
@@ -575,7 +575,7 @@ discard block |
||
575 | 575 | } |
576 | 576 | $games[] = new Game(array_merge([$lockedTeam1], $teamsB), $this); |
577 | 577 | // $this->orderGames(); |
578 | - break;} |
|
578 | + break; } |
|
579 | 579 | } |
580 | 580 | return $games; |
581 | 581 | } |
@@ -601,7 +601,7 @@ discard block |
||
601 | 601 | } |
602 | 602 | return $this; |
603 | 603 | } |
604 | - public function isPlayed(){ |
|
604 | + public function isPlayed() { |
|
605 | 605 | foreach ($this->games as $game) { |
606 | 606 | if ((isset($game) || !$this->getSkip()) && !$game->isPlayed()) return false; |
607 | 607 | } |
@@ -33,23 +33,36 @@ discard block |
||
33 | 33 | foreach ($settings as $key => $value) { |
34 | 34 | switch ($key) { |
35 | 35 | case 'name': |
36 | - if (gettype($value) === 'string') $this->name = $value; |
|
37 | - else throw new \Exception('Expected string as group name '.gettype($value).' given'); |
|
36 | + if (gettype($value) === 'string') { |
|
37 | + $this->name = $value; |
|
38 | + } else { |
|
39 | + throw new \Exception('Expected string as group name '.gettype($value).' given'); |
|
40 | + } |
|
38 | 41 | break; |
39 | 42 | case 'type': |
40 | - if (in_array($value, groupTypes)) $this->type = $value; |
|
41 | - else throw new \Exception('Unknown group type: '.$value); |
|
43 | + if (in_array($value, groupTypes)) { |
|
44 | + $this->type = $value; |
|
45 | + } else { |
|
46 | + throw new \Exception('Unknown group type: '.$value); |
|
47 | + } |
|
42 | 48 | break; |
43 | 49 | case 'ordering': |
44 | - if (in_array($value, orderingTypes)) $this->ordering = $value; |
|
45 | - else throw new \Exception('Unknown group ordering: '.$value); |
|
50 | + if (in_array($value, orderingTypes)) { |
|
51 | + $this->ordering = $value; |
|
52 | + } else { |
|
53 | + throw new \Exception('Unknown group ordering: '.$value); |
|
54 | + } |
|
46 | 55 | break; |
47 | 56 | case 'inGame': |
48 | 57 | if (gettype($value) === 'integer') { |
49 | - if ($value === 2 || $value === 3 || $value === 4) $this->inGame = $value; |
|
50 | - else throw new \Exception('Expected 2,3 or 4 as inGame '.$value.' given'); |
|
58 | + if ($value === 2 || $value === 3 || $value === 4) { |
|
59 | + $this->inGame = $value; |
|
60 | + } else { |
|
61 | + throw new \Exception('Expected 2,3 or 4 as inGame '.$value.' given'); |
|
62 | + } |
|
63 | + } else { |
|
64 | + throw new \Exception('Expected integer as inGame '.gettype($value).' given'); |
|
51 | 65 | } |
52 | - else throw new \Exception('Expected integer as inGame '.gettype($value).' given'); |
|
53 | 66 | break; |
54 | 67 | case 'maxSize': |
55 | 68 | if (gettype($value) === 'integer') { |
@@ -98,10 +111,11 @@ discard block |
||
98 | 111 | 'second' => 0, |
99 | 112 | 'third' => 0 |
100 | 113 | ]; |
101 | - } |
|
102 | - elseif (gettype($team) === 'array') { |
|
114 | + } elseif (gettype($team) === 'array') { |
|
103 | 115 | foreach ($team as $team2) { |
104 | - if ($team2 instanceof Team) $this->teams[] = $team2; |
|
116 | + if ($team2 instanceof Team) { |
|
117 | + $this->teams[] = $team2; |
|
118 | + } |
|
105 | 119 | $team2->groupResults[$this->id] = [ |
106 | 120 | 'group' => $this, |
107 | 121 | 'points' => 0, |
@@ -113,16 +127,20 @@ discard block |
||
113 | 127 | 'third' => 0 |
114 | 128 | ]; |
115 | 129 | } |
130 | + } else { |
|
131 | + throw new \Exception('Trying to add team which is not an instance of Team class'); |
|
116 | 132 | } |
117 | - else throw new \Exception('Trying to add team which is not an instance of Team class'); |
|
118 | 133 | } |
119 | 134 | return $this; |
120 | 135 | } |
121 | 136 | public function getTeams($filters = []) { |
122 | 137 | $teams = $this->teams; |
123 | 138 | |
124 | - if (gettype($filters) !== 'array' && $filters instanceof TeamFilter) $filters = [$filters]; |
|
125 | - elseif (gettype($filters) !== 'array') $filters = []; |
|
139 | + if (gettype($filters) !== 'array' && $filters instanceof TeamFilter) { |
|
140 | + $filters = [$filters]; |
|
141 | + } elseif (gettype($filters) !== 'array') { |
|
142 | + $filters = []; |
|
143 | + } |
|
126 | 144 | |
127 | 145 | // APPLY FILTERS |
128 | 146 | foreach ($filters as $key => $filter) { |
@@ -130,27 +148,31 @@ discard block |
||
130 | 148 | switch (strtolower($key)) { |
131 | 149 | case 'and': |
132 | 150 | foreach ($teams as $tkey => $team) { |
133 | - if (!$this->filterAnd($team, $filter)) unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
151 | + if (!$this->filterAnd($team, $filter)) { |
|
152 | + unset($teams[$tkey]); |
|
153 | + } |
|
154 | + // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
134 | 155 | } |
135 | 156 | break; |
136 | 157 | case 'or': |
137 | 158 | foreach ($teams as $tkey => $team) { |
138 | - if (!$this->filterOr($team, $filter)) unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
159 | + if (!$this->filterOr($team, $filter)) { |
|
160 | + unset($teams[$tkey]); |
|
161 | + } |
|
162 | + // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
139 | 163 | } |
140 | 164 | break; |
141 | 165 | default: |
142 | 166 | throw new \Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".'); |
143 | 167 | break; |
144 | 168 | } |
145 | - } |
|
146 | - elseif ($filter instanceof TeamFilter) { |
|
169 | + } elseif ($filter instanceof TeamFilter) { |
|
147 | 170 | foreach ($teams as $tkey => $team) { |
148 | 171 | if (!$filter->validate($team, $this->id, 'sum', $this)) { |
149 | 172 | unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
150 | 173 | } |
151 | 174 | } |
152 | - } |
|
153 | - else { |
|
175 | + } else { |
|
154 | 176 | throw new \Exception('Filer ['.$key.'] is not an instance of TeamFilter class'); |
155 | 177 | } |
156 | 178 | } |
@@ -161,20 +183,24 @@ discard block |
||
161 | 183 | if (gettype($value) === 'array') { |
162 | 184 | switch (strtolower($key)) { |
163 | 185 | case 'and': |
164 | - if ($this->filterAnd($team, $value)) return false; |
|
186 | + if ($this->filterAnd($team, $value)) { |
|
187 | + return false; |
|
188 | + } |
|
165 | 189 | break; |
166 | 190 | case 'or': |
167 | - if ($this->filterOr($team, $value)) return false; |
|
191 | + if ($this->filterOr($team, $value)) { |
|
192 | + return false; |
|
193 | + } |
|
168 | 194 | break; |
169 | 195 | default: |
170 | 196 | throw new \Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".'); |
171 | 197 | break; |
172 | 198 | } |
173 | - } |
|
174 | - elseif ($value instanceof TeamFilter) { |
|
175 | - if (!$value->validate($team, $this->id, 'sum', $this)) return false; |
|
176 | - } |
|
177 | - else { |
|
199 | + } elseif ($value instanceof TeamFilter) { |
|
200 | + if (!$value->validate($team, $this->id, 'sum', $this)) { |
|
201 | + return false; |
|
202 | + } |
|
203 | + } else { |
|
178 | 204 | throw new \Exception('Filer ['.$key.'] is not an instance of TeamFilter class'); |
179 | 205 | } |
180 | 206 | } |
@@ -185,20 +211,24 @@ discard block |
||
185 | 211 | if (gettype($value) === 'array') { |
186 | 212 | switch (strtolower($key)) { |
187 | 213 | case 'and': |
188 | - if ($this->filterAnd($team, $value)) return true; |
|
214 | + if ($this->filterAnd($team, $value)) { |
|
215 | + return true; |
|
216 | + } |
|
189 | 217 | break; |
190 | 218 | case 'or': |
191 | - if ($this->filterOr($team, $value)) return true; |
|
219 | + if ($this->filterOr($team, $value)) { |
|
220 | + return true; |
|
221 | + } |
|
192 | 222 | break; |
193 | 223 | default: |
194 | 224 | throw new \Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".'); |
195 | 225 | break; |
196 | 226 | } |
197 | - } |
|
198 | - elseif ($value instanceof TeamFilter) { |
|
199 | - if (!$value->validate($team, $this->id, 'sum', $this)) return true; |
|
200 | - } |
|
201 | - else { |
|
227 | + } elseif ($value instanceof TeamFilter) { |
|
228 | + if (!$value->validate($team, $this->id, 'sum', $this)) { |
|
229 | + return true; |
|
230 | + } |
|
231 | + } else { |
|
202 | 232 | throw new \Exception('Filer ['.$key.'] is not an instance of TeamFilter class'); |
203 | 233 | } |
204 | 234 | } |
@@ -220,16 +250,22 @@ discard block |
||
220 | 250 | return $t; |
221 | 251 | } |
222 | 252 | public function setType(string $type = R_R) { |
223 | - if (in_array($type, groupTypes)) $this->type = $type; |
|
224 | - else throw new \Exception('Unknown group type: '.$type); |
|
253 | + if (in_array($type, groupTypes)) { |
|
254 | + $this->type = $type; |
|
255 | + } else { |
|
256 | + throw new \Exception('Unknown group type: '.$type); |
|
257 | + } |
|
225 | 258 | return $this; |
226 | 259 | } |
227 | 260 | public function getType() { |
228 | 261 | return $this->type; |
229 | 262 | } |
230 | 263 | public function setOrdering(string $ordering = POINTS) { |
231 | - if (in_array($ordering, orderingTypes)) $this->ordering = $ordering; |
|
232 | - else throw new \Exception('Unknown group ordering: '.$ordering); |
|
264 | + if (in_array($ordering, orderingTypes)) { |
|
265 | + $this->ordering = $ordering; |
|
266 | + } else { |
|
267 | + throw new \Exception('Unknown group ordering: '.$ordering); |
|
268 | + } |
|
233 | 269 | return $this; |
234 | 270 | } |
235 | 271 | public function getOrdering() { |
@@ -239,14 +275,20 @@ discard block |
||
239 | 275 | switch ($this->ordering) { |
240 | 276 | case POINTS:{ |
241 | 277 | usort($this->teams, function($a, $b) { |
242 | - if ($a->groupResults[$this->id]["points"] === $b->groupResults[$this->id]["points"] && $a->groupResults[$this->id]["score"] === $b->groupResults[$this->id]["score"]) return 0; |
|
243 | - if ($a->groupResults[$this->id]["points"] === $b->groupResults[$this->id]["points"]) return ($a->groupResults[$this->id]["score"] > $b->groupResults[$this->id]["score"] ? -1 : 1); |
|
278 | + if ($a->groupResults[$this->id]["points"] === $b->groupResults[$this->id]["points"] && $a->groupResults[$this->id]["score"] === $b->groupResults[$this->id]["score"]) { |
|
279 | + return 0; |
|
280 | + } |
|
281 | + if ($a->groupResults[$this->id]["points"] === $b->groupResults[$this->id]["points"]) { |
|
282 | + return ($a->groupResults[$this->id]["score"] > $b->groupResults[$this->id]["score"] ? -1 : 1); |
|
283 | + } |
|
244 | 284 | return ($a->groupResults[$this->id]["points"] > $b->groupResults[$this->id]["points"] ? -1 : 1); |
245 | 285 | }); |
246 | 286 | break;} |
247 | 287 | case SCORE:{ |
248 | 288 | usort($this->teams, function($a, $b) { |
249 | - if ($a->groupResults[$this->id]["score"] === $b->groupResults[$this->id]["score"]) return 0; |
|
289 | + if ($a->groupResults[$this->id]["score"] === $b->groupResults[$this->id]["score"]) { |
|
290 | + return 0; |
|
291 | + } |
|
250 | 292 | return ($a->groupResults[$this->id]["score"] > $b->groupResults[$this->id]["score"] ? -1 : 1); |
251 | 293 | }); |
252 | 294 | break;} |
@@ -255,17 +297,24 @@ discard block |
||
255 | 297 | } |
256 | 298 | public function setInGame(int $inGame) { |
257 | 299 | if (gettype($inGame) === 'integer') { |
258 | - if ($inGame === 2 || $inGame === 3 || $inGame === 4) $this->inGame = $inGame; |
|
259 | - else throw new \Exception('Expected 2,3 or 4 as inGame '.$inGame.' given'); |
|
300 | + if ($inGame === 2 || $inGame === 3 || $inGame === 4) { |
|
301 | + $this->inGame = $inGame; |
|
302 | + } else { |
|
303 | + throw new \Exception('Expected 2,3 or 4 as inGame '.$inGame.' given'); |
|
304 | + } |
|
305 | + } else { |
|
306 | + throw new \Exception('Expected integer as inGame '.gettype($inGame).' given'); |
|
260 | 307 | } |
261 | - else throw new \Exception('Expected integer as inGame '.gettype($inGame).' given'); |
|
262 | 308 | } |
263 | 309 | public function getInGame() { |
264 | 310 | return $this->inGame; |
265 | 311 | } |
266 | 312 | public function addProgression(Progression $progression) { |
267 | - if ($progression instanceof Progression) $this->progressions[] = $progression; |
|
268 | - else throw new \Exception('Trying to add progression which is not an instance of Progression class'); |
|
313 | + if ($progression instanceof Progression) { |
|
314 | + $this->progressions[] = $progression; |
|
315 | + } else { |
|
316 | + throw new \Exception('Trying to add progression which is not an instance of Progression class'); |
|
317 | + } |
|
269 | 318 | return $this; |
270 | 319 | } |
271 | 320 | public function progression(Group $to, int $start = 0, int $len = null) { |
@@ -287,16 +336,13 @@ discard block |
||
287 | 336 | foreach ($teams as $team) { |
288 | 337 | if ($team instanceOf Team) { |
289 | 338 | $this->progressed[] = $team->id; |
290 | - } |
|
291 | - elseif (gettype($team) === 'string' || gettype($team) === 'integer') { |
|
339 | + } elseif (gettype($team) === 'string' || gettype($team) === 'integer') { |
|
292 | 340 | $this->progressed[] = $team; |
293 | - } |
|
294 | - elseif (gettype($team) === 'array') { |
|
341 | + } elseif (gettype($team) === 'array') { |
|
295 | 342 | foreach ($team as $teamInner) { |
296 | 343 | if ($teamInner instanceOf Team) { |
297 | 344 | $this->progressed[] = $teamInner->id; |
298 | - } |
|
299 | - elseif (gettype($teamInner) === 'string' || gettype($teamInner) === 'integer') { |
|
345 | + } elseif (gettype($teamInner) === 'string' || gettype($teamInner) === 'integer') { |
|
300 | 346 | $this->progressed[] = $teamInner; |
301 | 347 | } |
302 | 348 | } |
@@ -350,12 +396,15 @@ discard block |
||
350 | 396 | while ($g > 0) { |
351 | 397 | foreach ($games as $key => $group) { |
352 | 398 | $this->games[] = array_shift($games[$key]); |
353 | - if (count($games[$key]) === 0) unset($games[$key]); |
|
399 | + if (count($games[$key]) === 0) { |
|
400 | + unset($games[$key]); |
|
401 | + } |
|
354 | 402 | $g--; |
355 | 403 | } |
356 | 404 | } |
405 | + } else { |
|
406 | + $this->games = $this->r_rGames(); |
|
357 | 407 | } |
358 | - else $this->games = $this->r_rGames(); |
|
359 | 408 | break; |
360 | 409 | } |
361 | 410 | return $this->games; |
@@ -367,8 +416,11 @@ discard block |
||
367 | 416 | } |
368 | 417 | public function addGame(Game ...$games){ |
369 | 418 | foreach ($games as $game) { |
370 | - if ($game instanceof Game) $this->games[] = $game; |
|
371 | - else throw new \Exception('Trying to add game which is not instance of Game object.'); |
|
419 | + if ($game instanceof Game) { |
|
420 | + $this->games[] = $game; |
|
421 | + } else { |
|
422 | + throw new \Exception('Trying to add game which is not instance of Game object.'); |
|
423 | + } |
|
372 | 424 | } |
373 | 425 | return $this; |
374 | 426 | } |
@@ -396,21 +448,30 @@ discard block |
||
396 | 448 | $teams[$team->id] = 0; |
397 | 449 | } |
398 | 450 | foreach (end($this->games)->getTeams() as $team) { |
399 | - if (!isset($teams[$team->id])) $teams[$team->id] = 4; |
|
400 | - else $teams[$team->id] += 4; |
|
451 | + if (!isset($teams[$team->id])) { |
|
452 | + $teams[$team->id] = 4; |
|
453 | + } else { |
|
454 | + $teams[$team->id] += 4; |
|
455 | + } |
|
401 | 456 | } |
402 | 457 | $g = prev($this->games); |
403 | 458 | if ($g instanceof Game) { |
404 | 459 | foreach ($g->getTeams() as $team) { |
405 | - if (!isset($teams[$team->id])) $teams[$team->id] = 2; |
|
406 | - else $teams[$team->id] += 2; |
|
460 | + if (!isset($teams[$team->id])) { |
|
461 | + $teams[$team->id] = 2; |
|
462 | + } else { |
|
463 | + $teams[$team->id] += 2; |
|
464 | + } |
|
407 | 465 | } |
408 | 466 | } |
409 | 467 | $g = prev($this->games); |
410 | 468 | if ($g instanceof Game) { |
411 | 469 | foreach ($g->getTeams() as $team) { |
412 | - if (!isset($teams[$team->id])) $teams[$team->id] = 1; |
|
413 | - else $teams[$team->id]++; |
|
470 | + if (!isset($teams[$team->id])) { |
|
471 | + $teams[$team->id] = 1; |
|
472 | + } else { |
|
473 | + $teams[$team->id]++; |
|
474 | + } |
|
414 | 475 | } |
415 | 476 | } |
416 | 477 | |
@@ -432,7 +493,9 @@ discard block |
||
432 | 493 | break; |
433 | 494 | } |
434 | 495 | } |
435 | - if ($found) continue; |
|
496 | + if ($found) { |
|
497 | + continue; |
|
498 | + } |
|
436 | 499 | |
437 | 500 | // CYCLE 2 |
438 | 501 | // ! TEAM WHICH PLAYED IN LAST TWO GAMES (NOT 6 or 7) |
@@ -453,7 +516,9 @@ discard block |
||
453 | 516 | break; |
454 | 517 | } |
455 | 518 | } |
456 | - if ($found) continue; |
|
519 | + if ($found) { |
|
520 | + continue; |
|
521 | + } |
|
457 | 522 | |
458 | 523 | // CYCLE 3 |
459 | 524 | // ! TEAM WHICH PLAYED IN LAST THREE GAMES (NOT 7) |
@@ -484,7 +549,9 @@ discard block |
||
484 | 549 | break; |
485 | 550 | } |
486 | 551 | } |
487 | - if ($found) continue; |
|
552 | + if ($found) { |
|
553 | + continue; |
|
554 | + } |
|
488 | 555 | |
489 | 556 | // CYCLE 4 |
490 | 557 | // ! TEAM WHICH PLAYED IN LAST THREE GAMES (NOT 7) |
@@ -505,7 +572,9 @@ discard block |
||
505 | 572 | break; |
506 | 573 | } |
507 | 574 | } |
508 | - if ($found) continue; |
|
575 | + if ($found) { |
|
576 | + continue; |
|
577 | + } |
|
509 | 578 | |
510 | 579 | // CYCLE 5 |
511 | 580 | // TEAMS THAT DIDN'T PLAY IN LAST GAME WILL PLAY THIS GAME (< 4) |
@@ -530,7 +599,9 @@ discard block |
||
530 | 599 | break; |
531 | 600 | } |
532 | 601 | } |
533 | - if ($found) continue; |
|
602 | + if ($found) { |
|
603 | + continue; |
|
604 | + } |
|
534 | 605 | |
535 | 606 | // CYCLE 6 |
536 | 607 | // FIRST AVAILABLE GAME |
@@ -541,7 +612,9 @@ discard block |
||
541 | 612 | } |
542 | 613 | public function r_rGames(array $teams = []) { |
543 | 614 | $games = []; |
544 | - if (count($teams) === 0) $teams = $this->teams; |
|
615 | + if (count($teams) === 0) { |
|
616 | + $teams = $this->teams; |
|
617 | + } |
|
545 | 618 | switch ($this->inGame) { |
546 | 619 | case 2: |
547 | 620 | $games = circle_genGames2($teams, $this); |
@@ -589,7 +662,9 @@ discard block |
||
589 | 662 | $game->setResults($results); |
590 | 663 | } |
591 | 664 | $return = $this->sortTeams($filters); |
592 | - if (!$reset) return $return; |
|
665 | + if (!$reset) { |
|
666 | + return $return; |
|
667 | + } |
|
593 | 668 | foreach ($this->getGames() as $game) { |
594 | 669 | $game->resetResults(); |
595 | 670 | } |
@@ -597,13 +672,17 @@ discard block |
||
597 | 672 | } |
598 | 673 | public function resetGames() { |
599 | 674 | foreach ($this->getGames() as $game) { |
600 | - if (isset($game)) $game->resetResults(); |
|
675 | + if (isset($game)) { |
|
676 | + $game->resetResults(); |
|
677 | + } |
|
601 | 678 | } |
602 | 679 | return $this; |
603 | 680 | } |
604 | 681 | public function isPlayed(){ |
605 | 682 | foreach ($this->games as $game) { |
606 | - if ((isset($game) || !$this->getSkip()) && !$game->isPlayed()) return false; |
|
683 | + if ((isset($game) || !$this->getSkip()) && !$game->isPlayed()) { |
|
684 | + return false; |
|
685 | + } |
|
607 | 686 | } |
608 | 687 | return true; |
609 | 688 | } |
@@ -43,61 +43,61 @@ |
||
43 | 43 | return array_filter($this->groupResults[$groupId], function($k) { return $k !== 'group'; }, ARRAY_FILTER_USE_KEY); |
44 | 44 | } |
45 | 45 | |
46 | - public function addWin(string $groupId = ''){ |
|
46 | + public function addWin(string $groupId = '') { |
|
47 | 47 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
48 | 48 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->winPoints; |
49 | 49 | $this->groupResults[$groupId]['wins']++; |
50 | 50 | return $this; |
51 | 51 | } |
52 | - public function removeWin(string $groupId = ''){ |
|
52 | + public function removeWin(string $groupId = '') { |
|
53 | 53 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
54 | 54 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->winPoints; |
55 | 55 | $this->groupResults[$groupId]['wins']--; |
56 | 56 | return $this; |
57 | 57 | } |
58 | - public function addDraw(string $groupId = ''){ |
|
58 | + public function addDraw(string $groupId = '') { |
|
59 | 59 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
60 | 60 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->drawPoints; |
61 | 61 | $this->groupResults[$groupId]['draws']++; |
62 | 62 | return $this; |
63 | 63 | } |
64 | - public function removeDraw(string $groupId = ''){ |
|
64 | + public function removeDraw(string $groupId = '') { |
|
65 | 65 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
66 | 66 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->drawPointsPoints; |
67 | 67 | $this->groupResults[$groupId]['draws']--; |
68 | 68 | return $this; |
69 | 69 | } |
70 | - public function addLoss(string $groupId = ''){ |
|
70 | + public function addLoss(string $groupId = '') { |
|
71 | 71 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
72 | 72 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->lostPoints; |
73 | 73 | $this->groupResults[$groupId]['losses']++; |
74 | 74 | return $this; |
75 | 75 | } |
76 | - public function removeLoss(string $groupId = ''){ |
|
76 | + public function removeLoss(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']->lostPoints; |
79 | 79 | $this->groupResults[$groupId]['losses']--; |
80 | 80 | return $this; |
81 | 81 | } |
82 | - public function addSecond(string $groupId = ''){ |
|
82 | + public function addSecond(string $groupId = '') { |
|
83 | 83 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
84 | 84 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->secondPoints; |
85 | 85 | $this->groupResults[$groupId]['second']++; |
86 | 86 | return $this; |
87 | 87 | } |
88 | - public function removeSecond(string $groupId = ''){ |
|
88 | + public function removeSecond(string $groupId = '') { |
|
89 | 89 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
90 | 90 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->secondPoints; |
91 | 91 | $this->groupResults[$groupId]['second']--; |
92 | 92 | return $this; |
93 | 93 | } |
94 | - public function addThird(string $groupId = ''){ |
|
94 | + public function addThird(string $groupId = '') { |
|
95 | 95 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
96 | 96 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->thirdPoints; |
97 | 97 | $this->groupResults[$groupId]['third']++; |
98 | 98 | return $this; |
99 | 99 | } |
100 | - public function removeThird(string $groupId = ''){ |
|
100 | + public function removeThird(string $groupId = '') { |
|
101 | 101 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
102 | 102 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->thirdPoints; |
103 | 103 | $this->groupResults[$groupId]['third']--; |
@@ -44,61 +44,81 @@ |
||
44 | 44 | } |
45 | 45 | |
46 | 46 | public function addWin(string $groupId = ''){ |
47 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
47 | + if (!isset($this->groupResults[$groupId])) { |
|
48 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
49 | + } |
|
48 | 50 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->winPoints; |
49 | 51 | $this->groupResults[$groupId]['wins']++; |
50 | 52 | return $this; |
51 | 53 | } |
52 | 54 | public function removeWin(string $groupId = ''){ |
53 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
55 | + if (!isset($this->groupResults[$groupId])) { |
|
56 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
57 | + } |
|
54 | 58 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->winPoints; |
55 | 59 | $this->groupResults[$groupId]['wins']--; |
56 | 60 | return $this; |
57 | 61 | } |
58 | 62 | public function addDraw(string $groupId = ''){ |
59 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
63 | + if (!isset($this->groupResults[$groupId])) { |
|
64 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
65 | + } |
|
60 | 66 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->drawPoints; |
61 | 67 | $this->groupResults[$groupId]['draws']++; |
62 | 68 | return $this; |
63 | 69 | } |
64 | 70 | public function removeDraw(string $groupId = ''){ |
65 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
71 | + if (!isset($this->groupResults[$groupId])) { |
|
72 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
73 | + } |
|
66 | 74 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->drawPointsPoints; |
67 | 75 | $this->groupResults[$groupId]['draws']--; |
68 | 76 | return $this; |
69 | 77 | } |
70 | 78 | public function addLoss(string $groupId = ''){ |
71 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
79 | + if (!isset($this->groupResults[$groupId])) { |
|
80 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
81 | + } |
|
72 | 82 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->lostPoints; |
73 | 83 | $this->groupResults[$groupId]['losses']++; |
74 | 84 | return $this; |
75 | 85 | } |
76 | 86 | public function removeLoss(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']->lostPoints; |
79 | 91 | $this->groupResults[$groupId]['losses']--; |
80 | 92 | return $this; |
81 | 93 | } |
82 | 94 | public function addSecond(string $groupId = ''){ |
83 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
95 | + if (!isset($this->groupResults[$groupId])) { |
|
96 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
97 | + } |
|
84 | 98 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->secondPoints; |
85 | 99 | $this->groupResults[$groupId]['second']++; |
86 | 100 | return $this; |
87 | 101 | } |
88 | 102 | public function removeSecond(string $groupId = ''){ |
89 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
103 | + if (!isset($this->groupResults[$groupId])) { |
|
104 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
105 | + } |
|
90 | 106 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->secondPoints; |
91 | 107 | $this->groupResults[$groupId]['second']--; |
92 | 108 | return $this; |
93 | 109 | } |
94 | 110 | public function addThird(string $groupId = ''){ |
95 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
111 | + if (!isset($this->groupResults[$groupId])) { |
|
112 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
113 | + } |
|
96 | 114 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->thirdPoints; |
97 | 115 | $this->groupResults[$groupId]['third']++; |
98 | 116 | return $this; |
99 | 117 | } |
100 | 118 | public function removeThird(string $groupId = ''){ |
101 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
119 | + if (!isset($this->groupResults[$groupId])) { |
|
120 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
121 | + } |
|
102 | 122 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->thirdPoints; |
103 | 123 | $this->groupResults[$groupId]['third']--; |
104 | 124 | return $this; |
@@ -15,7 +15,9 @@ discard block |
||
15 | 15 | |
16 | 16 | $countTeams = count($this->getTeams()); |
17 | 17 | |
18 | - if ($countTeams < 3) throw new \Exception('Double elimination is possible for minimum of 3 teams - '.$countTeams.' teams given.'); |
|
18 | + if ($countTeams < 3) { |
|
19 | + throw new \Exception('Double elimination is possible for minimum of 3 teams - '.$countTeams.' teams given.'); |
|
20 | + } |
|
19 | 21 | |
20 | 22 | |
21 | 23 | // CALCULATE BYES |
@@ -79,15 +81,19 @@ discard block |
||
79 | 81 | if ($r === 2) { // FIRST LOSING ROUND |
80 | 82 | $previousGroups[2*($g-1)]->progression($group, 1, 1); // PROGRESS FROM STARTING GROUP |
81 | 83 | $previousGroups[(2*($g-1))+1]->progression($group, 1, 1); // PROGREESS FROM STARTING GROUP |
82 | - } |
|
83 | - elseif ($losingGroupTeamsCount >= 2) { |
|
84 | + } elseif ($losingGroupTeamsCount >= 2) { |
|
84 | 85 | $previousLosingGroups[$g-1]->progression($group, 0, 1); // PROGRESS FROM LOSING GROUP BEFORE |
85 | - if (isset(array_reverse($previousGroups)[$g-1])) array_reverse($previousGroups)[$g-1]->progression($group, 1, 1); // PROGREESS FROM WINNING GROUP BEFORE |
|
86 | - else $previousLosingGroups[$g]->progression($group, 0, 1); // PROGRESS OTHER TEAM FROM LOSING GROUP BEEFORE |
|
86 | + if (isset(array_reverse($previousGroups)[$g-1])) { |
|
87 | + array_reverse($previousGroups)[$g-1]->progression($group, 1, 1); |
|
88 | + } |
|
89 | + // PROGREESS FROM WINNING GROUP BEFORE |
|
90 | + else { |
|
91 | + $previousLosingGroups[$g]->progression($group, 0, 1); |
|
92 | + } |
|
93 | + // PROGRESS OTHER TEAM FROM LOSING GROUP BEEFORE |
|
87 | 94 | } |
88 | 95 | } |
89 | - } |
|
90 | - else { // IF THE NUMBER OF TEAMS IS NOT A POWER OF 2, GENERATE GROUPS WITH BYES |
|
96 | + } else { // IF THE NUMBER OF TEAMS IS NOT A POWER OF 2, GENERATE GROUPS WITH BYES |
|
91 | 97 | // LOOK FOR THE CLOSEST LOWER POWER OF 2 |
92 | 98 | $losingByes = $losingGroupTeamsCount-bindec(str_pad(1, strlen(decbin($losingGroupTeamsCount)), 0, STR_PAD_RIGHT)); |
93 | 99 | $n = (floor(count($previousLosingGroups)/2)+$losingByes); |
@@ -111,10 +117,12 @@ discard block |
||
111 | 117 | if (in_array($g, $byesGroupsNums) && isset($previousGroups[$byesProgressed])) { // EMPTY GROUP FROM BYE |
112 | 118 | $previousGroups[$byesProgressed]->progression($group, 1, 1); // PROGRESS FROM WINNING GROUP BEFORE |
113 | 119 | $byesProgressed++; |
114 | - } |
|
115 | - else { |
|
120 | + } else { |
|
116 | 121 | $previousLosingGroups[$lastGroup]->progression($group, 0, 1); // PROGRESS FROM LOSING GROUP BEFORE |
117 | - if (isset($previousLosingGroups[$lastGroup + 1])) $previousLosingGroups[$lastGroup + 1]->progression($group, 0, 1); // PROGREESS FROM LOSING GROUP BEFORE |
|
122 | + if (isset($previousLosingGroups[$lastGroup + 1])) { |
|
123 | + $previousLosingGroups[$lastGroup + 1]->progression($group, 0, 1); |
|
124 | + } |
|
125 | + // PROGREESS FROM LOSING GROUP BEFORE |
|
118 | 126 | $lastGroup += 2; |
119 | 127 | } |
120 | 128 | } |
@@ -12,7 +12,9 @@ |
||
12 | 12 | |
13 | 13 | public function generate() { |
14 | 14 | |
15 | - if (count($this->getTeams()) === 0) throw new \Exception('Couldn\'t generate 2R2G tournament because there are no teams in the tournament.'); |
|
15 | + if (count($this->getTeams()) === 0) { |
|
16 | + throw new \Exception('Couldn\'t generate 2R2G tournament because there are no teams in the tournament.'); |
|
17 | + } |
|
16 | 18 | |
17 | 19 | |
18 | 20 | $round1 = $this->round('Round 1'); |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | return $this->name; |
26 | 26 | } |
27 | 27 | |
28 | - public function addGroup(Group ...$groups){ |
|
28 | + public function addGroup(Group ...$groups) { |
|
29 | 29 | foreach ($groups as $group) { |
30 | 30 | if ($group instanceof Group) $this->groups[] = $group; |
31 | 31 | else throw new \Exception('Trying to add group which is not an instance of Group class.'); |
@@ -37,21 +37,21 @@ discard block |
||
37 | 37 | $this->groups[] = $g->setSkip($this->allowSkip); |
38 | 38 | return $g; |
39 | 39 | } |
40 | - public function getGroups(){ |
|
40 | + public function getGroups() { |
|
41 | 41 | $this->orderGroups(); |
42 | 42 | return $this->groups; |
43 | 43 | } |
44 | 44 | public function orderGroups() { |
45 | - usort($this->groups, function($a, $b){ |
|
46 | - return $a->order - $b->order; |
|
45 | + usort($this->groups, function($a, $b) { |
|
46 | + return $a->order-$b->order; |
|
47 | 47 | }); |
48 | 48 | } |
49 | 49 | |
50 | - public function allowSkip(){ |
|
50 | + public function allowSkip() { |
|
51 | 51 | $this->allowSkip = true; |
52 | 52 | return $this; |
53 | 53 | } |
54 | - public function disallowSkip(){ |
|
54 | + public function disallowSkip() { |
|
55 | 55 | $this->allowSkip = false; |
56 | 56 | return $this; |
57 | 57 | } |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | return $this->allowSkip; |
64 | 64 | } |
65 | 65 | |
66 | - public function genGames(){ |
|
66 | + public function genGames() { |
|
67 | 67 | $games = []; |
68 | 68 | $g = 0; |
69 | 69 | foreach ($this->groups as $group) { |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | public function getGames() { |
88 | 88 | return $this->games; |
89 | 89 | } |
90 | - public function isPlayed(){ |
|
90 | + public function isPlayed() { |
|
91 | 91 | foreach ($this->groups as $group) { |
92 | 92 | if (!$group->isPlayed()) return false; |
93 | 93 | } |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | |
97 | 97 | public function addTeam(...$teams) { |
98 | 98 | foreach ($teams as $team) { |
99 | - if ($team instanceof Team) { |
|
99 | + if ($team instanceof Team) { |
|
100 | 100 | $this->teams[] = $team; |
101 | 101 | } |
102 | 102 | elseif (gettype($team) === 'array') { |
@@ -157,14 +157,14 @@ discard block |
||
157 | 157 | return $this; |
158 | 158 | } |
159 | 159 | |
160 | - public function progress(){ |
|
160 | + public function progress() { |
|
161 | 161 | foreach ($this->groups as $group) { |
162 | 162 | $group->progress(); |
163 | 163 | } |
164 | 164 | return $this; |
165 | 165 | } |
166 | 166 | |
167 | - public function progressBlank(){ |
|
167 | + public function progressBlank() { |
|
168 | 168 | if (!$this->isPlayed()) $this->simulate(); |
169 | 169 | foreach ($this->groups as $group) { |
170 | 170 | $group->progressBlank(); |
@@ -27,8 +27,11 @@ discard block |
||
27 | 27 | |
28 | 28 | public function addGroup(Group ...$groups){ |
29 | 29 | foreach ($groups as $group) { |
30 | - if ($group instanceof Group) $this->groups[] = $group; |
|
31 | - else throw new \Exception('Trying to add group which is not an instance of Group class.'); |
|
30 | + if ($group instanceof Group) { |
|
31 | + $this->groups[] = $group; |
|
32 | + } else { |
|
33 | + throw new \Exception('Trying to add group which is not an instance of Group class.'); |
|
34 | + } |
|
32 | 35 | } |
33 | 36 | return $this; |
34 | 37 | } |
@@ -78,7 +81,9 @@ discard block |
||
78 | 81 | while ($g > 0) { |
79 | 82 | foreach ($games as $key => $group) { |
80 | 83 | $this->games[] = array_shift($games[$key]); |
81 | - if (count($games[$key]) === 0) unset($games[$key]); |
|
84 | + if (count($games[$key]) === 0) { |
|
85 | + unset($games[$key]); |
|
86 | + } |
|
82 | 87 | $g--; |
83 | 88 | } |
84 | 89 | } |
@@ -89,7 +94,9 @@ discard block |
||
89 | 94 | } |
90 | 95 | public function isPlayed(){ |
91 | 96 | foreach ($this->groups as $group) { |
92 | - if (!$group->isPlayed()) return false; |
|
97 | + if (!$group->isPlayed()) { |
|
98 | + return false; |
|
99 | + } |
|
93 | 100 | } |
94 | 101 | return true; |
95 | 102 | } |
@@ -98,10 +105,11 @@ discard block |
||
98 | 105 | foreach ($teams as $team) { |
99 | 106 | if ($team instanceof Team) { |
100 | 107 | $this->teams[] = $team; |
101 | - } |
|
102 | - elseif (gettype($team) === 'array') { |
|
108 | + } elseif (gettype($team) === 'array') { |
|
103 | 109 | foreach ($team as $team2) { |
104 | - if ($team2 instanceof Team) $this->teams[] = $team2; |
|
110 | + if ($team2 instanceof Team) { |
|
111 | + $this->teams[] = $team2; |
|
112 | + } |
|
105 | 113 | $team2->groupResults[$this->id] = [ |
106 | 114 | 'group' => $this, |
107 | 115 | 'points' => 0, |
@@ -113,8 +121,9 @@ discard block |
||
113 | 121 | 'third' => 0 |
114 | 122 | ]; |
115 | 123 | } |
124 | + } else { |
|
125 | + throw new \Exception('Trying to add team which is not an instance of Team class'); |
|
116 | 126 | } |
117 | - else throw new \Exception('Trying to add team which is not an instance of Team class'); |
|
118 | 127 | } |
119 | 128 | return $this; |
120 | 129 | } |
@@ -124,7 +133,9 @@ discard block |
||
124 | 133 | return $t; |
125 | 134 | } |
126 | 135 | public function getTeams() { |
127 | - if (count($this->teams) > 0) return $this->teams; |
|
136 | + if (count($this->teams) > 0) { |
|
137 | + return $this->teams; |
|
138 | + } |
|
128 | 139 | $teams = []; |
129 | 140 | foreach ($this->groups as $group) { |
130 | 141 | $teams = array_merge($teams, $group->getTeams()); |
@@ -135,7 +146,9 @@ discard block |
||
135 | 146 | |
136 | 147 | public function splitTeams(...$groups) { |
137 | 148 | |
138 | - if (count($groups) === 0) $groups = $this->getGroups(); |
|
149 | + if (count($groups) === 0) { |
|
150 | + $groups = $this->getGroups(); |
|
151 | + } |
|
139 | 152 | |
140 | 153 | foreach ($groups as $key => $value) { |
141 | 154 | if (gettype($value) === 'array') { |
@@ -150,7 +163,9 @@ discard block |
||
150 | 163 | while (count($teams) > 0) { |
151 | 164 | foreach ($groups as $group) { |
152 | 165 | if ($group instanceof Group) { |
153 | - if (count($teams) > 0) $group->addTeam(array_shift($teams)); |
|
166 | + if (count($teams) > 0) { |
|
167 | + $group->addTeam(array_shift($teams)); |
|
168 | + } |
|
154 | 169 | } |
155 | 170 | } |
156 | 171 | } |
@@ -165,7 +180,9 @@ discard block |
||
165 | 180 | } |
166 | 181 | |
167 | 182 | public function progressBlank(){ |
168 | - if (!$this->isPlayed()) $this->simulate(); |
|
183 | + if (!$this->isPlayed()) { |
|
184 | + $this->simulate(); |
|
185 | + } |
|
169 | 186 | foreach ($this->groups as $group) { |
170 | 187 | $group->progressBlank(); |
171 | 188 | } |
@@ -174,7 +191,9 @@ discard block |
||
174 | 191 | |
175 | 192 | public function simulate() { |
176 | 193 | foreach ($this->groups as $group) { |
177 | - if ($group->isPlayed()) continue; |
|
194 | + if ($group->isPlayed()) { |
|
195 | + continue; |
|
196 | + } |
|
178 | 197 | $group->simulate([], false); |
179 | 198 | } |
180 | 199 | return $this; |
@@ -45,12 +45,12 @@ |
||
45 | 45 | |
46 | 46 | private $groups = []; |
47 | 47 | |
48 | - function __construct(string $what = 'points', string $how = '>', $val = 0, $groups = []){ |
|
48 | + function __construct(string $what = 'points', string $how = '>', $val = 0, $groups = []) { |
|
49 | 49 | if (in_array(strtolower($what), ['points', 'score', 'wins', 'draws', 'losses', 'second', 'third', 'team', 'notprogressed', 'progressed'])) $this->what = strtolower($what); |
50 | 50 | if (in_array($how, ['>', '<', '>=', '<=', '=', '!='])) $this->how = $how; |
51 | 51 | if ((gettype($val) === 'integer' && strtolower($what) !== 'team') || ($val instanceof Team && strtolower($what) === 'team')) $this->val = $val; |
52 | 52 | foreach ($groups as $group) { |
53 | - if ($group instanceof Group) $this->groups[] = $group->id; |
|
53 | + if ($group instanceof Group) $this->groups[] = $group->id; |
|
54 | 54 | } |
55 | 55 | } |
56 | 56 | public function __toString() { |
@@ -46,11 +46,19 @@ discard block |
||
46 | 46 | private $groups = []; |
47 | 47 | |
48 | 48 | function __construct(string $what = 'points', string $how = '>', $val = 0, $groups = []){ |
49 | - if (in_array(strtolower($what), ['points', 'score', 'wins', 'draws', 'losses', 'second', 'third', 'team', 'notprogressed', 'progressed'])) $this->what = strtolower($what); |
|
50 | - if (in_array($how, ['>', '<', '>=', '<=', '=', '!='])) $this->how = $how; |
|
51 | - if ((gettype($val) === 'integer' && strtolower($what) !== 'team') || ($val instanceof Team && strtolower($what) === 'team')) $this->val = $val; |
|
49 | + if (in_array(strtolower($what), ['points', 'score', 'wins', 'draws', 'losses', 'second', 'third', 'team', 'notprogressed', 'progressed'])) { |
|
50 | + $this->what = strtolower($what); |
|
51 | + } |
|
52 | + if (in_array($how, ['>', '<', '>=', '<=', '=', '!='])) { |
|
53 | + $this->how = $how; |
|
54 | + } |
|
55 | + if ((gettype($val) === 'integer' && strtolower($what) !== 'team') || ($val instanceof Team && strtolower($what) === 'team')) { |
|
56 | + $this->val = $val; |
|
57 | + } |
|
52 | 58 | foreach ($groups as $group) { |
53 | - if ($group instanceof Group) $this->groups[] = $group->id; |
|
59 | + if ($group instanceof Group) { |
|
60 | + $this->groups[] = $group->id; |
|
61 | + } |
|
54 | 62 | } |
55 | 63 | } |
56 | 64 | public function __toString() { |
@@ -58,37 +66,54 @@ discard block |
||
58 | 66 | } |
59 | 67 | |
60 | 68 | public function validate(Team $team, $groupsId, string $operation = 'sum', Group $from = null) { |
61 | - if (count($this->groups) > 0) $groupsId = array_unique(array_merge($this->groups, (gettype($groupsId) === 'array' ? $groupsId : [$groupsId])), SORT_REGULAR); |
|
69 | + if (count($this->groups) > 0) { |
|
70 | + $groupsId = array_unique(array_merge($this->groups, (gettype($groupsId) === 'array' ? $groupsId : [$groupsId])), SORT_REGULAR); |
|
71 | + } |
|
62 | 72 | if ($this->what == 'team') { |
63 | 73 | switch ($this->how) { |
64 | 74 | case '=': |
65 | - if ($this->val === $team) return true; |
|
75 | + if ($this->val === $team) { |
|
76 | + return true; |
|
77 | + } |
|
66 | 78 | break; |
67 | 79 | case '!=': |
68 | - if ($this->val !== $team) return true; |
|
80 | + if ($this->val !== $team) { |
|
81 | + return true; |
|
82 | + } |
|
69 | 83 | break; |
70 | 84 | } |
71 | 85 | return false; |
72 | - } |
|
73 | - elseif ($this->what == 'notprogressed') { |
|
74 | - if ($from === null) throw new \Exception('Group $from was not defined.'); |
|
86 | + } elseif ($this->what == 'notprogressed') { |
|
87 | + if ($from === null) { |
|
88 | + throw new \Exception('Group $from was not defined.'); |
|
89 | + } |
|
75 | 90 | return !$from->progressed($team); |
76 | - } |
|
77 | - elseif ($this->what == 'progressed') { |
|
78 | - if ($from === null) throw new \Exception('Group $from was not defined.'); |
|
91 | + } elseif ($this->what == 'progressed') { |
|
92 | + if ($from === null) { |
|
93 | + throw new \Exception('Group $from was not defined.'); |
|
94 | + } |
|
79 | 95 | return $from->progressed($team); |
80 | 96 | } |
81 | - 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.'); |
|
97 | + if (gettype($groupsId) === 'array' && !in_array(strtolower($operation), ['sum', 'avg', 'max', 'min'])) { |
|
98 | + throw new \Exception('Unknown operation of '.$operation.'. Only "sum", "avg", "min", "max" possible.'); |
|
99 | + } |
|
82 | 100 | $comp = 0; |
83 | 101 | if (gettype($groupsId) === 'array' && count($groupsId) > 0) { |
84 | 102 | $sum = 0; |
85 | 103 | $max = null; |
86 | 104 | $min = null; |
87 | 105 | foreach ($groupsId as $id) { |
88 | - if (!isset($team->groupResults[$id])) continue; // IF TEAM DIDN'T PLAY IN THAT GROUP -> SKIP |
|
106 | + if (!isset($team->groupResults[$id])) { |
|
107 | + continue; |
|
108 | + } |
|
109 | + // IF TEAM DIDN'T PLAY IN THAT GROUP -> SKIP |
|
89 | 110 | $sum += $team->groupResults[$id][$this->what]; |
90 | - if ($team->groupResults[$id][$this->what] > $max || $max === null) $max = $team->groupResults[$id][$this->what]; |
|
91 | - if ($team->groupResults[$id][$this->what] < $min || $min === null) $min = $team->groupResults[$id][$this->what]; |
|
111 | + if ($team->groupResults[$id][$this->what] > $max || $max === null) { |
|
112 | + $max = $team->groupResults[$id][$this->what]; |
|
113 | + } |
|
114 | + if ($team->groupResults[$id][$this->what] < $min || $min === null) { |
|
115 | + $min = $team->groupResults[$id][$this->what]; |
|
116 | + } |
|
92 | 117 | } |
93 | 118 | switch (strtolower($operation)) { |
94 | 119 | case 'sum': |
@@ -104,11 +129,9 @@ discard block |
||
104 | 129 | $comp = $min; |
105 | 130 | break; |
106 | 131 | } |
107 | - } |
|
108 | - elseif (gettype($groupsId) === 'string' && isset($team->groupResults[$groupsId])) { |
|
132 | + } elseif (gettype($groupsId) === 'string' && isset($team->groupResults[$groupsId])) { |
|
109 | 133 | $comp = $team->groupResults[$groupsId][$this->what]; |
110 | - } |
|
111 | - else { |
|
134 | + } else { |
|
112 | 135 | throw new \Exception("Couldn't find group of id ".print_r($groupsId, true)); |
113 | 136 | } |
114 | 137 |
@@ -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') { |
@@ -80,8 +80,11 @@ discard block |
||
80 | 80 | |
81 | 81 | public function addCategory(Category ...$categories){ |
82 | 82 | foreach ($categories as $category) { |
83 | - if ($category instanceof Category) $this->categories[] = $category; |
|
84 | - else throw new \Exception('Trying to add category which is not an instance of the Category class.'); |
|
83 | + if ($category instanceof Category) { |
|
84 | + $this->categories[] = $category; |
|
85 | + } else { |
|
86 | + throw new \Exception('Trying to add category which is not an instance of the Category class.'); |
|
87 | + } |
|
85 | 88 | } |
86 | 89 | return $this; |
87 | 90 | } |
@@ -96,8 +99,11 @@ discard block |
||
96 | 99 | |
97 | 100 | public function addRound(Round ...$rounds) { |
98 | 101 | foreach ($rounds as $round) { |
99 | - if ($round instanceof Round) $this->rounds[] = $round; |
|
100 | - else throw new \Exception('Trying to add round which is not an instance of the Round class.'); |
|
102 | + if ($round instanceof Round) { |
|
103 | + $this->rounds[] = $round; |
|
104 | + } else { |
|
105 | + throw new \Exception('Trying to add round which is not an instance of the Round class.'); |
|
106 | + } |
|
101 | 107 | } |
102 | 108 | return $this; |
103 | 109 | } |
@@ -121,13 +127,15 @@ discard block |
||
121 | 127 | foreach ($teams as $team) { |
122 | 128 | if ($team instanceof Team) { |
123 | 129 | $this->teams[] = $team; |
124 | - } |
|
125 | - elseif (gettype($team) === 'array') { |
|
130 | + } elseif (gettype($team) === 'array') { |
|
126 | 131 | foreach ($team as $team2) { |
127 | - if ($team2 instanceof Team) $this->teams[] = $team2; |
|
132 | + if ($team2 instanceof Team) { |
|
133 | + $this->teams[] = $team2; |
|
134 | + } |
|
128 | 135 | } |
136 | + } else { |
|
137 | + throw new \Exception('Trying to add team which is not an instance of Team class'); |
|
129 | 138 | } |
130 | - else throw new \Exception('Trying to add team which is not an instance of Team class'); |
|
131 | 139 | } |
132 | 140 | return $this; |
133 | 141 | } |
@@ -137,7 +145,9 @@ discard block |
||
137 | 145 | return $t; |
138 | 146 | } |
139 | 147 | public function getTeams() { |
140 | - if (count($this->teams) > 0) return $this->teams; |
|
148 | + if (count($this->teams) > 0) { |
|
149 | + return $this->teams; |
|
150 | + } |
|
141 | 151 | $teams = []; |
142 | 152 | foreach ($this->categories as $category) { |
143 | 153 | $teams = array_merge($teams, $category->getTeams()); |
@@ -159,7 +169,9 @@ discard block |
||
159 | 169 | |
160 | 170 | public function splitTeams(...$wheres) { |
161 | 171 | |
162 | - if (count($wheres) === 0) $wheres = array_merge($this->getRounds(), $this->getCategories()); |
|
172 | + if (count($wheres) === 0) { |
|
173 | + $wheres = array_merge($this->getRounds(), $this->getCategories()); |
|
174 | + } |
|
163 | 175 | |
164 | 176 | foreach ($wheres as $key => $value) { |
165 | 177 | if (gettype($value) === 'array') { |
@@ -174,10 +186,13 @@ discard block |
||
174 | 186 | while (count($teams) > 0) { |
175 | 187 | foreach ($wheres as $where) { |
176 | 188 | if ($where instanceof Round) { |
177 | - if (count($teams) > 0) $where->addTeam(array_shift($teams)); |
|
178 | - } |
|
179 | - elseif ($where instanceof Category) { |
|
180 | - if (count($teams) > 0) $where->addTeam(array_shift($teams)); |
|
189 | + if (count($teams) > 0) { |
|
190 | + $where->addTeam(array_shift($teams)); |
|
191 | + } |
|
192 | + } elseif ($where instanceof Category) { |
|
193 | + if (count($teams) > 0) { |
|
194 | + $where->addTeam(array_shift($teams)); |
|
195 | + } |
|
181 | 196 | } |
182 | 197 | } |
183 | 198 | } |
@@ -193,8 +208,7 @@ discard block |
||
193 | 208 | foreach ($this->categories as $category) { |
194 | 209 | $games = array_merge($games, $category->genGamesSimulate()); |
195 | 210 | } |
196 | - } |
|
197 | - elseif (count($this->rounds) > 0) { |
|
211 | + } elseif (count($this->rounds) > 0) { |
|
198 | 212 | foreach ($this->rounds as $round) { |
199 | 213 | $games = array_merge($games, $round->genGames()); |
200 | 214 | $round->simulate()->progressBlank(); |
@@ -202,11 +216,12 @@ discard block |
||
202 | 216 | foreach ($this->rounds as $round) { |
203 | 217 | $round->resetGames(); |
204 | 218 | } |
205 | - } |
|
206 | - else { |
|
219 | + } else { |
|
207 | 220 | throw new \Exception('There are no rounds or categories to simulate games from.'); |
208 | 221 | } |
209 | - if ($returnTime) return $this->getTournamentTime(); |
|
222 | + if ($returnTime) { |
|
223 | + return $this->getTournamentTime(); |
|
224 | + } |
|
210 | 225 | return $games; |
211 | 226 | } |
212 | 227 | public function genGamesSimulateReal(bool $returnTime = false) { |
@@ -215,18 +230,18 @@ discard block |
||
215 | 230 | foreach ($this->categories as $category) { |
216 | 231 | $games = array_merge($games, $category->genGamesSimulate()); |
217 | 232 | } |
218 | - } |
|
219 | - elseif (count($this->rounds) > 0) { |
|
233 | + } elseif (count($this->rounds) > 0) { |
|
220 | 234 | foreach ($this->rounds as $round) { |
221 | 235 | $games = array_merge($games, $round->genGames()); |
222 | 236 | $round->simulate(); |
223 | 237 | $round->progress(); |
224 | 238 | } |
225 | - } |
|
226 | - else { |
|
239 | + } else { |
|
227 | 240 | throw new \Exception('There are no rounds or categories to simulate games from.'); |
228 | 241 | } |
229 | - if ($returnTime) return $this->getTournamentTime(); |
|
242 | + if ($returnTime) { |
|
243 | + return $this->getTournamentTime(); |
|
244 | + } |
|
230 | 245 | return $games; |
231 | 246 | } |
232 | 247 |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | $this->name = $name; |
22 | 22 | } |
23 | 23 | |
24 | - public function addRound(Round ...$rounds){ |
|
24 | + public function addRound(Round ...$rounds) { |
|
25 | 25 | foreach ($rounds as $round) { |
26 | 26 | if ($round instanceof Round) $this->rounds[] = $round; |
27 | 27 | else throw new \Exception('Trying to add round which is not an instance of Round class.'); |
@@ -33,15 +33,15 @@ discard block |
||
33 | 33 | $this->rounds[] = $r->setSkip($this->allowSkip); |
34 | 34 | return $r; |
35 | 35 | } |
36 | - public function getRounds(){ |
|
36 | + public function getRounds() { |
|
37 | 37 | return $this->rounds; |
38 | 38 | } |
39 | 39 | |
40 | - public function allowSkip(){ |
|
40 | + public function allowSkip() { |
|
41 | 41 | $this->allowSkip = true; |
42 | 42 | return $this; |
43 | 43 | } |
44 | - public function disallowSkip(){ |
|
44 | + public function disallowSkip() { |
|
45 | 45 | $this->allowSkip = false; |
46 | 46 | return $this; |
47 | 47 | } |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | |
56 | 56 | public function addTeam(...$teams) { |
57 | 57 | foreach ($teams as $team) { |
58 | - if ($team instanceof Team) { |
|
58 | + if ($team instanceof Team) { |
|
59 | 59 | $this->teams[] = $team; |
60 | 60 | } |
61 | 61 | elseif (gettype($team) === 'array') { |
@@ -23,8 +23,11 @@ discard block |
||
23 | 23 | |
24 | 24 | public function addRound(Round ...$rounds){ |
25 | 25 | foreach ($rounds as $round) { |
26 | - if ($round instanceof Round) $this->rounds[] = $round; |
|
27 | - else throw new \Exception('Trying to add round which is not an instance of Round class.'); |
|
26 | + if ($round instanceof Round) { |
|
27 | + $this->rounds[] = $round; |
|
28 | + } else { |
|
29 | + throw new \Exception('Trying to add round which is not an instance of Round class.'); |
|
30 | + } |
|
28 | 31 | } |
29 | 32 | return $this; |
30 | 33 | } |
@@ -57,13 +60,15 @@ discard block |
||
57 | 60 | foreach ($teams as $team) { |
58 | 61 | if ($team instanceof Team) { |
59 | 62 | $this->teams[] = $team; |
60 | - } |
|
61 | - elseif (gettype($team) === 'array') { |
|
63 | + } elseif (gettype($team) === 'array') { |
|
62 | 64 | foreach ($team as $team2) { |
63 | - if ($team2 instanceof Team) $this->teams[] = $team2; |
|
65 | + if ($team2 instanceof Team) { |
|
66 | + $this->teams[] = $team2; |
|
67 | + } |
|
64 | 68 | } |
69 | + } else { |
|
70 | + throw new \Exception('Trying to add team which is not an instance of Team class'); |
|
65 | 71 | } |
66 | - else throw new \Exception('Trying to add team which is not an instance of Team class'); |
|
67 | 72 | } |
68 | 73 | return $this; |
69 | 74 | } |
@@ -73,7 +78,9 @@ discard block |
||
73 | 78 | return $t; |
74 | 79 | } |
75 | 80 | public function getTeams() { |
76 | - if (count($this->teams) > 0) return $this->teams; |
|
81 | + if (count($this->teams) > 0) { |
|
82 | + return $this->teams; |
|
83 | + } |
|
77 | 84 | $teams = []; |
78 | 85 | foreach ($this->rounds as $round) { |
79 | 86 | $teams = array_merge($teams, $round->getTeams()); |
@@ -92,7 +99,9 @@ discard block |
||
92 | 99 | |
93 | 100 | public function splitTeams(...$rounds) { |
94 | 101 | |
95 | - if (count($rounds) === 0) $rounds = $this->getRounds(); |
|
102 | + if (count($rounds) === 0) { |
|
103 | + $rounds = $this->getRounds(); |
|
104 | + } |
|
96 | 105 | |
97 | 106 | $teams = $this->getTeams(); |
98 | 107 | shuffle($teams); |
@@ -112,7 +121,9 @@ discard block |
||
112 | 121 | |
113 | 122 | public function genGamesSimulate() { |
114 | 123 | $games = []; |
115 | - if (count($this->rounds) <= 0) throw new \Exception('There are no rounds to simulate games from.'); |
|
124 | + if (count($this->rounds) <= 0) { |
|
125 | + throw new \Exception('There are no rounds to simulate games from.'); |
|
126 | + } |
|
116 | 127 | foreach ($this->rounds as $round) { |
117 | 128 | $games = array_merge($games, $round->genGames()); |
118 | 129 | $round->simulate()->progressBlank()->resetGames(); |
@@ -78,10 +78,10 @@ discard block |
||
78 | 78 | 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)); |
79 | 79 | return $this; |
80 | 80 | } |
81 | - public function getTeams(){ |
|
81 | + public function getTeams() { |
|
82 | 82 | return $this->teams; |
83 | 83 | } |
84 | - public function getTeamsIds(){ |
|
84 | + public function getTeamsIds() { |
|
85 | 85 | $ids = []; |
86 | 86 | foreach ($this->teams as $team) { |
87 | 87 | $ids[] = $team->id; |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | $team->addLoss($this->group->id); |
129 | 129 | $this->results[$team->id] += ['points' => $this->group->lostPoints, 'type' => 'loss']; |
130 | 130 | } |
131 | - break;} |
|
131 | + break; } |
|
132 | 132 | case 3:{ |
133 | 133 | switch ($i) { |
134 | 134 | case 1: |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | $this->results[$team->id] += ['points' => $this->group->lostPoints, 'type' => 'loss']; |
148 | 148 | break; |
149 | 149 | } |
150 | - break;} |
|
150 | + break; } |
|
151 | 151 | case 4:{ |
152 | 152 | switch ($i) { |
153 | 153 | case 1: |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | $this->results[$team->id] += ['points' => $this->group->lostPoints, 'type' => 'loss']; |
172 | 172 | break; |
173 | 173 | } |
174 | - break;} |
|
174 | + break; } |
|
175 | 175 | } |
176 | 176 | $team->groupResults[$this->group->id]['score'] += $score; |
177 | 177 | $i++; |
@@ -27,9 +27,10 @@ discard block |
||
27 | 27 | if (!$team instanceof Team) { |
28 | 28 | $error[] = $team; |
29 | 29 | unset($teams[$key]); |
30 | - } |
|
31 | - else { |
|
32 | - if (!isset($team->games[$group->id])) $team->games[$group->id] = []; |
|
30 | + } else { |
|
31 | + if (!isset($team->games[$group->id])) { |
|
32 | + $team->games[$group->id] = []; |
|
33 | + } |
|
33 | 34 | $team->games[$group->id][] = $this; |
34 | 35 | $tids[] = $team->id; |
35 | 36 | } |
@@ -38,12 +39,16 @@ discard block |
||
38 | 39 | foreach ($this->teams as $team) { |
39 | 40 | foreach ($tids as $id) { |
40 | 41 | if ($team->id !== $id) { |
41 | - if (!isset($team->gamesWith[$group->id][$id])) $team->gamesWith[$group->id][$id] = 0; |
|
42 | + if (!isset($team->gamesWith[$group->id][$id])) { |
|
43 | + $team->gamesWith[$group->id][$id] = 0; |
|
44 | + } |
|
42 | 45 | $team->gamesWith[$group->id][$id]++; |
43 | 46 | } |
44 | 47 | } |
45 | 48 | } |
46 | - 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)); |
|
49 | + if (count($error) > 0) { |
|
50 | + throw new \Exception('Trying to add teams ('.count($error).') that are not instance of Team class'.PHP_EOL.print_r($error, true)); |
|
51 | + } |
|
47 | 52 | } |
48 | 53 | |
49 | 54 | public function addTeam(...$teams) { |
@@ -51,9 +56,13 @@ discard block |
||
51 | 56 | foreach ($this->teams as $team) { |
52 | 57 | foreach ($teams as $team2) { |
53 | 58 | if ($team2 instanceof Team) { |
54 | - if (!isset($team->gamesWith[$this->group->id][$team2->id])) $team->gamesWith[$this->group->id][$team2->id] = 0; |
|
59 | + if (!isset($team->gamesWith[$this->group->id][$team2->id])) { |
|
60 | + $team->gamesWith[$this->group->id][$team2->id] = 0; |
|
61 | + } |
|
55 | 62 | $team->gamesWith[$this->group->id][$team2->id]++; |
56 | - if (!isset($team2->gamesWith[$this->group->id][$team->id])) $team2->gamesWith[$this->group->id][$team->id] = 0; |
|
63 | + if (!isset($team2->gamesWith[$this->group->id][$team->id])) { |
|
64 | + $team2->gamesWith[$this->group->id][$team->id] = 0; |
|
65 | + } |
|
57 | 66 | $team2->gamesWith[$this->group->id][$team->id]++; |
58 | 67 | } |
59 | 68 | } |
@@ -61,21 +70,26 @@ discard block |
||
61 | 70 | foreach ($teams as $key => $team) { |
62 | 71 | if ($team instanceof Team) { |
63 | 72 | $this->teams[] = $team; |
64 | - if (!isset($team->games[$this->group->id])) $team->games[$this->group->id] = []; |
|
73 | + if (!isset($team->games[$this->group->id])) { |
|
74 | + $team->games[$this->group->id] = []; |
|
75 | + } |
|
65 | 76 | $team->games[$this->group->id][] = $this; |
66 | 77 | foreach ($teams as $key2 => $team2) { |
67 | 78 | if ($team2 instanceof Team) { |
68 | - if (!isset($team->gamesWith[$this->group->id][$team2->id])) $team->gamesWith[$this->group->id][$team2->id] = 0; |
|
79 | + if (!isset($team->gamesWith[$this->group->id][$team2->id])) { |
|
80 | + $team->gamesWith[$this->group->id][$team2->id] = 0; |
|
81 | + } |
|
69 | 82 | $team->gamesWith[$this->group->id][$team2->id]++; |
70 | 83 | } |
71 | 84 | } |
72 | - } |
|
73 | - else { |
|
85 | + } else { |
|
74 | 86 | $error[] = $team; |
75 | 87 | unset($teams[$key]); |
76 | 88 | } |
77 | 89 | } |
78 | - 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)); |
|
90 | + if (count($error) > 0) { |
|
91 | + throw new \Exception('Trying to add teams ('.count($error).') that are not instance of Team class'.PHP_EOL.print_r($error, true)); |
|
92 | + } |
|
79 | 93 | return $this; |
80 | 94 | } |
81 | 95 | public function getTeams(){ |
@@ -90,7 +104,9 @@ discard block |
||
90 | 104 | } |
91 | 105 | public function getTeam(string $id) { |
92 | 106 | foreach ($this->teams as $team) { |
93 | - if ($team->id === $id) return $team; |
|
107 | + if ($team->id === $id) { |
|
108 | + return $team; |
|
109 | + } |
|
94 | 110 | } |
95 | 111 | return false; |
96 | 112 | } |
@@ -101,12 +117,16 @@ discard block |
||
101 | 117 | * ) |
102 | 118 | */ |
103 | 119 | public function setResults(array $results = []) { |
104 | - if (count($this->results) === 0) $this->resetResults(); |
|
120 | + if (count($this->results) === 0) { |
|
121 | + $this->resetResults(); |
|
122 | + } |
|
105 | 123 | arsort($results); |
106 | 124 | $i = 1; |
107 | 125 | foreach ($results as $id => $score) { |
108 | 126 | $team = $this->getTeam($id); |
109 | - if ($team === false) throw new \Exception('Couldn\'t find team with id of "'.$id.'"'); |
|
127 | + if ($team === false) { |
|
128 | + throw new \Exception('Couldn\'t find team with id of "'.$id.'"'); |
|
129 | + } |
|
110 | 130 | $this->results[$team->id] = ['score' => $score]; |
111 | 131 | $prev = prev($results); |
112 | 132 | next($results); |
@@ -117,13 +137,11 @@ discard block |
||
117 | 137 | $this->drawIds[] = $team->id; |
118 | 138 | $team->addDraw($this->group->id); |
119 | 139 | $this->results[$team->id] += ['points' => $this->group->drawPoints, 'type' => 'draw']; |
120 | - } |
|
121 | - elseif ($i === 1) { |
|
140 | + } elseif ($i === 1) { |
|
122 | 141 | $this->winId = $team->id; |
123 | 142 | $team->addWin($this->group->id); |
124 | 143 | $this->results[$team->id] += ['points' => $this->group->winPoints, 'type' => 'win']; |
125 | - } |
|
126 | - else { |
|
144 | + } else { |
|
127 | 145 | $this->lossId = $team->id; |
128 | 146 | $team->addLoss($this->group->id); |
129 | 147 | $this->results[$team->id] += ['points' => $this->group->lostPoints, 'type' => 'loss']; |
@@ -220,7 +238,9 @@ discard block |
||
220 | 238 | } |
221 | 239 | |
222 | 240 | public function isPlayed() { |
223 | - if (count($this->results) > 0) return true; |
|
241 | + if (count($this->results) > 0) { |
|
242 | + return true; |
|
243 | + } |
|
224 | 244 | return false; |
225 | 245 | } |
226 | 246 | } |