@@ -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 | /** |
@@ -62,8 +62,7 @@ |
||
62 | 62 | public function setType(string $type = Constants::ROUND_ROBIN) : Generator { |
63 | 63 | if (in_array($type, Constants::GroupTypes, true)) { |
64 | 64 | $this->type = $type; |
65 | - } |
|
66 | - else { |
|
65 | + } else { |
|
67 | 66 | throw new Exception('Unknown group type: '.$type); |
68 | 67 | } |
69 | 68 | return $this; |
@@ -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); |
@@ -221,13 +221,11 @@ |
||
221 | 221 | $this->drawIds[] = $team->getId(); |
222 | 222 | $team->addDraw($this->group->getId()); |
223 | 223 | $this->results[$team->getId()] += ['points' => $this->group->getDrawPoints(), 'type' => 'draw']; |
224 | - } |
|
225 | - elseif ($teamPosition === 1) { |
|
224 | + } elseif ($teamPosition === 1) { |
|
226 | 225 | $this->winId = $team->getId(); |
227 | 226 | $team->addWin($this->group->getId()); |
228 | 227 | $this->results[$team->getId()] += ['points' => $this->group->getWinPoints(), 'type' => 'win']; |
229 | - } |
|
230 | - else { |
|
228 | + } else { |
|
231 | 229 | $this->lossId = $team->getId(); |
232 | 230 | $team->addLoss($this->group->getId()); |
233 | 231 | $this->results[$team->getId()] += ['points' => $this->group->getLostPoints(), 'type' => 'loss']; |
@@ -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) { |
@@ -145,8 +145,7 @@ discard block |
||
145 | 145 | if ($roundNum === 2) { // FIRST LOSING ROUND |
146 | 146 | $previousGroups[2 * ($g - 1)]->progression($group, 1, 1); // PROGRESS FROM STARTING GROUP |
147 | 147 | $previousGroups[(2 * ($g - 1)) + 1]->progression($group, 1, 1); // PROGRESS FROM STARTING GROUP |
148 | - } |
|
149 | - elseif ($losingGroupTeamsCount >= 2) { |
|
148 | + } elseif ($losingGroupTeamsCount >= 2) { |
|
150 | 149 | $previousLosingGroups[$g - 1]->progression($group, 0, 1); // PROGRESS FROM LOSING GROUP BEFORE |
151 | 150 | if (isset(array_reverse($previousGroups)[$g - 1])) { |
152 | 151 | array_reverse($previousGroups)[$g - 1]->progression($group, 1, 1); |
@@ -156,8 +155,7 @@ discard block |
||
156 | 155 | } // PROGRESS OTHER TEAM FROM LOSING GROUP BEFORE |
157 | 156 | } |
158 | 157 | } |
159 | - } |
|
160 | - else { // IF THE NUMBER OF TEAMS IS NOT A POWER OF 2, GENERATE GROUPS WITH BYES |
|
158 | + } else { // IF THE NUMBER OF TEAMS IS NOT A POWER OF 2, GENERATE GROUPS WITH BYES |
|
161 | 159 | // LOOK FOR THE CLOSEST LOWER POWER OF 2 |
162 | 160 | $losingByes = $losingGroupTeamsCount - Functions::previousPowerOf2($losingGroupTeamsCount); |
163 | 161 | $n = (floor(count($previousLosingGroups) / 2) + $losingByes); |
@@ -179,8 +177,7 @@ discard block |
||
179 | 177 | if (isset($previousGroups[$byesProgressed]) && in_array($lastGroup, $byesGroupsNums, true)) { // EMPTY GROUP FROM BYE |
180 | 178 | $previousGroups[$byesProgressed]->progression($group, 1, 1); // PROGRESS FROM WINNING GROUP BEFORE |
181 | 179 | $byesProgressed++; |
182 | - } |
|
183 | - else { |
|
180 | + } else { |
|
184 | 181 | $previousLosingGroups[$lastGroup]->progression($group, 0, 1); // PROGRESS FROM LOSING GROUP BEFORE |
185 | 182 | if (isset($previousLosingGroups[$lastGroup + 1])) { // PROGRESS FROM LOSING GROUP BEFORE |
186 | 183 | $previousLosingGroups[$lastGroup + 1]->progression($group, 0, 1); |
@@ -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 |
@@ -95,15 +95,13 @@ discard block |
||
95 | 95 | |
96 | 96 | if ($blank) { |
97 | 97 | $teams = $this->from->isPlayed() ? $this->from->sortTeams(null, $this->filters) : $this->from->simulate($this->filters); |
98 | - } |
|
99 | - else { |
|
98 | + } else { |
|
100 | 99 | $teams = $this->from->sortTeams(null, $this->filters); |
101 | 100 | } |
102 | 101 | |
103 | 102 | if ($this->start !== 0 || $this->len !== null) { |
104 | 103 | $next = array_splice($teams, $this->start, ($this->len ?? count($teams))); |
105 | - } |
|
106 | - else { |
|
104 | + } else { |
|
107 | 105 | $next = $teams; |
108 | 106 | } |
109 | 107 | |
@@ -112,8 +110,7 @@ discard block |
||
112 | 110 | foreach ($next as $team) { |
113 | 111 | if ($blank) { |
114 | 112 | $this->to->addTeam(new BlankTeam($this.' - '.$i++, $team, $this->from, $this)); |
115 | - } |
|
116 | - else { |
|
113 | + } else { |
|
117 | 114 | $team->addPoints($this->from->getProgressPoints()); |
118 | 115 | } |
119 | 116 | } |
@@ -70,8 +70,7 @@ |
||
70 | 70 | if (!is_string($id) && !is_int($id)) { |
71 | 71 | $this->id = uniqid('', false); |
72 | 72 | throw new InvalidArgumentException('Unsupported id type ('.gettype($id).') - expected type of string or int'); |
73 | - } |
|
74 | - else { |
|
73 | + } else { |
|
75 | 74 | $this->id = $id; |
76 | 75 | } |
77 | 76 | return $this; |