@@ -118,8 +118,7 @@ |
||
118 | 118 | // Check tournament type (can be a preset) |
119 | 119 | if (empty($setting['type']) || $setting['type'] === 'general') { |
120 | 120 | $tournament = new Tournament(); |
121 | - } |
|
122 | - else { |
|
121 | + } else { |
|
123 | 122 | $tournament = new $setting['type']; |
124 | 123 | } |
125 | 124 | self::$root = $tournament; // If set - Tournament is always root |
@@ -92,8 +92,7 @@ |
||
92 | 92 | foreach ($this->exporters as $name => $exporter) { |
93 | 93 | if ($name === 'setup') { |
94 | 94 | $data += $exporter->get(); |
95 | - } |
|
96 | - else { |
|
95 | + } else { |
|
97 | 96 | $data[$name] = $exporter->get(); |
98 | 97 | } |
99 | 98 | } |
@@ -66,7 +66,7 @@ |
||
66 | 66 | shuffle($teams); |
67 | 67 | } |
68 | 68 | |
69 | - $split = ceil(count($teams) / count($wheres)); |
|
69 | + $split = ceil(count($teams)/count($wheres)); |
|
70 | 70 | foreach ($wheres as $where) { |
71 | 71 | if (count($teams) > 0) { |
72 | 72 | $where->addTeam(...array_splice($teams, 0, $split)); |
@@ -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 | } |
@@ -64,8 +64,7 @@ discard block |
||
64 | 64 | // Get initial data |
65 | 65 | if ($this->topLevelOnly) { |
66 | 66 | $data = $this->container->getTopLevel(); |
67 | - } |
|
68 | - else { |
|
67 | + } else { |
|
69 | 68 | $data = $this->container->get(); |
70 | 69 | } |
71 | 70 | |
@@ -105,8 +104,7 @@ discard block |
||
105 | 104 | } |
106 | 105 | $ids[] = $obj->getId(); |
107 | 106 | } |
108 | - } |
|
109 | - else { |
|
107 | + } else { |
|
110 | 108 | $data = array_unique($data); |
111 | 109 | } |
112 | 110 | } |
@@ -132,11 +130,9 @@ discard block |
||
132 | 130 | protected function sortData(array &$data) : void { |
133 | 131 | if (isset($this->sorter)) { |
134 | 132 | $data = $this->sorter->sort($data); |
135 | - } |
|
136 | - elseif (isset($this->sortClosure)) { |
|
133 | + } elseif (isset($this->sortClosure)) { |
|
137 | 134 | uasort($data, $this->sortClosure); |
138 | - } |
|
139 | - elseif (isset($this->sortProperty)) { |
|
135 | + } elseif (isset($this->sortProperty)) { |
|
140 | 136 | uasort($data, [$this, 'sortByPropertyCallback']); |
141 | 137 | } |
142 | 138 | } |
@@ -226,8 +222,7 @@ discard block |
||
226 | 222 | } |
227 | 223 | return $a < $b ? -1 : 1; |
228 | 224 | }; |
229 | - } |
|
230 | - else { |
|
225 | + } else { |
|
231 | 226 | $this->sortClosure = $callback; |
232 | 227 | } |
233 | 228 | return $this; |
@@ -309,14 +304,12 @@ discard block |
||
309 | 304 | $property2 = null; |
310 | 305 | if (is_object($value1) && isset($value1->$property)) { |
311 | 306 | $property1 = $value1->$property; |
312 | - } |
|
313 | - elseif (is_array($value1) && isset($value1[$property])) { |
|
307 | + } elseif (is_array($value1) && isset($value1[$property])) { |
|
314 | 308 | $property1 = $value1[$property]; |
315 | 309 | } |
316 | 310 | if (is_object($value2) && isset($value2->$property)) { |
317 | 311 | $property2 = $value2->$property; |
318 | - } |
|
319 | - elseif (is_array($value2) && isset($value2[$property])) { |
|
312 | + } elseif (is_array($value2) && isset($value2[$property])) { |
|
320 | 313 | $property2 = $value2[$property]; |
321 | 314 | } |
322 | 315 |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | public function orderGroups() : array { |
99 | 99 | $groups = $this->getGroups(); |
100 | 100 | usort($groups, static function($a, $b) { |
101 | - return $a->getOrder() - $b->getOrder(); |
|
101 | + return $a->getOrder()-$b->getOrder(); |
|
102 | 102 | }); |
103 | 103 | return $groups; |
104 | 104 | } |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | shuffle($teams); |
156 | 156 | } |
157 | 157 | |
158 | - $split = ceil(count($teams) / count($groups)); |
|
158 | + $split = ceil(count($teams)/count($groups)); |
|
159 | 159 | foreach ($groups as $where) { |
160 | 160 | if (count($teams) > 0) { |
161 | 161 | $where->addTeam(...array_splice($teams, 0, $split)); |
@@ -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 |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * @return bool |
24 | 24 | */ |
25 | 25 | public static function isPowerOf2(int $x) : bool { |
26 | - return ($x !== 0) && ($x & ($x - 1)) === 0; |
|
26 | + return ($x !== 0) && ($x&($x-1)) === 0; |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public static function previousPowerOf2(int $x) : int { |
49 | 49 | // Left bit shift by the bit length of the previous number |
50 | - return 1 << (strlen(decbin($x)) - 1); |
|
50 | + return 1 << (strlen(decbin($x))-1); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -73,9 +73,9 @@ discard block |
||
73 | 73 | public static function sortAlternate(array &$array) : array { |
74 | 74 | $new = []; |
75 | 75 | $new2 = []; |
76 | - $count = count($array) / 2; |
|
76 | + $count = count($array)/2; |
|
77 | 77 | for ($i = 0; $i < $count; $i++) { |
78 | - if ($i % 2 === 0) { |
|
78 | + if ($i%2 === 0) { |
|
79 | 79 | $new[] = array_shift($array); |
80 | 80 | $new[] = array_pop($array); |
81 | 81 | } |
@@ -78,8 +78,7 @@ |
||
78 | 78 | if ($i % 2 === 0) { |
79 | 79 | $new[] = array_shift($array); |
80 | 80 | $new[] = array_pop($array); |
81 | - } |
|
82 | - else { |
|
81 | + } else { |
|
83 | 82 | $new2[] = array_shift($array); |
84 | 83 | $new2[] = array_pop($array); |
85 | 84 | } |
@@ -71,8 +71,7 @@ |
||
71 | 71 | /** @infection-ignore-all */ |
72 | 72 | $this->id = uniqid('', false); |
73 | 73 | throw new InvalidArgumentException('Unsupported id type ('.gettype($id).') - expected type of string or int'); |
74 | - } |
|
75 | - else { |
|
74 | + } else { |
|
76 | 75 | $this->id = $id; |
77 | 76 | } |
78 | 77 | return $this; |
@@ -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"; |