@@ -100,7 +100,9 @@ discard block |
||
| 100 | 100 | return $t; |
| 101 | 101 | } |
| 102 | 102 | public function sortTeams(array $filters = [], $ordering = null) { |
| 103 | - if (!isset($ordering)) $ordering = $this->ordering; |
|
| 103 | + if (!isset($ordering)) { |
|
| 104 | + $ordering = $this->ordering; |
|
| 105 | + } |
|
| 104 | 106 | Utilis\Sorter\Teams::sortGroup($this->teams, $this, $ordering); |
| 105 | 107 | return $this->getTeams($filters); |
| 106 | 108 | } |
@@ -130,7 +132,9 @@ discard block |
||
| 130 | 132 | } |
| 131 | 133 | |
| 132 | 134 | public function setOrdering(string $ordering = \TournamentGenerator\Constants::POINTS) { |
| 133 | - if (!in_array($ordering, \TournamentGenerator\Constants::OrderingTypes)) throw new \Exception('Unknown group ordering: '.$ordering); |
|
| 135 | + if (!in_array($ordering, \TournamentGenerator\Constants::OrderingTypes)) { |
|
| 136 | + throw new \Exception('Unknown group ordering: '.$ordering); |
|
| 137 | + } |
|
| 134 | 138 | $this->ordering = $ordering; |
| 135 | 139 | return $this; |
| 136 | 140 | } |
@@ -162,8 +166,9 @@ discard block |
||
| 162 | 166 | } |
| 163 | 167 | public function addProgressed(...$teams) { |
| 164 | 168 | foreach ($teams as $team) { |
| 165 | - if ($team instanceOf Team) $this->progressed[] = $team; |
|
| 166 | - elseif (gettype($team) === 'array') { |
|
| 169 | + if ($team instanceOf Team) { |
|
| 170 | + $this->progressed[] = $team; |
|
| 171 | + } elseif (gettype($team) === 'array') { |
|
| 167 | 172 | $this->progressed = array_merge($this->progressed, array_filter($team, function($a) { |
| 168 | 173 | return ($a instanceof Team); |
| 169 | 174 | })); |
@@ -192,7 +197,9 @@ discard block |
||
| 192 | 197 | $this->games = array_merge($this->games, array_filter($game, function($a){ return ($a instanceof Game); })); |
| 193 | 198 | continue; |
| 194 | 199 | } |
| 195 | - if (!$game instanceof Game) throw new \Exception('Trying to add game which is not instance of Game object.'); |
|
| 200 | + if (!$game instanceof Game) { |
|
| 201 | + throw new \Exception('Trying to add game which is not instance of Game object.'); |
|
| 202 | + } |
|
| 196 | 203 | $this->games[] = $game; |
| 197 | 204 | } |
| 198 | 205 | return $this; |
@@ -201,7 +208,9 @@ discard block |
||
| 201 | 208 | return $this->games; |
| 202 | 209 | } |
| 203 | 210 | public function orderGames() { |
| 204 | - if (count($this->games) <= 4) return $this->games; |
|
| 211 | + if (count($this->games) <= 4) { |
|
| 212 | + return $this->games; |
|
| 213 | + } |
|
| 205 | 214 | $this->games = $this->generator->orderGames(); |
| 206 | 215 | return $this->games; |
| 207 | 216 | } |
@@ -216,9 +225,13 @@ discard block |
||
| 216 | 225 | return $this; |
| 217 | 226 | } |
| 218 | 227 | public function isPlayed(){ |
| 219 | - if (count($this->games) === 0) return false; |
|
| 228 | + if (count($this->games) === 0) { |
|
| 229 | + return false; |
|
| 230 | + } |
|
| 220 | 231 | foreach ($this->games as $game) { |
| 221 | - if (!$game->isPlayed()) return false; |
|
| 232 | + if (!$game->isPlayed()) { |
|
| 233 | + return false; |
|
| 234 | + } |
|
| 222 | 235 | } |
| 223 | 236 | return true; |
| 224 | 237 | } |
@@ -75,24 +75,32 @@ discard block |
||
| 75 | 75 | } |
| 76 | 76 | public function getGroupResults($groupId = null) { |
| 77 | 77 | if (isset($groupId)) { |
| 78 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Trying to get unexisting group results ('.$groupId.')'); |
|
| 78 | + if (!isset($this->groupResults[$groupId])) { |
|
| 79 | + throw new \Exception('Trying to get unexisting group results ('.$groupId.')'); |
|
| 80 | + } |
|
| 79 | 81 | return $this->groupResults[$groupId]; |
| 80 | 82 | } |
| 81 | 83 | return $this->groupResults; |
| 82 | 84 | } |
| 83 | 85 | |
| 84 | 86 | public function addGameWith(Team $team, Group $group) { |
| 85 | - if (!isset($this->gamesWith[$group->getId()][$team->getId()])) $this->gamesWith[$group->getId()][$team->getId()] = 0; |
|
| 87 | + if (!isset($this->gamesWith[$group->getId()][$team->getId()])) { |
|
| 88 | + $this->gamesWith[$group->getId()][$team->getId()] = 0; |
|
| 89 | + } |
|
| 86 | 90 | $this->gamesWith[$group->getId()][$team->getId()]++; |
| 87 | 91 | return $this; |
| 88 | 92 | } |
| 89 | 93 | public function addGroup(Group $group) { |
| 90 | - if (!isset($this->games[$group->getId()])) $this->games[$group->getId()] = []; |
|
| 94 | + if (!isset($this->games[$group->getId()])) { |
|
| 95 | + $this->games[$group->getId()] = []; |
|
| 96 | + } |
|
| 91 | 97 | return $this; |
| 92 | 98 | } |
| 93 | 99 | public function addGame(Game $game) { |
| 94 | 100 | $group = $game->getGroup(); |
| 95 | - if (!isset($this->games[$group->getId()])) $this->games[$group->getId()] = []; |
|
| 101 | + if (!isset($this->games[$group->getId()])) { |
|
| 102 | + $this->games[$group->getId()] = []; |
|
| 103 | + } |
|
| 96 | 104 | $this->games[$group->getId()][] = $game; |
| 97 | 105 | return $this; |
| 98 | 106 | } |
@@ -105,70 +113,90 @@ discard block |
||
| 105 | 113 | } |
| 106 | 114 | |
| 107 | 115 | public function addWin(string $groupId = ''){ |
| 108 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 116 | + if (!isset($this->groupResults[$groupId])) { |
|
| 117 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 118 | + } |
|
| 109 | 119 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->winPoints; |
| 110 | 120 | $this->sumPoints += $this->groupResults[$groupId]['group']->winPoints; |
| 111 | 121 | $this->groupResults[$groupId]['wins']++; |
| 112 | 122 | return $this; |
| 113 | 123 | } |
| 114 | 124 | public function removeWin(string $groupId = ''){ |
| 115 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 125 | + if (!isset($this->groupResults[$groupId])) { |
|
| 126 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 127 | + } |
|
| 116 | 128 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->winPoints; |
| 117 | 129 | $this->sumPoints -= $this->groupResults[$groupId]['group']->winPoints; |
| 118 | 130 | $this->groupResults[$groupId]['wins']--; |
| 119 | 131 | return $this; |
| 120 | 132 | } |
| 121 | 133 | public function addDraw(string $groupId = ''){ |
| 122 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 134 | + if (!isset($this->groupResults[$groupId])) { |
|
| 135 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 136 | + } |
|
| 123 | 137 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->drawPoints; |
| 124 | 138 | $this->sumPoints += $this->groupResults[$groupId]['group']->drawPoints; |
| 125 | 139 | $this->groupResults[$groupId]['draws']++; |
| 126 | 140 | return $this; |
| 127 | 141 | } |
| 128 | 142 | public function removeDraw(string $groupId = ''){ |
| 129 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 143 | + if (!isset($this->groupResults[$groupId])) { |
|
| 144 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 145 | + } |
|
| 130 | 146 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->drawPointsPoints; |
| 131 | 147 | $this->sumPoints -= $this->groupResults[$groupId]['group']->drawPoints; |
| 132 | 148 | $this->groupResults[$groupId]['draws']--; |
| 133 | 149 | return $this; |
| 134 | 150 | } |
| 135 | 151 | public function addLoss(string $groupId = ''){ |
| 136 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 152 | + if (!isset($this->groupResults[$groupId])) { |
|
| 153 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 154 | + } |
|
| 137 | 155 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->lostPoints; |
| 138 | 156 | $this->sumPoints += $this->groupResults[$groupId]['group']->lostPoints; |
| 139 | 157 | $this->groupResults[$groupId]['losses']++; |
| 140 | 158 | return $this; |
| 141 | 159 | } |
| 142 | 160 | public function removeLoss(string $groupId = ''){ |
| 143 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 161 | + if (!isset($this->groupResults[$groupId])) { |
|
| 162 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 163 | + } |
|
| 144 | 164 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->lostPoints; |
| 145 | 165 | $this->sumPoints -= $this->groupResults[$groupId]['group']->lostPoints; |
| 146 | 166 | $this->groupResults[$groupId]['losses']--; |
| 147 | 167 | return $this; |
| 148 | 168 | } |
| 149 | 169 | public function addSecond(string $groupId = ''){ |
| 150 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 170 | + if (!isset($this->groupResults[$groupId])) { |
|
| 171 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 172 | + } |
|
| 151 | 173 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->secondPoints; |
| 152 | 174 | $this->sumPoints += $this->groupResults[$groupId]['group']->secondPoints; |
| 153 | 175 | $this->groupResults[$groupId]['second']++; |
| 154 | 176 | return $this; |
| 155 | 177 | } |
| 156 | 178 | public function removeSecond(string $groupId = ''){ |
| 157 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 179 | + if (!isset($this->groupResults[$groupId])) { |
|
| 180 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 181 | + } |
|
| 158 | 182 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->secondPoints; |
| 159 | 183 | $this->sumPoints -= $this->groupResults[$groupId]['group']->secondPoints; |
| 160 | 184 | $this->groupResults[$groupId]['second']--; |
| 161 | 185 | return $this; |
| 162 | 186 | } |
| 163 | 187 | public function addThird(string $groupId = ''){ |
| 164 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 188 | + if (!isset($this->groupResults[$groupId])) { |
|
| 189 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 190 | + } |
|
| 165 | 191 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->thirdPoints; |
| 166 | 192 | $this->sumPoints += $this->groupResults[$groupId]['group']->thirdPoints; |
| 167 | 193 | $this->groupResults[$groupId]['third']++; |
| 168 | 194 | return $this; |
| 169 | 195 | } |
| 170 | 196 | public function removeThird(string $groupId = ''){ |
| 171 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 197 | + if (!isset($this->groupResults[$groupId])) { |
|
| 198 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 199 | + } |
|
| 172 | 200 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->thirdPoints; |
| 173 | 201 | $this->sumPoints -= $this->groupResults[$groupId]['group']->thirdPoints; |
| 174 | 202 | $this->groupResults[$groupId]['third']--; |
@@ -176,7 +204,9 @@ discard block |
||
| 176 | 204 | } |
| 177 | 205 | |
| 178 | 206 | public function sumPoints(array $groupIds = []) { |
| 179 | - if (count($groupIds) === 0) return $this->sumPoints; |
|
| 207 | + if (count($groupIds) === 0) { |
|
| 208 | + return $this->sumPoints; |
|
| 209 | + } |
|
| 180 | 210 | $sum = 0; |
| 181 | 211 | foreach ($groupIds as $gid) { |
| 182 | 212 | $sum += $this->groupResults[$gid]['points'] ?? 0; |
@@ -184,7 +214,9 @@ discard block |
||
| 184 | 214 | return $sum; |
| 185 | 215 | } |
| 186 | 216 | public function sumScore(array $groupIds = []) { |
| 187 | - if (count($groupIds) === 0) return $this->sumScore; |
|
| 217 | + if (count($groupIds) === 0) { |
|
| 218 | + return $this->sumScore; |
|
| 219 | + } |
|
| 188 | 220 | $sum = 0; |
| 189 | 221 | foreach ($groupIds as $gid) { |
| 190 | 222 | $sum += $this->groupResults[$gid]['score'] ?? 0; |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | $groupIds = []; |
| 32 | 32 | $allGroups = []; |
| 33 | 33 | |
| 34 | - for ($i=1; $i <= $startGroups; $i++) { |
|
| 34 | + for ($i = 1; $i <= $startGroups; $i++) { |
|
| 35 | 35 | $g = $startRound->group('Start group - '.$i)->setInGame(2)->setType(\TournamentGenerator\Constants::ROUND_TWO); |
| 36 | 36 | $allGroups[] = $g; |
| 37 | 37 | $groupIds[] = $g->getId(); |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | // SPLIT TEAMS EVENLY |
| 42 | 42 | $this->splitTeams(); |
| 43 | 43 | |
| 44 | - for ($r=2; $r <= $roundsNum-1; $r++) { |
|
| 44 | + for ($r = 2; $r <= $roundsNum-1; $r++) { |
|
| 45 | 45 | $groups = []; |
| 46 | 46 | $losingGroups = []; |
| 47 | 47 | $round = $this->round('Round '.$r); |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | private function calcByes(int $countTeams, int &$nextPow) { |
| 76 | 76 | $byes = 0; |
| 77 | 77 | $nextPow = $countTeams; |
| 78 | - if ( !\TournamentGenerator\isPowerOf2($countTeams) ) { |
|
| 78 | + if (!\TournamentGenerator\isPowerOf2($countTeams)) { |
|
| 79 | 79 | $nextPow = bindec(str_pad(1, strlen(decbin($countTeams))+1, 0, STR_PAD_RIGHT)); |
| 80 | 80 | $byes = $nextPow-$countTeams; |
| 81 | 81 | } |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | } |
| 84 | 84 | private function generateWinSide(int &$r, int &$byes, int &$countTeams, \TournamentGenerator\Round &$round, array &$allGroups, array &$groups, \TournamentGenerator\Group &$lastWinningGroup = null, array &$previousGroups = []) { |
| 85 | 85 | $order = 1; |
| 86 | - for ($g=1; $g <= (($countTeams+$byes)/pow(2, $r)); $g++) { |
|
| 86 | + for ($g = 1; $g <= (($countTeams+$byes)/pow(2, $r)); $g++) { |
|
| 87 | 87 | $group = $round->group('Round '.$r.' - win '.$g)->setInGame(2)->setType(\TournamentGenerator\Constants::ROUND_TWO)->setOrder($order); |
| 88 | 88 | $allGroups[] = $group; |
| 89 | 89 | $order += 2; |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | $losingGroupTeamsCount = count($previousLosingGroups)+count($previousGroups); |
| 99 | 99 | $order = 2; |
| 100 | 100 | if (\TournamentGenerator\isPowerOf2($losingGroupTeamsCount)) { // IF THE NUMBER OF TEAMS IS A POWER OF 2, GENERATE GROUPS WITHOUT BYES |
| 101 | - for ($g=1; $g <= $losingGroupTeamsCount/2; $g++) { |
|
| 101 | + for ($g = 1; $g <= $losingGroupTeamsCount/2; $g++) { |
|
| 102 | 102 | $group = $round->group('Round '.$r.' - loss '.$g)->setInGame(2)->setType(\TournamentGenerator\Constants::ROUND_TWO)->setOrder($order); |
| 103 | 103 | $allGroups[] = $group; |
| 104 | 104 | $order += 2; |
@@ -121,11 +121,11 @@ discard block |
||
| 121 | 121 | $n = (floor(count($previousLosingGroups)/2)+$losingByes); |
| 122 | 122 | $byesGroupsNums = []; |
| 123 | 123 | $byesProgressed = 0; |
| 124 | - for ($i=0; $i < $losingByes; $i++) { |
|
| 124 | + for ($i = 0; $i < $losingByes; $i++) { |
|
| 125 | 125 | $byesGroupsNums[] = $n-($i*2); |
| 126 | 126 | } |
| 127 | 127 | $lastGroup = 0; |
| 128 | - for ($g=1; $g <= ((count($previousLosingGroups)/2)+$losingByes); $g++) { |
|
| 128 | + for ($g = 1; $g <= ((count($previousLosingGroups)/2)+$losingByes); $g++) { |
|
| 129 | 129 | $group = $round->group('Round '.$r.' - loss '.$g)->setInGame(2)->setType(\TournamentGenerator\Constants::ROUND_TWO)->setOrder($order); |
| 130 | 130 | $allGroups[] = $group; |
| 131 | 131 | $order += 2; |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | } |
| 138 | 138 | else { |
| 139 | 139 | $previousLosingGroups[$lastGroup]->progression($group, 0, 1); // PROGRESS FROM LOSING GROUP BEFORE |
| 140 | - if (isset($previousLosingGroups[$lastGroup + 1])) $previousLosingGroups[$lastGroup + 1]->progression($group, 0, 1); // PROGREESS FROM LOSING GROUP BEFORE |
|
| 140 | + if (isset($previousLosingGroups[$lastGroup+1])) $previousLosingGroups[$lastGroup+1]->progression($group, 0, 1); // PROGREESS FROM LOSING GROUP BEFORE |
|
| 141 | 141 | $lastGroup += 2; |
| 142 | 142 | } |
| 143 | 143 | } |