@@ -18,7 +18,9 @@ discard block |
||
| 18 | 18 | $game->setResults($results); |
| 19 | 19 | } |
| 20 | 20 | $return = $group->sortTeams($filters); |
| 21 | - if (!$reset) return $return; |
|
| 21 | + if (!$reset) { |
|
| 22 | + return $return; |
|
| 23 | + } |
|
| 22 | 24 | foreach ($group->getGames() as $game) { |
| 23 | 25 | $game->resetResults(); |
| 24 | 26 | } |
@@ -27,14 +29,18 @@ discard block |
||
| 27 | 29 | |
| 28 | 30 | public static function simulateRound(\TournamentGenerator\Round $round) { |
| 29 | 31 | foreach ($round->getGroups() as $group) { |
| 30 | - if ($group->isPlayed()) continue; |
|
| 32 | + if ($group->isPlayed()) { |
|
| 33 | + continue; |
|
| 34 | + } |
|
| 31 | 35 | $group->simulate([], false); |
| 32 | 36 | } |
| 33 | 37 | return true; |
| 34 | 38 | } |
| 35 | 39 | |
| 36 | 40 | public static function simulateTournament(\TournamentGenerator\Tournament $tournament) { |
| 37 | - if (count($tournament->getCategories()) === 0 && count($tournament->getRounds()) === 0) throw new \Exception('There are no rounds or categories to simulate games from.'); |
|
| 41 | + if (count($tournament->getCategories()) === 0 && count($tournament->getRounds()) === 0) { |
|
| 42 | + throw new \Exception('There are no rounds or categories to simulate games from.'); |
|
| 43 | + } |
|
| 38 | 44 | |
| 39 | 45 | $games = []; |
| 40 | 46 | |
@@ -55,7 +61,9 @@ discard block |
||
| 55 | 61 | |
| 56 | 62 | public static function simulateTournamentReal(\TournamentGenerator\Tournament $tournament) { |
| 57 | 63 | $games = []; |
| 58 | - if (count($tournament->getCategories()) === 0 && count($tournament->getRounds()) === 0) throw new \Exception('There are no rounds or categories to simulate games from.'); |
|
| 64 | + if (count($tournament->getCategories()) === 0 && count($tournament->getRounds()) === 0) { |
|
| 65 | + throw new \Exception('There are no rounds or categories to simulate games from.'); |
|
| 66 | + } |
|
| 59 | 67 | |
| 60 | 68 | foreach ($tournament->getCategories() as $category) { |
| 61 | 69 | $games = array_merge($games, $category->genGamesSimulate()); |
@@ -36,7 +36,9 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | $games = $this->group->getGames(); |
| 38 | 38 | |
| 39 | - if (count($games) <= 4) return $games; |
|
| 39 | + if (count($games) <= 4) { |
|
| 40 | + return $games; |
|
| 41 | + } |
|
| 40 | 42 | |
| 41 | 43 | $this->games = []; |
| 42 | 44 | |
@@ -48,24 +50,34 @@ discard block |
||
| 48 | 50 | while (count($games) > 0) { |
| 49 | 51 | // CYCLE 1 |
| 50 | 52 | // TEAM WHICH DIDN'T PLAY IN LAST GAME (< 4) |
| 51 | - if ($this->cycle1($games, $teams)) continue; |
|
| 53 | + if ($this->cycle1($games, $teams)) { |
|
| 54 | + continue; |
|
| 55 | + } |
|
| 52 | 56 | |
| 53 | 57 | // CYCLE 2 |
| 54 | 58 | // NOT TEAM WHICH PLAYED IN LAST TWO GAMES (NOT 6 or 7) |
| 55 | - if ($this->cycle2($games, $teams)) continue; |
|
| 59 | + if ($this->cycle2($games, $teams)) { |
|
| 60 | + continue; |
|
| 61 | + } |
|
| 56 | 62 | |
| 57 | 63 | // CYCLE 3 |
| 58 | 64 | // NOT TEAM WHICH PLAYED IN LAST THREE GAMES (NOT 7) |
| 59 | 65 | // TEAMS THAT DIDN'T PLAY IN LAST GAME WILL PLAY THIS GAME (< 4) |
| 60 | - if ($this->cycle3($games, $teams)) continue; |
|
| 66 | + if ($this->cycle3($games, $teams)) { |
|
| 67 | + continue; |
|
| 68 | + } |
|
| 61 | 69 | |
| 62 | 70 | // CYCLE 4 |
| 63 | 71 | // NOT TEAM WHICH PLAYED IN LAST THREE GAMES (NOT 7) |
| 64 | - if ($this->cycle4($games, $teams)) continue; |
|
| 72 | + if ($this->cycle4($games, $teams)) { |
|
| 73 | + continue; |
|
| 74 | + } |
|
| 65 | 75 | |
| 66 | 76 | // CYCLE 5 |
| 67 | 77 | // TEAMS THAT DIDN'T PLAY IN LAST GAME WILL PLAY THIS GAME (< 4) |
| 68 | - if ($this->cycle5($games, $teams)) continue; |
|
| 78 | + if ($this->cycle5($games, $teams)) { |
|
| 79 | + continue; |
|
| 80 | + } |
|
| 69 | 81 | |
| 70 | 82 | // CYCLE 6 |
| 71 | 83 | // FIRST AVAILABLE GAME |
@@ -174,11 +186,17 @@ discard block |
||
| 174 | 186 | $requiredTeams = array_filter($teams, function($a) use ($required) { return in_array($a, $required); }); |
| 175 | 187 | |
| 176 | 188 | foreach ($game->getTeamsIds() as $tid) { |
| 177 | - if (in_array($teams[$tid], $checkVals)) return false; |
|
| 178 | - if (isset($requiredTeams[$tid])) unset($requiredTeams[$tid]); |
|
| 189 | + if (in_array($teams[$tid], $checkVals)) { |
|
| 190 | + return false; |
|
| 191 | + } |
|
| 192 | + if (isset($requiredTeams[$tid])) { |
|
| 193 | + unset($requiredTeams[$tid]); |
|
| 194 | + } |
|
| 179 | 195 | } |
| 180 | 196 | |
| 181 | - if (count($requiredTeams) > 0) return false; |
|
| 197 | + if (count($requiredTeams) > 0) { |
|
| 198 | + return false; |
|
| 199 | + } |
|
| 182 | 200 | |
| 183 | 201 | return true; |
| 184 | 202 | |
@@ -36,8 +36,11 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | |
| 38 | 38 | public function setType(/** @scrutinizer ignore-all */ string $type = \TournamentGenerator\Constants::ROUND_ROBIN) { |
| 39 | - if (in_array($type, \TournamentGenerator\Constants::GroupTypes)) $this->type = $type; |
|
| 40 | - else throw new \Exception('Unknown group type: '.$type); |
|
| 39 | + if (in_array($type, \TournamentGenerator\Constants::GroupTypes)) { |
|
| 40 | + $this->type = $type; |
|
| 41 | + } else { |
|
| 42 | + throw new \Exception('Unknown group type: '.$type); |
|
| 43 | + } |
|
| 41 | 44 | return $this; |
| 42 | 45 | } |
| 43 | 46 | public function getType() { |
@@ -45,7 +48,9 @@ discard block |
||
| 45 | 48 | } |
| 46 | 49 | |
| 47 | 50 | public function setInGame(int $inGame) { |
| 48 | - if ($inGame < 2 || $inGame > 4) throw new \Exception('Expected 2,3 or 4 as inGame '.$inGame.' given'); |
|
| 51 | + if ($inGame < 2 || $inGame > 4) { |
|
| 52 | + throw new \Exception('Expected 2,3 or 4 as inGame '.$inGame.' given'); |
|
| 53 | + } |
|
| 49 | 54 | $this->inGame = $inGame; |
| 50 | 55 | return $this; |
| 51 | 56 | } |
@@ -54,7 +59,9 @@ discard block |
||
| 54 | 59 | } |
| 55 | 60 | |
| 56 | 61 | public function setMaxSize(int $maxSize) { |
| 57 | - if ($maxSize < 2) throw new \Exception('Max group size has to be at least 2, '.$maxSize.' given'); |
|
| 62 | + if ($maxSize < 2) { |
|
| 63 | + throw new \Exception('Max group size has to be at least 2, '.$maxSize.' given'); |
|
| 64 | + } |
|
| 58 | 65 | $this->maxSize = $maxSize; |
| 59 | 66 | return $this; |
| 60 | 67 | } |
@@ -78,7 +85,9 @@ discard block |
||
| 78 | 85 | } |
| 79 | 86 | private function r_rGames(array $teams = []) { |
| 80 | 87 | $games = []; |
| 81 | - if (count($teams) === 0) $teams = $this->group->getTeams(); |
|
| 88 | + if (count($teams) === 0) { |
|
| 89 | + $teams = $this->group->getTeams(); |
|
| 90 | + } |
|
| 82 | 91 | switch ($this->inGame) { |
| 83 | 92 | case 2: |
| 84 | 93 | $games = Generator::circle_genGames2($teams, $this->group); |
@@ -98,7 +107,9 @@ discard block |
||
| 98 | 107 | $lockedTeam = array_shift($teamsB); |
| 99 | 108 | $gamesTemp = Generator::circle_genGames2($teamsB, $this->group); |
| 100 | 109 | foreach ($gamesTemp as $game) { |
| 101 | - if (isset($lockedTeam1)) $game->addTeam($lockedTeam1); |
|
| 110 | + if (isset($lockedTeam1)) { |
|
| 111 | + $game->addTeam($lockedTeam1); |
|
| 112 | + } |
|
| 102 | 113 | $game->addTeam($lockedTeam); |
| 103 | 114 | } |
| 104 | 115 | $games = array_merge($games, $gamesTemp); |
@@ -116,7 +127,9 @@ discard block |
||
| 116 | 127 | return $games; |
| 117 | 128 | } |
| 118 | 129 | private function two_twoGames(array $teams = []) { |
| 119 | - if (count($teams) === 0) $teams = $this->group->getTeams(); |
|
| 130 | + if (count($teams) === 0) { |
|
| 131 | + $teams = $this->group->getTeams(); |
|
| 132 | + } |
|
| 120 | 133 | $discard = []; |
| 121 | 134 | shuffle($teams); |
| 122 | 135 | $count = count($teams); |
@@ -128,13 +141,17 @@ discard block |
||
| 128 | 141 | $this->group->game($tInGame); |
| 129 | 142 | } |
| 130 | 143 | |
| 131 | - if (count($discard) > 0 && !$this->allowSkip) throw new \Exception('Couldn\'t make games with all teams. Expected k*'.$this->inGame.' teams '.$count.' teams given - discarting '.count($discard).' teams ('.implode(', ', $discard).') in group '.$this->group.' - allow skip '.($this->allowSkip ? 'True' : 'False')); |
|
| 144 | + if (count($discard) > 0 && !$this->allowSkip) { |
|
| 145 | + throw new \Exception('Couldn\'t make games with all teams. Expected k*'.$this->inGame.' teams '.$count.' teams given - discarting '.count($discard).' teams ('.implode(', ', $discard).') in group '.$this->group.' - allow skip '.($this->allowSkip ? 'True' : 'False')); |
|
| 146 | + } |
|
| 132 | 147 | |
| 133 | 148 | return $this; |
| 134 | 149 | } |
| 135 | 150 | private function cond_splitGames(array $teams = []) { |
| 136 | 151 | $games = []; |
| 137 | - if (count($teams) === 0) $teams = $this->group->getTeams(); |
|
| 152 | + if (count($teams) === 0) { |
|
| 153 | + $teams = $this->group->getTeams(); |
|
| 154 | + } |
|
| 138 | 155 | |
| 139 | 156 | if (count($teams) > $this->maxSize) { |
| 140 | 157 | $groups = array_chunk($teams, /** @scrutinizer ignore-type */ ceil(count($teams)/ceil(count($teams)/$this->maxSize))); // SPLIT TEAMS INTO GROUP OF MAXIMUM SIZE OF $this->maxSize |
@@ -144,7 +161,9 @@ discard block |
||
| 144 | 161 | while ($g > 0) { |
| 145 | 162 | foreach ($games as $key => $group) { |
| 146 | 163 | $this->group->addGame(array_shift($games[$key])); |
| 147 | - if (count($games[$key]) === 0) unset($games[$key]); |
|
| 164 | + if (count($games[$key]) === 0) { |
|
| 165 | + unset($games[$key]); |
|
| 166 | + } |
|
| 148 | 167 | $g--; |
| 149 | 168 | } |
| 150 | 169 | } |
@@ -165,7 +184,10 @@ discard block |
||
| 165 | 184 | public static function circle_genGames2(array $teams = [], \tournamentGenerator\Group $group) { |
| 166 | 185 | $bracket = []; // ARRAY OF GAMES |
| 167 | 186 | |
| 168 | - if (count($teams) % 2 != 0) $teams[] = \TournamentGenerator\Constants::DUMMY_TEAM; // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY |
|
| 187 | + if (count($teams) % 2 != 0) { |
|
| 188 | + $teams[] = \TournamentGenerator\Constants::DUMMY_TEAM; |
|
| 189 | + } |
|
| 190 | + // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY |
|
| 169 | 191 | |
| 170 | 192 | shuffle($teams); // SHUFFLE TEAMS FOR MORE RANDOMNESS |
| 171 | 193 | |
@@ -189,7 +211,10 @@ discard block |
||
| 189 | 211 | $reverse = array_reverse($teams); |
| 190 | 212 | $away = $reverse[$i]; |
| 191 | 213 | |
| 192 | - if (($home == \TournamentGenerator\Constants::DUMMY_TEAM || $away == \TournamentGenerator\Constants::DUMMY_TEAM)) continue; // SKIP WHEN DUMMY_TEAM IS PRESENT |
|
| 214 | + if (($home == \TournamentGenerator\Constants::DUMMY_TEAM || $away == \TournamentGenerator\Constants::DUMMY_TEAM)) { |
|
| 215 | + continue; |
|
| 216 | + } |
|
| 217 | + // SKIP WHEN DUMMY_TEAM IS PRESENT |
|
| 193 | 218 | |
| 194 | 219 | $bracket[] = new \TournamentGenerator\Game([$home, $away], $group); |
| 195 | 220 | |
@@ -33,11 +33,17 @@ discard block |
||
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | public function progress(bool $blank = false) { |
| 36 | - if ($blank) $teams = $this->from->isPlayed() ? $this->from->sortTeams($this->filters) : $this->from->simulate($this->filters); |
|
| 37 | - else $teams = $this->from->sortTeams($this->filters); |
|
| 36 | + if ($blank) { |
|
| 37 | + $teams = $this->from->isPlayed() ? $this->from->sortTeams($this->filters) : $this->from->simulate($this->filters); |
|
| 38 | + } else { |
|
| 39 | + $teams = $this->from->sortTeams($this->filters); |
|
| 40 | + } |
|
| 38 | 41 | |
| 39 | - if (count($this->filters) === 0 || $this->len !== null || $this->start !== 0) $next = array_splice($teams, $this->start, ($this->len === null ? count($teams) : $this->len)); |
|
| 40 | - 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 | + } |
|
| 41 | 47 | |
| 42 | 48 | $i = 1; |
| 43 | 49 | |
@@ -45,12 +51,15 @@ discard block |
||
| 45 | 51 | if ($blank) { |
| 46 | 52 | $this->to->addTeam(new BlankTeam($this.' - '.$i, $team)); |
| 47 | 53 | $i++; |
| 54 | + } else { |
|
| 55 | + $team->sumPoints += $this->from->progressPoints; |
|
| 48 | 56 | } |
| 49 | - else $team->sumPoints += $this->from->progressPoints; |
|
| 50 | 57 | } |
| 51 | 58 | |
| 52 | 59 | $this->from->addProgressed($next); |
| 53 | - if (!$blank) $this->to->addTeam($next); |
|
| 60 | + if (!$blank) { |
|
| 61 | + $this->to->addTeam($next); |
|
| 62 | + } |
|
| 54 | 63 | return $this; |
| 55 | 64 | } |
| 56 | 65 | |
@@ -21,8 +21,11 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | public function addRound(Round ...$rounds){ |
| 23 | 23 | foreach ($rounds as $round) { |
| 24 | - if ($round instanceof Round) $this->rounds[] = $round; |
|
| 25 | - else throw new \Exception('Trying to add round which is not an instance of Round class.'); |
|
| 24 | + if ($round instanceof Round) { |
|
| 25 | + $this->rounds[] = $round; |
|
| 26 | + } else { |
|
| 27 | + throw new \Exception('Trying to add round which is not an instance of Round class.'); |
|
| 28 | + } |
|
| 26 | 29 | } |
| 27 | 30 | return $this; |
| 28 | 31 | } |
@@ -63,7 +66,9 @@ discard block |
||
| 63 | 66 | return $t; |
| 64 | 67 | } |
| 65 | 68 | public function getTeams() { |
| 66 | - if (count($this->teams) > 0) return $this->teams; |
|
| 69 | + if (count($this->teams) > 0) { |
|
| 70 | + return $this->teams; |
|
| 71 | + } |
|
| 67 | 72 | $teams = []; |
| 68 | 73 | foreach ($this->rounds as $round) { |
| 69 | 74 | $teams = array_merge($teams, $round->getTeams()); |
@@ -82,7 +87,9 @@ discard block |
||
| 82 | 87 | |
| 83 | 88 | public function splitTeams(...$rounds) { |
| 84 | 89 | |
| 85 | - if (count($rounds) === 0) $rounds = $this->getRounds(); |
|
| 90 | + if (count($rounds) === 0) { |
|
| 91 | + $rounds = $this->getRounds(); |
|
| 92 | + } |
|
| 86 | 93 | |
| 87 | 94 | $teams = $this->getTeams(); |
| 88 | 95 | shuffle($teams); |
@@ -102,7 +109,9 @@ discard block |
||
| 102 | 109 | |
| 103 | 110 | public function genGamesSimulate() { |
| 104 | 111 | $games = []; |
| 105 | - if (count($this->rounds) <= 0) throw new \Exception('There are no rounds to simulate games from.'); |
|
| 112 | + if (count($this->rounds) <= 0) { |
|
| 113 | + throw new \Exception('There are no rounds to simulate games from.'); |
|
| 114 | + } |
|
| 106 | 115 | foreach ($this->rounds as $round) { |
| 107 | 116 | $games = array_merge($games, $round->genGames()); |
| 108 | 117 | $round->simulate()->progress(true)->resetGames(); |
@@ -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'); |
@@ -13,7 +13,9 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | $countTeams = count($this->getTeams()); |
| 15 | 15 | |
| 16 | - if ($countTeams < 3) throw new \Exception('Double elimination is possible for minimum of 3 teams - '.$countTeams.' teams given.'); |
|
| 16 | + if ($countTeams < 3) { |
|
| 17 | + throw new \Exception('Double elimination is possible for minimum of 3 teams - '.$countTeams.' teams given.'); |
|
| 18 | + } |
|
| 17 | 19 | |
| 18 | 20 | |
| 19 | 21 | // CALCULATE BYES |
@@ -131,15 +133,19 @@ discard block |
||
| 131 | 133 | if ($r === 2) { // FIRST LOSING ROUND |
| 132 | 134 | $previousGroups[2*($g-1)]->progression($group, 1, 1); // PROGRESS FROM STARTING GROUP |
| 133 | 135 | $previousGroups[(2*($g-1))+1]->progression($group, 1, 1); // PROGREESS FROM STARTING GROUP |
| 134 | - } |
|
| 135 | - elseif ($losingGroupTeamsCount >= 2) { |
|
| 136 | + } elseif ($losingGroupTeamsCount >= 2) { |
|
| 136 | 137 | $previousLosingGroups[$g-1]->progression($group, 0, 1); // PROGRESS FROM LOSING GROUP BEFORE |
| 137 | - if (isset(array_reverse($previousGroups)[$g-1])) array_reverse($previousGroups)[$g-1]->progression($group, 1, 1); // PROGREESS FROM WINNING GROUP BEFORE |
|
| 138 | - else $previousLosingGroups[$g]->progression($group, 0, 1); // PROGRESS OTHER TEAM FROM LOSING GROUP BEEFORE |
|
| 138 | + if (isset(array_reverse($previousGroups)[$g-1])) { |
|
| 139 | + array_reverse($previousGroups)[$g-1]->progression($group, 1, 1); |
|
| 140 | + } |
|
| 141 | + // PROGREESS FROM WINNING GROUP BEFORE |
|
| 142 | + else { |
|
| 143 | + $previousLosingGroups[$g]->progression($group, 0, 1); |
|
| 144 | + } |
|
| 145 | + // PROGRESS OTHER TEAM FROM LOSING GROUP BEEFORE |
|
| 139 | 146 | } |
| 140 | 147 | } |
| 141 | - } |
|
| 142 | - else { // IF THE NUMBER OF TEAMS IS NOT A POWER OF 2, GENERATE GROUPS WITH BYES |
|
| 148 | + } else { // IF THE NUMBER OF TEAMS IS NOT A POWER OF 2, GENERATE GROUPS WITH BYES |
|
| 143 | 149 | // LOOK FOR THE CLOSEST LOWER POWER OF 2 |
| 144 | 150 | $losingByes = $losingGroupTeamsCount-bindec(str_pad(1, strlen(decbin($losingGroupTeamsCount)), 0, STR_PAD_RIGHT)); |
| 145 | 151 | $n = (floor(count($previousLosingGroups)/2)+$losingByes); |
@@ -163,10 +169,12 @@ discard block |
||
| 163 | 169 | if (in_array($g, $byesGroupsNums) && isset($previousGroups[$byesProgressed])) { // EMPTY GROUP FROM BYE |
| 164 | 170 | $previousGroups[$byesProgressed]->progression($group, 1, 1); // PROGRESS FROM WINNING GROUP BEFORE |
| 165 | 171 | $byesProgressed++; |
| 166 | - } |
|
| 167 | - else { |
|
| 172 | + } else { |
|
| 168 | 173 | $previousLosingGroups[$lastGroup]->progression($group, 0, 1); // PROGRESS FROM LOSING GROUP BEFORE |
| 169 | - if (isset($previousLosingGroups[$lastGroup + 1])) $previousLosingGroups[$lastGroup + 1]->progression($group, 0, 1); // PROGREESS FROM LOSING GROUP BEFORE |
|
| 174 | + if (isset($previousLosingGroups[$lastGroup + 1])) { |
|
| 175 | + $previousLosingGroups[$lastGroup + 1]->progression($group, 0, 1); |
|
| 176 | + } |
|
| 177 | + // PROGREESS FROM LOSING GROUP BEFORE |
|
| 170 | 178 | $lastGroup += 2; |
| 171 | 179 | } |
| 172 | 180 | } |
@@ -32,7 +32,9 @@ discard block |
||
| 32 | 32 | * @return array Sorted array of teams |
| 33 | 33 | */ |
| 34 | 34 | public static function sortGroup(array &$teams, \TournamentGenerator\Group $group, string $ordering = \TournamentGenerator\Constants::POINTS) { |
| 35 | - if (!in_array($ordering, \TournamentGenerator\Constants::OrderingTypes)) throw new \Exception('Unknown ordering type `'.$ordering.'`'); |
|
| 35 | + if (!in_array($ordering, \TournamentGenerator\Constants::OrderingTypes)) { |
|
| 36 | + throw new \Exception('Unknown ordering type `'.$ordering.'`'); |
|
| 37 | + } |
|
| 36 | 38 | |
| 37 | 39 | self::$ids = [$group->getId()]; |
| 38 | 40 | |
@@ -58,7 +60,9 @@ discard block |
||
| 58 | 60 | * @return array Sorted array of teams |
| 59 | 61 | */ |
| 60 | 62 | public static function sortRound(array &$teams, \TournamentGenerator\Round $round, string $ordering = \TournamentGenerator\Constants::POINTS) { |
| 61 | - if (!in_array($ordering, \TournamentGenerator\Constants::OrderingTypes)) throw new \Exception('Unknown ordering type `'.$ordering.'`'); |
|
| 63 | + if (!in_array($ordering, \TournamentGenerator\Constants::OrderingTypes)) { |
|
| 64 | + throw new \Exception('Unknown ordering type `'.$ordering.'`'); |
|
| 65 | + } |
|
| 62 | 66 | |
| 63 | 67 | self::$ids = $round->getGroupsIds(); |
| 64 | 68 | |
@@ -79,8 +83,12 @@ discard block |
||
| 79 | 83 | */ |
| 80 | 84 | private static function sortTeamsByPoints($a, $b) { |
| 81 | 85 | $groupsIds = self::$ids; |
| 82 | - if ($a->sumPoints($groupsIds) === $b->sumPoints($groupsIds) && $a->sumScore($groupsIds) === $b->sumScore($groupsIds)) return 0; |
|
| 83 | - if ($a->sumPoints($groupsIds) === $b->sumPoints($groupsIds)) return ($a->sumScore($groupsIds) > $b->sumScore($groupsIds) ? -1 : 1); |
|
| 86 | + if ($a->sumPoints($groupsIds) === $b->sumPoints($groupsIds) && $a->sumScore($groupsIds) === $b->sumScore($groupsIds)) { |
|
| 87 | + return 0; |
|
| 88 | + } |
|
| 89 | + if ($a->sumPoints($groupsIds) === $b->sumPoints($groupsIds)) { |
|
| 90 | + return ($a->sumScore($groupsIds) > $b->sumScore($groupsIds) ? -1 : 1); |
|
| 91 | + } |
|
| 84 | 92 | return ($a->sumPoints($groupsIds) > $b->sumPoints($groupsIds) ? -1 : 1); |
| 85 | 93 | } |
| 86 | 94 | /** |
@@ -88,7 +96,9 @@ discard block |
||
| 88 | 96 | */ |
| 89 | 97 | private static function sortTeamsByScore($a, $b) { |
| 90 | 98 | $groupsIds = self::$ids; |
| 91 | - if ($a->sumScore($groupsIds) === $b->sumScore($groupsIds)) return 0; |
|
| 99 | + if ($a->sumScore($groupsIds) === $b->sumScore($groupsIds)) { |
|
| 100 | + return 0; |
|
| 101 | + } |
|
| 92 | 102 | return ($a->sumScore($groupsIds) > $b->sumScore($groupsIds) ? -1 : 1); |
| 93 | 103 | } |
| 94 | 104 | |
@@ -93,9 +93,13 @@ discard block |
||
| 93 | 93 | return $this->games; |
| 94 | 94 | } |
| 95 | 95 | public function isPlayed(){ |
| 96 | - if (count($this->games) === 0) return false; |
|
| 96 | + if (count($this->games) === 0) { |
|
| 97 | + return false; |
|
| 98 | + } |
|
| 97 | 99 | foreach ($this->groups as $group) { |
| 98 | - if (!$group->isPlayed()) return false; |
|
| 100 | + if (!$group->isPlayed()) { |
|
| 101 | + return false; |
|
| 102 | + } |
|
| 99 | 103 | } |
| 100 | 104 | return true; |
| 101 | 105 | } |
@@ -131,14 +135,18 @@ discard block |
||
| 131 | 135 | |
| 132 | 136 | public function splitTeams(Group ...$groups) { |
| 133 | 137 | |
| 134 | - if (count($groups) === 0) $groups = $this->getGroups(); |
|
| 138 | + if (count($groups) === 0) { |
|
| 139 | + $groups = $this->getGroups(); |
|
| 140 | + } |
|
| 135 | 141 | |
| 136 | 142 | $teams = $this->getTeams(); |
| 137 | 143 | shuffle($teams); |
| 138 | 144 | |
| 139 | 145 | while (count($teams) > 0) { |
| 140 | 146 | foreach ($groups as $group) { |
| 141 | - if (count($teams) > 0) $group->addTeam(array_shift($teams)); |
|
| 147 | + if (count($teams) > 0) { |
|
| 148 | + $group->addTeam(array_shift($teams)); |
|
| 149 | + } |
|
| 142 | 150 | } |
| 143 | 151 | } |
| 144 | 152 | return $this; |