@@ -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; |