@@ -151,8 +151,7 @@ discard block |
||
| 151 | 151 | $teams = $this->getTeams(true, Constants::SEED); |
| 152 | 152 | if ($this::isSeeded($teams)) { |
| 153 | 153 | Functions::sortAlternate($teams); |
| 154 | - } |
|
| 155 | - else { |
|
| 154 | + } else { |
|
| 156 | 155 | shuffle($teams); |
| 157 | 156 | } |
| 158 | 157 | |
@@ -182,8 +181,7 @@ discard block |
||
| 182 | 181 | $teams = $this->getTeams(true, Constants::SEED); |
| 183 | 182 | if ($this::isSeeded($teams)) { |
| 184 | 183 | Functions::sortAlternate($teams); |
| 185 | - } |
|
| 186 | - else { |
|
| 184 | + } else { |
|
| 187 | 185 | shuffle($teams); |
| 188 | 186 | } |
| 189 | 187 | |
@@ -44,13 +44,13 @@ discard block |
||
| 44 | 44 | $startRound = $this->round('Start round'); |
| 45 | 45 | |
| 46 | 46 | /** Total round count (minus final rounds) */ |
| 47 | - $roundsNum = log($nextPow, 2) * 2; |
|
| 47 | + $roundsNum = log($nextPow, 2)*2; |
|
| 48 | 48 | |
| 49 | 49 | /** How many groups are in the first round */ |
| 50 | - $startGroups = ($countTeams + $byes) / 2; |
|
| 50 | + $startGroups = ($countTeams+$byes)/2; |
|
| 51 | 51 | |
| 52 | 52 | /** How many losing teams there are after the first winning rounds */ |
| 53 | - $losingTeams = (($countTeams - $byes) / 2) + ($extraStart ? $startGroups / 2 : 0); |
|
| 53 | + $losingTeams = (($countTeams-$byes)/2)+($extraStart ? $startGroups/2 : 0); |
|
| 54 | 54 | /** If an extra losing round is generated first */ |
| 55 | 55 | $extraLosingStart = !Functions::isPowerOf2($losingTeams); |
| 56 | 56 | |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | $lastWinningGroup = end($allGroups); |
| 94 | 94 | |
| 95 | 95 | // Create all rounds |
| 96 | - for ($r = $winR; $r <= $roundsNum - 1; $r++) { |
|
| 96 | + for ($r = $winR; $r <= $roundsNum-1; $r++) { |
|
| 97 | 97 | $groups = []; |
| 98 | 98 | $losingGroups = []; |
| 99 | 99 | $winningGroups = []; |
@@ -103,8 +103,8 @@ discard block |
||
| 103 | 103 | $this->generateLosingSide($r, $extraStart, $round, $allGroups, $previousLosingGroups, $previousGroups, $losingGroups); |
| 104 | 104 | |
| 105 | 105 | // Skip some winning rounds - losing side will have more rounds |
| 106 | - $rr = $r - ($extraStart ? 1 : 0) + ($extraLosingStart ? 1 : 0); |
|
| 107 | - if (($rr < 3 || $rr % 2 === 0) && (!$extraStart || count($previousWinningGroups) > 1)) { |
|
| 106 | + $rr = $r-($extraStart ? 1 : 0)+($extraLosingStart ? 1 : 0); |
|
| 107 | + if (($rr < 3 || $rr%2 === 0) && (!$extraStart || count($previousWinningGroups) > 1)) { |
|
| 108 | 108 | // First round after the starting rounds |
| 109 | 109 | if ($extraStart && $r === 3) { |
| 110 | 110 | $previousGroups = $previousWinningGroups; |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | $nextPow = $countTeams; |
| 160 | 160 | if (!Functions::isPowerOf2($countTeams)) { |
| 161 | 161 | $nextPow = Functions::nextPowerOf2($countTeams); |
| 162 | - $byes = $nextPow - $countTeams; |
|
| 162 | + $byes = $nextPow-$countTeams; |
|
| 163 | 163 | } |
| 164 | 164 | return $byes; |
| 165 | 165 | } |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | private function generateWinSide(int $roundNum, int $winRoundNum, int $byes, int $countTeams, Round $round, array &$allGroups, array &$groups, array &$previousWinningGroups = [], array $previousGroups = []) : void { |
| 184 | 184 | $order = 1; |
| 185 | 185 | // All groups |
| 186 | - for ($g = 1; $g <= (($countTeams + $byes) / (2 ** $winRoundNum)); $g++) { |
|
| 186 | + for ($g = 1; $g <= (($countTeams+$byes)/(2 ** $winRoundNum)); $g++) { |
|
| 187 | 187 | $group = $round |
| 188 | 188 | ->group('Round '.$roundNum.' (win '.$g.')') |
| 189 | 189 | ->setInGame(2) |
@@ -197,8 +197,8 @@ discard block |
||
| 197 | 197 | $previousWinningGroups[] = $group; |
| 198 | 198 | |
| 199 | 199 | // Progress from winning groups before |
| 200 | - $previousGroups[2 * ($g - 1)]->progression($group, 0, 1); |
|
| 201 | - $previousGroups[(2 * ($g - 1)) + 1]->progression($group, 0, 1); |
|
| 200 | + $previousGroups[2*($g-1)]->progression($group, 0, 1); |
|
| 201 | + $previousGroups[(2*($g-1))+1]->progression($group, 0, 1); |
|
| 202 | 202 | } |
| 203 | 203 | } |
| 204 | 204 | |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | // Save counts |
| 230 | 230 | $losingCount = count($previousLosingGroups); |
| 231 | 231 | $winningCount = count($previousWinningGroups); |
| 232 | - $teamsTotal = $losingCount + $winningCount; |
|
| 232 | + $teamsTotal = $losingCount+$winningCount; |
|
| 233 | 233 | |
| 234 | 234 | // Merge all groups in an alternating order for progressions |
| 235 | 235 | /** @var array[] $progressGroups 0: Group, 1: int - progression offset */ |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | $order = 2; |
| 249 | 249 | // Check byes |
| 250 | 250 | if (Functions::isPowerOf2($teamsTotal)) { |
| 251 | - for ($g = 1; $g <= $teamsTotal / 2; $g++) { |
|
| 251 | + for ($g = 1; $g <= $teamsTotal/2; $g++) { |
|
| 252 | 252 | $group = $round |
| 253 | 253 | ->group('Round '.$roundNum.' (loss '.$g.')') |
| 254 | 254 | ->setInGame(2) |
@@ -261,11 +261,11 @@ discard block |
||
| 261 | 261 | // First losing round |
| 262 | 262 | // Progress from winning teams only |
| 263 | 263 | if (($roundNum === 2 && !$extraStart) || ($roundNum === 3 && $extraStart)) { |
| 264 | - $previousWinningGroups[2 * ($g - 1)]->progression($group, 1, 1); |
|
| 265 | - $previousWinningGroups[(2 * ($g - 1)) + 1]->progression($group, 1, 1); |
|
| 264 | + $previousWinningGroups[2*($g-1)]->progression($group, 1, 1); |
|
| 265 | + $previousWinningGroups[(2*($g-1))+1]->progression($group, 1, 1); |
|
| 266 | 266 | } |
| 267 | 267 | elseif ($teamsTotal >= 2) { |
| 268 | - $key = 2 * ($g - 1); |
|
| 268 | + $key = 2*($g-1); |
|
| 269 | 269 | $progressGroups[$key][0]->progression($group, $progressGroups[$key][1], 1); |
| 270 | 270 | $key++; |
| 271 | 271 | $progressGroups[$key][0]->progression($group, $progressGroups[$key][1], 1); |
@@ -275,14 +275,14 @@ discard block |
||
| 275 | 275 | else { |
| 276 | 276 | // Calculate byes |
| 277 | 277 | $nextPowerOf2 = Functions::nextPowerOf2($teamsTotal); |
| 278 | - $losingByes = $nextPowerOf2 - $teamsTotal; |
|
| 278 | + $losingByes = $nextPowerOf2-$teamsTotal; |
|
| 279 | 279 | |
| 280 | 280 | // Counters |
| 281 | 281 | $byesProgressed = 0; |
| 282 | 282 | $teamCounter = 0; |
| 283 | 283 | |
| 284 | 284 | // Generate groups |
| 285 | - $groupCount = $nextPowerOf2 / 2; |
|
| 285 | + $groupCount = $nextPowerOf2/2; |
|
| 286 | 286 | for ($g = 1; $g <= $groupCount; $g++) { |
| 287 | 287 | $group = $round |
| 288 | 288 | ->group('Round '.$roundNum.' (loss '.$g.')') |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | // Create progressions from groups before |
| 297 | 297 | $teamCounter++; |
| 298 | 298 | $progressGroups[$byesProgressed][0]->progression($group, $progressGroups[$byesProgressed++][1], 1); |
| 299 | - if (isset($progressGroups[$byesProgressed]) && $teamCounter < $teamsTotal - $losingByes) { |
|
| 299 | + if (isset($progressGroups[$byesProgressed]) && $teamCounter < $teamsTotal-$losingByes) { |
|
| 300 | 300 | $teamCounter++; |
| 301 | 301 | $progressGroups[$byesProgressed][0]->progression($group, $progressGroups[$byesProgressed++][1], 1); |
| 302 | 302 | } |
@@ -313,7 +313,7 @@ discard block |
||
| 313 | 313 | foreach ($this->getRounds() as $round) { |
| 314 | 314 | $name = $round->getName(); |
| 315 | 315 | $len = strlen($name); |
| 316 | - $str .= "\n| ---------------------------------------- |\n| ".str_repeat('-', floor((40 - $len) / 2) - 1).' '.$name.' '.str_repeat('-', ceil((40 - $len) / 2) - 1)." |\n| ---------------------------------------- |\n\n"; |
|
| 316 | + $str .= "\n| ---------------------------------------- |\n| ".str_repeat('-', floor((40-$len)/2)-1).' '.$name.' '.str_repeat('-', ceil((40-$len)/2)-1)." |\n| ---------------------------------------- |\n\n"; |
|
| 317 | 317 | foreach ($round->getGroups() as $group) { |
| 318 | 318 | $str .= '-- '.$group->getName().PHP_EOL; |
| 319 | 319 | if (count($group->getGames()) === 0) { |
@@ -263,16 +263,14 @@ discard block |
||
| 263 | 263 | if (($roundNum === 2 && !$extraStart) || ($roundNum === 3 && $extraStart)) { |
| 264 | 264 | $previousWinningGroups[2 * ($g - 1)]->progression($group, 1, 1); |
| 265 | 265 | $previousWinningGroups[(2 * ($g - 1)) + 1]->progression($group, 1, 1); |
| 266 | - } |
|
| 267 | - elseif ($teamsTotal >= 2) { |
|
| 266 | + } elseif ($teamsTotal >= 2) { |
|
| 268 | 267 | $key = 2 * ($g - 1); |
| 269 | 268 | $progressGroups[$key][0]->progression($group, $progressGroups[$key][1], 1); |
| 270 | 269 | $key++; |
| 271 | 270 | $progressGroups[$key][0]->progression($group, $progressGroups[$key][1], 1); |
| 272 | 271 | } |
| 273 | 272 | } |
| 274 | - } |
|
| 275 | - else { |
|
| 273 | + } else { |
|
| 276 | 274 | // Calculate byes |
| 277 | 275 | $nextPowerOf2 = Functions::nextPowerOf2($teamsTotal); |
| 278 | 276 | $losingByes = $nextPowerOf2 - $teamsTotal; |
@@ -320,8 +318,7 @@ discard block |
||
| 320 | 318 | $str .= '| '.implode(' | ', array_map(static function(Team $team) { |
| 321 | 319 | return $team->getName(); |
| 322 | 320 | }, $group->getTeams())).' |'.PHP_EOL; |
| 323 | - } |
|
| 324 | - else { |
|
| 321 | + } else { |
|
| 325 | 322 | foreach ($group->getGames() as $game) { |
| 326 | 323 | $str .= '| '.implode(' | ', array_map(static function(Team $team) use ($game) { |
| 327 | 324 | return ($team->getId() === $game->getWin() ? "\e[1m\e[4m" : '').$team->getName()."\e[0m"; |
@@ -61,8 +61,7 @@ discard block |
||
| 61 | 61 | $teams = $this->getTeams(true, Constants::SEED); |
| 62 | 62 | if ($this::isSeeded($teams)) { |
| 63 | 63 | Functions::sortAlternate($teams); |
| 64 | - } |
|
| 65 | - else { |
|
| 64 | + } else { |
|
| 66 | 65 | shuffle($teams); |
| 67 | 66 | } |
| 68 | 67 | |
@@ -95,8 +94,7 @@ discard block |
||
| 95 | 94 | $teams = $this->getTeams(true, Constants::SEED); |
| 96 | 95 | if ($this::isSeeded($teams)) { |
| 97 | 96 | Functions::sortAlternate($teams); |
| 98 | - } |
|
| 99 | - else { |
|
| 97 | + } else { |
|
| 100 | 98 | shuffle($teams); |
| 101 | 99 | } |
| 102 | 100 | |
@@ -129,8 +127,7 @@ discard block |
||
| 129 | 127 | } |
| 130 | 128 | if ($ordered) { |
| 131 | 129 | $returnTeams = $this->sortTeams($ordering); |
| 132 | - } |
|
| 133 | - else { |
|
| 130 | + } else { |
|
| 134 | 131 | $returnTeams = $this->teams->unique()->get(); |
| 135 | 132 | } |
| 136 | 133 | |
@@ -180,8 +177,7 @@ discard block |
||
| 180 | 177 | if ($this instanceof WithGroupsInterface) { |
| 181 | 178 | $filter = new Filter($filters, $this->getGroups()); |
| 182 | 179 | $filter->filter($teams); |
| 183 | - } |
|
| 184 | - else if ($this instanceof Group) { |
|
| 180 | + } else if ($this instanceof Group) { |
|
| 185 | 181 | $filter = new Filter($filters, [$this]); |
| 186 | 182 | $filter->filter($teams); |
| 187 | 183 | } |