@@ -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,10 +297,14 @@ 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; |
@@ -286,16 +332,13 @@ discard block |
||
286 | 332 | foreach ($teams as $team) { |
287 | 333 | if ($team instanceOf Team) { |
288 | 334 | $this->progressed[] = $team->id; |
289 | - } |
|
290 | - elseif (gettype($team) === 'string' || gettype($team) === 'integer') { |
|
335 | + } elseif (gettype($team) === 'string' || gettype($team) === 'integer') { |
|
291 | 336 | $this->progressed[] = $team; |
292 | - } |
|
293 | - elseif (gettype($team) === 'array') { |
|
337 | + } elseif (gettype($team) === 'array') { |
|
294 | 338 | foreach ($team as $teamInner) { |
295 | 339 | if ($teamInner instanceOf Team) { |
296 | 340 | $this->progressed[] = $teamInner->id; |
297 | - } |
|
298 | - elseif (gettype($teamInner) === 'string' || gettype($teamInner) === 'integer') { |
|
341 | + } elseif (gettype($teamInner) === 'string' || gettype($teamInner) === 'integer') { |
|
299 | 342 | $this->progressed[] = $teamInner; |
300 | 343 | } |
301 | 344 | } |
@@ -349,12 +392,15 @@ discard block |
||
349 | 392 | while ($g > 0) { |
350 | 393 | foreach ($games as $key => $group) { |
351 | 394 | $this->games[] = array_shift($games[$key]); |
352 | - if (count($games[$key]) === 0) unset($games[$key]); |
|
395 | + if (count($games[$key]) === 0) { |
|
396 | + unset($games[$key]); |
|
397 | + } |
|
353 | 398 | $g--; |
354 | 399 | } |
355 | 400 | } |
401 | + } else { |
|
402 | + $this->games = $this->r_rGames(); |
|
356 | 403 | } |
357 | - else $this->games = $this->r_rGames(); |
|
358 | 404 | break; |
359 | 405 | } |
360 | 406 | return $this->games; |
@@ -366,8 +412,11 @@ discard block |
||
366 | 412 | } |
367 | 413 | public function addGame(Game ...$games){ |
368 | 414 | foreach ($games as $game) { |
369 | - if ($game instanceof Game) $this->games[] = $game; |
|
370 | - else throw new \Exception('Trying to add game which is not instance of Game object.'); |
|
415 | + if ($game instanceof Game) { |
|
416 | + $this->games[] = $game; |
|
417 | + } else { |
|
418 | + throw new \Exception('Trying to add game which is not instance of Game object.'); |
|
419 | + } |
|
371 | 420 | } |
372 | 421 | return $this; |
373 | 422 | } |
@@ -395,21 +444,30 @@ discard block |
||
395 | 444 | $teams[$team->id] = 0; |
396 | 445 | } |
397 | 446 | foreach (end($this->games)->getTeams() as $team) { |
398 | - if (!isset($teams[$team->id])) $teams[$team->id] = 4; |
|
399 | - else $teams[$team->id] += 4; |
|
447 | + if (!isset($teams[$team->id])) { |
|
448 | + $teams[$team->id] = 4; |
|
449 | + } else { |
|
450 | + $teams[$team->id] += 4; |
|
451 | + } |
|
400 | 452 | } |
401 | 453 | $g = prev($this->games); |
402 | 454 | if ($g instanceof Game) { |
403 | 455 | foreach ($g->getTeams() as $team) { |
404 | - if (!isset($teams[$team->id])) $teams[$team->id] = 2; |
|
405 | - else $teams[$team->id] += 2; |
|
456 | + if (!isset($teams[$team->id])) { |
|
457 | + $teams[$team->id] = 2; |
|
458 | + } else { |
|
459 | + $teams[$team->id] += 2; |
|
460 | + } |
|
406 | 461 | } |
407 | 462 | } |
408 | 463 | $g = prev($this->games); |
409 | 464 | if ($g instanceof Game) { |
410 | 465 | foreach ($g->getTeams() as $team) { |
411 | - if (!isset($teams[$team->id])) $teams[$team->id] = 1; |
|
412 | - else $teams[$team->id]++; |
|
466 | + if (!isset($teams[$team->id])) { |
|
467 | + $teams[$team->id] = 1; |
|
468 | + } else { |
|
469 | + $teams[$team->id]++; |
|
470 | + } |
|
413 | 471 | } |
414 | 472 | } |
415 | 473 | |
@@ -431,7 +489,9 @@ discard block |
||
431 | 489 | break; |
432 | 490 | } |
433 | 491 | } |
434 | - if ($found) continue; |
|
492 | + if ($found) { |
|
493 | + continue; |
|
494 | + } |
|
435 | 495 | |
436 | 496 | // CYCLE 2 |
437 | 497 | // ! TEAM WHICH PLAYED IN LAST TWO GAMES (NOT 6 or 7) |
@@ -452,7 +512,9 @@ discard block |
||
452 | 512 | break; |
453 | 513 | } |
454 | 514 | } |
455 | - if ($found) continue; |
|
515 | + if ($found) { |
|
516 | + continue; |
|
517 | + } |
|
456 | 518 | |
457 | 519 | // CYCLE 3 |
458 | 520 | // ! TEAM WHICH PLAYED IN LAST THREE GAMES (NOT 7) |
@@ -483,7 +545,9 @@ discard block |
||
483 | 545 | break; |
484 | 546 | } |
485 | 547 | } |
486 | - if ($found) continue; |
|
548 | + if ($found) { |
|
549 | + continue; |
|
550 | + } |
|
487 | 551 | |
488 | 552 | // CYCLE 4 |
489 | 553 | // ! TEAM WHICH PLAYED IN LAST THREE GAMES (NOT 7) |
@@ -504,7 +568,9 @@ discard block |
||
504 | 568 | break; |
505 | 569 | } |
506 | 570 | } |
507 | - if ($found) continue; |
|
571 | + if ($found) { |
|
572 | + continue; |
|
573 | + } |
|
508 | 574 | |
509 | 575 | // CYCLE 5 |
510 | 576 | // TEAMS THAT DIDN'T PLAY IN LAST GAME WILL PLAY THIS GAME (< 4) |
@@ -529,7 +595,9 @@ discard block |
||
529 | 595 | break; |
530 | 596 | } |
531 | 597 | } |
532 | - if ($found) continue; |
|
598 | + if ($found) { |
|
599 | + continue; |
|
600 | + } |
|
533 | 601 | |
534 | 602 | // CYCLE 6 |
535 | 603 | // FIRST AVAILABLE GAME |
@@ -540,7 +608,9 @@ discard block |
||
540 | 608 | } |
541 | 609 | public function r_rGames(array $teams = []) { |
542 | 610 | $games = []; |
543 | - if (count($teams) === 0) $teams = $this->teams; |
|
611 | + if (count($teams) === 0) { |
|
612 | + $teams = $this->teams; |
|
613 | + } |
|
544 | 614 | switch ($this->inGame) { |
545 | 615 | case 2: |
546 | 616 | $games = circle_genGames2($teams, $this); |
@@ -588,7 +658,9 @@ discard block |
||
588 | 658 | $game->setResults($results); |
589 | 659 | } |
590 | 660 | $return = $this->sortTeams($filters); |
591 | - if (!$reset) return $return; |
|
661 | + if (!$reset) { |
|
662 | + return $return; |
|
663 | + } |
|
592 | 664 | foreach ($this->getGames() as $game) { |
593 | 665 | $game->resetResults(); |
594 | 666 | } |
@@ -596,13 +668,17 @@ discard block |
||
596 | 668 | } |
597 | 669 | public function resetGames() { |
598 | 670 | foreach ($this->getGames() as $game) { |
599 | - if (isset($game)) $game->resetResults(); |
|
671 | + if (isset($game)) { |
|
672 | + $game->resetResults(); |
|
673 | + } |
|
600 | 674 | } |
601 | 675 | return $this; |
602 | 676 | } |
603 | 677 | public function isPlayed(){ |
604 | 678 | foreach ($this->games as $game) { |
605 | - if ((isset($game) || !$this->getSkip()) && !$game->isPlayed()) return false; |
|
679 | + if ((isset($game) || !$this->getSkip()) && !$game->isPlayed()) { |
|
680 | + return false; |
|
681 | + } |
|
606 | 682 | } |
607 | 683 | return true; |
608 | 684 | } |
@@ -29,7 +29,9 @@ discard block |
||
29 | 29 | |
30 | 30 | public function addFilter(...$filters) { |
31 | 31 | foreach ($filters as $filter) { |
32 | - if (!$filter instanceof TeamFilter) throw new \Exception('Trying to add filter which is not an instance of TeamFilter.'); |
|
32 | + if (!$filter instanceof TeamFilter) { |
|
33 | + throw new \Exception('Trying to add filter which is not an instance of TeamFilter.'); |
|
34 | + } |
|
33 | 35 | $this->filters[] = $filter; |
34 | 36 | } |
35 | 37 | return $this; |
@@ -37,8 +39,11 @@ discard block |
||
37 | 39 | |
38 | 40 | public function progress() { |
39 | 41 | $teams = $this->from->sortTeams($this->filters); |
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; |
|
42 | + if (count($this->filters) === 0 || $this->len !== null || $this->start !== 0) { |
|
43 | + $next = array_splice($teams, $this->start, ($this->len === null ? count($teams) : $this->len)); |
|
44 | + } else { |
|
45 | + $next = $teams; |
|
46 | + } |
|
42 | 47 | $this->from->addProgressed($next); |
43 | 48 | $this->to->addTeam($next); |
44 | 49 | return $this; |
@@ -46,8 +51,11 @@ discard block |
||
46 | 51 | |
47 | 52 | public function progressBlank(){ |
48 | 53 | $teams = $this->from->isPlayed() ? $this->from->sortTeams($this->filters) : $this->from->simulate($this->filters); |
49 | - if (count($this->filters) === 0 || $this->len !== null || $this->start !== 0) $next = array_splice($teams, $this->start, ($this->len === null ? count($teams) : $this->len)); |
|
50 | - else $next = $teams; |
|
54 | + if (count($this->filters) === 0 || $this->len !== null || $this->start !== 0) { |
|
55 | + $next = array_splice($teams, $this->start, ($this->len === null ? count($teams) : $this->len)); |
|
56 | + } else { |
|
57 | + $next = $teams; |
|
58 | + } |
|
51 | 59 | $this->from->addProgressed($next); |
52 | 60 | $i = 1; |
53 | 61 | foreach ($next as $team) { |