@@ -155,7 +155,7 @@ |
||
| 155 | 155 | */ |
| 156 | 156 | public function getTournamentTime() : int { |
| 157 | 157 | $games = count($this->getGames()); |
| 158 | - return $games * $this->expectedPlay + ($games - 1) * $this->expectedGameWait + (count($this->getRounds()) - 1) * $this->expectedRoundWait + (count($this->getCategories()) - 1) * $this->expectedCategoryWait; |
|
| 158 | + return $games*$this->expectedPlay+($games-1)*$this->expectedGameWait+(count($this->getRounds())-1)*$this->expectedRoundWait+(count($this->getCategories())-1)*$this->expectedCategoryWait; |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | /** |
@@ -121,7 +121,7 @@ |
||
| 121 | 121 | foreach ($groupsId as $id) { |
| 122 | 122 | $games += count($team->getGames(null, $id)); |
| 123 | 123 | } |
| 124 | - return self::calcSum($team, $groupsId) / $games; |
|
| 124 | + return self::calcSum($team, $groupsId)/$games; |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -50,14 +50,14 @@ |
||
| 50 | 50 | |
| 51 | 51 | $this->splitTeams($round1); |
| 52 | 52 | |
| 53 | - if (count($this->getTeams()) % 4 === 2) { |
|
| 53 | + if (count($this->getTeams())%4 === 2) { |
|
| 54 | 54 | $group_top = $round2->group('TOP')->setType(Constants::ROUND_TWO); |
| 55 | 55 | |
| 56 | 56 | $filter_win_2 = new TeamFilter('wins', '=', 2, [$group_0_0, $group_top]); |
| 57 | 57 | $filter_loss_2 = new TeamFilter('losses', '=', 2, [$group_0_0, $group_top]); |
| 58 | 58 | $filter_win_1_both = new TeamFilter('wins', '=', 1, [$group_0_0, $group_top]); |
| 59 | 59 | $filter_loss_1_both = new TeamFilter('losses', '=', 1, [$group_0_0, $group_top]); |
| 60 | - $group_0_0->progression($group_top, 0, 1)->addFilter($filter_win_1); // PROGRESS THE BEST WINNING TEAM |
|
| 60 | + $group_0_0->progression($group_top, 0, 1)->addFilter($filter_win_1); // PROGRESS THE BEST WINNING TEAM |
|
| 61 | 61 | $group_0_0->progression($group_top, 0, 1)->addFilter($filter_loss_1); // PROGRESS THE BEST LOSING TEAM |
| 62 | 62 | $group_top->progression($group_2_0)->addFilter($filter_win_2); |
| 63 | 63 | $group_top->progression($group_0_2)->addFilter($filter_loss_2); |
@@ -43,9 +43,9 @@ discard block |
||
| 43 | 43 | |
| 44 | 44 | $startRound = $this->round('Start round'); |
| 45 | 45 | |
| 46 | - $roundsNum = log($nextPow, 2) * 2; |
|
| 46 | + $roundsNum = log($nextPow, 2)*2; |
|
| 47 | 47 | |
| 48 | - $startGroups = ($countTeams + $byes) / 2; |
|
| 48 | + $startGroups = ($countTeams+$byes)/2; |
|
| 49 | 49 | |
| 50 | 50 | $previousGroups = []; |
| 51 | 51 | $previousLosingGroups = []; |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | $lastLosingGroup = null; |
| 64 | 64 | $lastWinningGroup = end($allGroups); |
| 65 | 65 | |
| 66 | - for ($r = 2; $r <= $roundsNum - 1; $r++) { |
|
| 66 | + for ($r = 2; $r <= $roundsNum-1; $r++) { |
|
| 67 | 67 | $groups = []; |
| 68 | 68 | $losingGroups = []; |
| 69 | 69 | $round = $this->round('Round '.$r); |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | $nextPow = $countTeams; |
| 113 | 113 | if (!Functions::isPowerOf2($countTeams)) { |
| 114 | 114 | $nextPow = Functions::nextPowerOf2($countTeams); |
| 115 | - $byes = $nextPow - $countTeams; |
|
| 115 | + $byes = $nextPow-$countTeams; |
|
| 116 | 116 | } |
| 117 | 117 | return $byes; |
| 118 | 118 | } |
@@ -130,10 +130,10 @@ discard block |
||
| 130 | 130 | * @return void Last losing group |
| 131 | 131 | */ |
| 132 | 132 | private function generateLosingSide(int $roundNum, Round $round, array &$allGroups, array $previousLosingGroups = [], array $previousGroups = [], array &$losingGroups = []) : void { |
| 133 | - $losingGroupTeamsCount = count($previousLosingGroups) + count($previousGroups); |
|
| 133 | + $losingGroupTeamsCount = count($previousLosingGroups)+count($previousGroups); |
|
| 134 | 134 | $order = 2; |
| 135 | 135 | if (Functions::isPowerOf2($losingGroupTeamsCount)) { // IF THE NUMBER OF TEAMS IS A POWER OF 2, GENERATE GROUPS WITHOUT BYES |
| 136 | - for ($g = 1; $g <= $losingGroupTeamsCount / 2; $g++) { |
|
| 136 | + for ($g = 1; $g <= $losingGroupTeamsCount/2; $g++) { |
|
| 137 | 137 | $group = $round |
| 138 | 138 | ->group('Round '.$roundNum.' (loss '.$g.')') |
| 139 | 139 | ->setInGame(2) |
@@ -143,13 +143,13 @@ discard block |
||
| 143 | 143 | $order += 2; |
| 144 | 144 | $losingGroups[] = $group; |
| 145 | 145 | if ($roundNum === 2) { // FIRST LOSING ROUND |
| 146 | - $previousGroups[2 * ($g - 1)]->progression($group, 1, 1); // PROGRESS FROM STARTING GROUP |
|
| 147 | - $previousGroups[(2 * ($g - 1)) + 1]->progression($group, 1, 1); // PROGRESS FROM STARTING GROUP |
|
| 146 | + $previousGroups[2*($g-1)]->progression($group, 1, 1); // PROGRESS FROM STARTING GROUP |
|
| 147 | + $previousGroups[(2*($g-1))+1]->progression($group, 1, 1); // PROGRESS FROM STARTING GROUP |
|
| 148 | 148 | } |
| 149 | 149 | elseif ($losingGroupTeamsCount >= 2) { |
| 150 | - $previousLosingGroups[$g - 1]->progression($group, 0, 1); // PROGRESS FROM LOSING GROUP BEFORE |
|
| 151 | - if (isset(array_reverse($previousGroups)[$g - 1])) { |
|
| 152 | - array_reverse($previousGroups)[$g - 1]->progression($group, 1, 1); |
|
| 150 | + $previousLosingGroups[$g-1]->progression($group, 0, 1); // PROGRESS FROM LOSING GROUP BEFORE |
|
| 151 | + if (isset(array_reverse($previousGroups)[$g-1])) { |
|
| 152 | + array_reverse($previousGroups)[$g-1]->progression($group, 1, 1); |
|
| 153 | 153 | } // PROGRESS FROM WINNING GROUP BEFORE |
| 154 | 154 | else { |
| 155 | 155 | $previousLosingGroups[$g]->progression($group, 0, 1); |
@@ -159,15 +159,15 @@ discard block |
||
| 159 | 159 | } |
| 160 | 160 | else { // IF THE NUMBER OF TEAMS IS NOT A POWER OF 2, GENERATE GROUPS WITH BYES |
| 161 | 161 | // LOOK FOR THE CLOSEST LOWER POWER OF 2 |
| 162 | - $losingByes = $losingGroupTeamsCount - Functions::previousPowerOf2($losingGroupTeamsCount); |
|
| 163 | - $n = (floor(count($previousLosingGroups) / 2) + $losingByes); |
|
| 162 | + $losingByes = $losingGroupTeamsCount-Functions::previousPowerOf2($losingGroupTeamsCount); |
|
| 163 | + $n = (floor(count($previousLosingGroups)/2)+$losingByes); |
|
| 164 | 164 | $byesGroupsNums = []; |
| 165 | 165 | $byesProgressed = 0; |
| 166 | 166 | for ($i = 0; $i < $losingByes; $i++) { |
| 167 | - $byesGroupsNums[] = (int) $n - ($i * 2); |
|
| 167 | + $byesGroupsNums[] = (int) $n-($i*2); |
|
| 168 | 168 | } |
| 169 | 169 | $lastGroup = 0; |
| 170 | - for ($g = 1; $g <= ((count($previousLosingGroups) / 2) + $losingByes); $g++) { |
|
| 170 | + for ($g = 1; $g <= ((count($previousLosingGroups)/2)+$losingByes); $g++) { |
|
| 171 | 171 | $group = $round |
| 172 | 172 | ->group('Round '.$roundNum.' (loss '.$g.')') |
| 173 | 173 | ->setInGame(2) |
@@ -177,13 +177,13 @@ discard block |
||
| 177 | 177 | $order += 2; |
| 178 | 178 | $losingGroups[] = $group; |
| 179 | 179 | if (isset($previousGroups[$byesProgressed]) && in_array($lastGroup, $byesGroupsNums, true)) { // EMPTY GROUP FROM BYE |
| 180 | - $previousGroups[$byesProgressed]->progression($group, 1, 1); // PROGRESS FROM WINNING GROUP BEFORE |
|
| 180 | + $previousGroups[$byesProgressed]->progression($group, 1, 1); // PROGRESS FROM WINNING GROUP BEFORE |
|
| 181 | 181 | $byesProgressed++; |
| 182 | 182 | } |
| 183 | 183 | else { |
| 184 | 184 | $previousLosingGroups[$lastGroup]->progression($group, 0, 1); // PROGRESS FROM LOSING GROUP BEFORE |
| 185 | - if (isset($previousLosingGroups[$lastGroup + 1])) { // PROGRESS FROM LOSING GROUP BEFORE |
|
| 186 | - $previousLosingGroups[$lastGroup + 1]->progression($group, 0, 1); |
|
| 185 | + if (isset($previousLosingGroups[$lastGroup+1])) { // PROGRESS FROM LOSING GROUP BEFORE |
|
| 186 | + $previousLosingGroups[$lastGroup+1]->progression($group, 0, 1); |
|
| 187 | 187 | } |
| 188 | 188 | $lastGroup += 2; |
| 189 | 189 | } |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | */ |
| 208 | 208 | private function generateWinSide(int $roundNum, int $byes, int $countTeams, Round $round, array &$allGroups, array &$groups, Group &$lastWinningGroup = null, array $previousGroups = []) : void { |
| 209 | 209 | $order = 1; |
| 210 | - for ($g = 1; $g <= (($countTeams + $byes) / (2 ** $roundNum)); $g++) { |
|
| 210 | + for ($g = 1; $g <= (($countTeams+$byes)/(2 ** $roundNum)); $g++) { |
|
| 211 | 211 | $group = $round |
| 212 | 212 | ->group('Round '.$roundNum.' (win '.$g.')') |
| 213 | 213 | ->setInGame(2) |
@@ -216,9 +216,9 @@ discard block |
||
| 216 | 216 | $allGroups[] = $group; |
| 217 | 217 | $order += 2; |
| 218 | 218 | $groups[] = $group; |
| 219 | - $lastWinningGroup = $group; // KEEP THE LAST GROUP FOR FINALE |
|
| 220 | - $previousGroups[2 * ($g - 1)]->progression($group, 0, 1); // PROGRESS FROM GROUP BEFORE |
|
| 221 | - $previousGroups[(2 * ($g - 1)) + 1]->progression($group, 0, 1); // PROGRESS FROM GROUP BEFORE |
|
| 219 | + $lastWinningGroup = $group; // KEEP THE LAST GROUP FOR FINALE |
|
| 220 | + $previousGroups[2*($g-1)]->progression($group, 0, 1); // PROGRESS FROM GROUP BEFORE |
|
| 221 | + $previousGroups[(2*($g-1))+1]->progression($group, 0, 1); // PROGRESS FROM GROUP BEFORE |
|
| 222 | 222 | } |
| 223 | 223 | } |
| 224 | 224 | |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | foreach ($this->getRounds() as $round) { |
| 231 | 231 | $name = $round->getName(); |
| 232 | 232 | $len = strlen($name); |
| 233 | - $str .= "\n| ---------------------------------------- |\n| ".str_repeat('-', floor((40 - $len) / 2) - 1).' '.$name.' '.str_repeat('-', ceil((40 - $len) / 2) - 1)." |\n| ---------------------------------------- |\n\n"; |
|
| 233 | + $str .= "\n| ---------------------------------------- |\n| ".str_repeat('-', floor((40-$len)/2)-1).' '.$name.' '.str_repeat('-', ceil((40-$len)/2)-1)." |\n| ---------------------------------------- |\n\n"; |
|
| 234 | 234 | foreach ($round->getGroups() as $group) { |
| 235 | 235 | $str .= '-- '.$group->getName().PHP_EOL; |
| 236 | 236 | foreach ($group->getGames() as $game) { |
@@ -33,16 +33,16 @@ discard block |
||
| 33 | 33 | $byes = 0; |
| 34 | 34 | if (!Functions::isPowerOf2($countTeams)) { |
| 35 | 35 | $nextPow = Functions::nextPowerOf2($countTeams); |
| 36 | - $byes = $nextPow - $countTeams; |
|
| 36 | + $byes = $nextPow-$countTeams; |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - $roundsNum = log($countTeams + $byes, 2); // NUMBER OF ROUNDS |
|
| 39 | + $roundsNum = log($countTeams+$byes, 2); // NUMBER OF ROUNDS |
|
| 40 | 40 | |
| 41 | 41 | $startRound = $this->round('Start'); |
| 42 | 42 | |
| 43 | 43 | $previousGroups = []; |
| 44 | 44 | |
| 45 | - for ($i = 1; $i <= (($countTeams + $byes) / 2); $i++) { |
|
| 45 | + for ($i = 1; $i <= (($countTeams+$byes)/2); $i++) { |
|
| 46 | 46 | $g = $startRound->group('Round 1 '.$i)->setInGame(2)->setType(Constants::ROUND_TWO); |
| 47 | 47 | $previousGroups[] = $g; |
| 48 | 48 | } |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | for ($r = 2; $r <= $roundsNum; $r++) { |
| 53 | 53 | $groups = []; |
| 54 | 54 | $round = $this->round('Round '.$r); |
| 55 | - for ($g = 1; $g <= (($countTeams + $byes) / (2 ** $r)); $g++) { |
|
| 55 | + for ($g = 1; $g <= (($countTeams+$byes)/(2 ** $r)); $g++) { |
|
| 56 | 56 | $group = $round->group('Round '.$r.' - '.$g)->setInGame(2)->setType(Constants::ROUND_TWO); |
| 57 | 57 | $groups[] = $group; |
| 58 | 58 | array_shift($previousGroups)->progression($group, 0, 1); // PROGRESS FROM GROUP BEFORE |
@@ -178,14 +178,14 @@ discard block |
||
| 178 | 178 | */ |
| 179 | 179 | public static function circle_genGames2(Group $group, array $teams = []) : array { |
| 180 | 180 | |
| 181 | - if (count($teams) % 2 !== 0) { |
|
| 181 | + if (count($teams)%2 !== 0) { |
|
| 182 | 182 | $teams[] = Constants::DUMMY_TEAM; |
| 183 | 183 | } // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY |
| 184 | 184 | |
| 185 | 185 | shuffle($teams); // SHUFFLE TEAMS FOR MORE RANDOMNESS |
| 186 | 186 | |
| 187 | 187 | $rounds = []; |
| 188 | - for ($i = 0; $i < count($teams) - 1; $i++) { |
|
| 188 | + for ($i = 0; $i < count($teams)-1; $i++) { |
|
| 189 | 189 | $rounds[] = self::circle_saveBracket($teams, $group); // SAVE CURRENT ROUND |
| 190 | 190 | |
| 191 | 191 | $teams = self::circle_rotateBracket($teams); // ROTATE TEAMS IN BRACKET |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | |
| 208 | 208 | $bracket = []; |
| 209 | 209 | |
| 210 | - for ($i = 0; $i < count($teams) / 2; $i++) { // GO THROUGH HALF OF THE TEAMS |
|
| 210 | + for ($i = 0; $i < count($teams)/2; $i++) { // GO THROUGH HALF OF THE TEAMS |
|
| 211 | 211 | |
| 212 | 212 | $home = $teams[$i]; |
| 213 | 213 | $reverse = array_reverse($teams); |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | public static function circle_rotateBracket(array $teams) : array { |
| 236 | 236 | |
| 237 | 237 | $first = array_shift($teams); // THE FIRST TEAM REMAINS FIRST |
| 238 | - $last = array_shift($teams); // THE SECOND TEAM MOVES TO LAST PLACE |
|
| 238 | + $last = array_shift($teams); // THE SECOND TEAM MOVES TO LAST PLACE |
|
| 239 | 239 | |
| 240 | 240 | return array_merge([$first], $teams, [$last]); // MERGE BACK TOGETHER |
| 241 | 241 | |
@@ -304,7 +304,7 @@ discard block |
||
| 304 | 304 | shuffle($teams); |
| 305 | 305 | $count = count($teams); // Store original count for exception |
| 306 | 306 | |
| 307 | - $discard = array_splice($teams, 0, $count % $this->inGame); |
|
| 307 | + $discard = array_splice($teams, 0, $count%$this->inGame); |
|
| 308 | 308 | |
| 309 | 309 | $teams = $this->saveTwoTwoGames($teams); |
| 310 | 310 | |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | $games = []; |
| 334 | 334 | |
| 335 | 335 | // Split teams into chunks of maximum size |
| 336 | - $groups = array_chunk($teams, (int) ceil($count / ceil($count / $this->maxSize))); |
|
| 336 | + $groups = array_chunk($teams, (int) ceil($count/ceil($count/$this->maxSize))); |
|
| 337 | 337 | // Generate games for each chunk |
| 338 | 338 | foreach ($groups as $group) { |
| 339 | 339 | $games[] = $this->r_rGames($group); |
@@ -564,7 +564,7 @@ |
||
| 564 | 564 | * @return bool |
| 565 | 565 | */ |
| 566 | 566 | public static function isObject($data) : bool { |
| 567 | - return is_object($data) || (is_array($data) && !empty($data) && array_keys($data) !== range(0, count($data) - 1)); |
|
| 567 | + return is_object($data) || (is_array($data) && !empty($data) && array_keys($data) !== range(0, count($data)-1)); |
|
| 568 | 568 | } |
| 569 | 569 | |
| 570 | 570 | /** |
@@ -42,7 +42,7 @@ |
||
| 42 | 42 | * |
| 43 | 43 | */ |
| 44 | 44 | public function getJson() : string { |
| 45 | - return json_encode($this->get(), JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES); |
|
| 45 | + return json_encode($this->get(), JSON_THROW_ON_ERROR|JSON_UNESCAPED_SLASHES); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -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)); |