@@ -44,17 +44,23 @@ discard block |
||
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | public function addGameWith(Team $team, Group $group) { |
| 47 | - if (!isset($this->gamesWith[$group->id][$team->id])) $this->gamesWith[$group->id][$team->id] = 0; |
|
| 47 | + if (!isset($this->gamesWith[$group->id][$team->id])) { |
|
| 48 | + $this->gamesWith[$group->id][$team->id] = 0; |
|
| 49 | + } |
|
| 48 | 50 | $this->gamesWith[$group->id][$team->id]++; |
| 49 | 51 | return $this; |
| 50 | 52 | } |
| 51 | 53 | public function addGroup(Group $group) { |
| 52 | - if (!isset($this->games[$group->id])) $this->games[$group->id] = []; |
|
| 54 | + if (!isset($this->games[$group->id])) { |
|
| 55 | + $this->games[$group->id] = []; |
|
| 56 | + } |
|
| 53 | 57 | return $this; |
| 54 | 58 | } |
| 55 | 59 | public function addGame(Game $game) { |
| 56 | 60 | $group = $game->getGroup(); |
| 57 | - if (!isset($this->games[$group->id])) $this->games[$group->id] = []; |
|
| 61 | + if (!isset($this->games[$group->id])) { |
|
| 62 | + $this->games[$group->id] = []; |
|
| 63 | + } |
|
| 58 | 64 | $this->games[$group->id][] = $game; |
| 59 | 65 | return $this; |
| 60 | 66 | } |
@@ -67,88 +73,116 @@ discard block |
||
| 67 | 73 | } |
| 68 | 74 | |
| 69 | 75 | public function addWin(string $groupId = ''){ |
| 70 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 76 | + if (!isset($this->groupResults[$groupId])) { |
|
| 77 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 78 | + } |
|
| 71 | 79 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->winPoints; |
| 72 | 80 | $this->sumPoints += $this->groupResults[$groupId]['group']->winPoints; |
| 73 | 81 | $this->groupResults[$groupId]['wins']++; |
| 74 | 82 | return $this; |
| 75 | 83 | } |
| 76 | 84 | public function removeWin(string $groupId = ''){ |
| 77 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 85 | + if (!isset($this->groupResults[$groupId])) { |
|
| 86 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 87 | + } |
|
| 78 | 88 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->winPoints; |
| 79 | 89 | $this->sumPoints -= $this->groupResults[$groupId]['group']->winPoints; |
| 80 | 90 | $this->groupResults[$groupId]['wins']--; |
| 81 | 91 | return $this; |
| 82 | 92 | } |
| 83 | 93 | public function addDraw(string $groupId = ''){ |
| 84 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 94 | + if (!isset($this->groupResults[$groupId])) { |
|
| 95 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 96 | + } |
|
| 85 | 97 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->drawPoints; |
| 86 | 98 | $this->sumPoints += $this->groupResults[$groupId]['group']->drawPoints; |
| 87 | 99 | $this->groupResults[$groupId]['draws']++; |
| 88 | 100 | return $this; |
| 89 | 101 | } |
| 90 | 102 | public function removeDraw(string $groupId = ''){ |
| 91 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 103 | + if (!isset($this->groupResults[$groupId])) { |
|
| 104 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 105 | + } |
|
| 92 | 106 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->drawPointsPoints; |
| 93 | 107 | $this->sumPoints -= $this->groupResults[$groupId]['group']->drawPoints; |
| 94 | 108 | $this->groupResults[$groupId]['draws']--; |
| 95 | 109 | return $this; |
| 96 | 110 | } |
| 97 | 111 | public function addLoss(string $groupId = ''){ |
| 98 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 112 | + if (!isset($this->groupResults[$groupId])) { |
|
| 113 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 114 | + } |
|
| 99 | 115 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->lostPoints; |
| 100 | 116 | $this->sumPoints += $this->groupResults[$groupId]['group']->lostPoints; |
| 101 | 117 | $this->groupResults[$groupId]['losses']++; |
| 102 | 118 | return $this; |
| 103 | 119 | } |
| 104 | 120 | public function removeLoss(string $groupId = ''){ |
| 105 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 121 | + if (!isset($this->groupResults[$groupId])) { |
|
| 122 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 123 | + } |
|
| 106 | 124 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->lostPoints; |
| 107 | 125 | $this->sumPoints -= $this->groupResults[$groupId]['group']->lostPoints; |
| 108 | 126 | $this->groupResults[$groupId]['losses']--; |
| 109 | 127 | return $this; |
| 110 | 128 | } |
| 111 | 129 | public function addSecond(string $groupId = ''){ |
| 112 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 130 | + if (!isset($this->groupResults[$groupId])) { |
|
| 131 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 132 | + } |
|
| 113 | 133 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->secondPoints; |
| 114 | 134 | $this->sumPoints += $this->groupResults[$groupId]['group']->secondPoints; |
| 115 | 135 | $this->groupResults[$groupId]['second']++; |
| 116 | 136 | return $this; |
| 117 | 137 | } |
| 118 | 138 | public function removeSecond(string $groupId = ''){ |
| 119 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 139 | + if (!isset($this->groupResults[$groupId])) { |
|
| 140 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 141 | + } |
|
| 120 | 142 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->secondPoints; |
| 121 | 143 | $this->sumPoints -= $this->groupResults[$groupId]['group']->secondPoints; |
| 122 | 144 | $this->groupResults[$groupId]['second']--; |
| 123 | 145 | return $this; |
| 124 | 146 | } |
| 125 | 147 | public function addThird(string $groupId = ''){ |
| 126 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 148 | + if (!isset($this->groupResults[$groupId])) { |
|
| 149 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 150 | + } |
|
| 127 | 151 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->thirdPoints; |
| 128 | 152 | $this->sumPoints += $this->groupResults[$groupId]['group']->thirdPoints; |
| 129 | 153 | $this->groupResults[$groupId]['third']++; |
| 130 | 154 | return $this; |
| 131 | 155 | } |
| 132 | 156 | public function removeThird(string $groupId = ''){ |
| 133 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 157 | + if (!isset($this->groupResults[$groupId])) { |
|
| 158 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 159 | + } |
|
| 134 | 160 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->thirdPoints; |
| 135 | 161 | $this->sumPoints -= $this->groupResults[$groupId]['group']->thirdPoints; |
| 136 | 162 | $this->groupResults[$groupId]['third']--; |
| 137 | 163 | return $this; |
| 138 | 164 | } |
| 139 | 165 | public function sumPoints(array $groupIds = []) { |
| 140 | - if (count($groupIds) === 0) return $this->sumPoints; |
|
| 166 | + if (count($groupIds) === 0) { |
|
| 167 | + return $this->sumPoints; |
|
| 168 | + } |
|
| 141 | 169 | $sum = 0; |
| 142 | 170 | foreach ($groupIds as $gid) { |
| 143 | - if (isset($this->groupResults[$gid])) $sum += $this->groupResults[$gid]['points']; |
|
| 171 | + if (isset($this->groupResults[$gid])) { |
|
| 172 | + $sum += $this->groupResults[$gid]['points']; |
|
| 173 | + } |
|
| 144 | 174 | } |
| 145 | 175 | return $sum; |
| 146 | 176 | } |
| 147 | 177 | public function sumScore(array $groupIds = []) { |
| 148 | - if (count($groupIds) === 0) return $this->sumScore; |
|
| 178 | + if (count($groupIds) === 0) { |
|
| 179 | + return $this->sumScore; |
|
| 180 | + } |
|
| 149 | 181 | $sum = 0; |
| 150 | 182 | foreach ($groupIds as $gid) { |
| 151 | - if (isset($this->groupResults[$gid])) $sum += $this->groupResults[$gid]['score']; |
|
| 183 | + if (isset($this->groupResults[$gid])) { |
|
| 184 | + $sum += $this->groupResults[$gid]['score']; |
|
| 185 | + } |
|
| 152 | 186 | } |
| 153 | 187 | return $sum; |
| 154 | 188 | } |
@@ -83,7 +83,9 @@ discard block |
||
| 83 | 83 | } |
| 84 | 84 | public function isPlayed(){ |
| 85 | 85 | foreach ($this->groups as $group) { |
| 86 | - if (!$group->isPlayed()) return false; |
|
| 86 | + if (!$group->isPlayed()) { |
|
| 87 | + return false; |
|
| 88 | + } |
|
| 87 | 89 | } |
| 88 | 90 | return true; |
| 89 | 91 | } |
@@ -92,10 +94,11 @@ discard block |
||
| 92 | 94 | foreach ($teams as $team) { |
| 93 | 95 | if ($team instanceof Team) { |
| 94 | 96 | $this->teams[] = $team; |
| 95 | - } |
|
| 96 | - elseif (gettype($team) === 'array') { |
|
| 97 | + } elseif (gettype($team) === 'array') { |
|
| 97 | 98 | foreach ($team as $team2) { |
| 98 | - if ($team2 instanceof Team) $this->teams[] = $team2; |
|
| 99 | + if ($team2 instanceof Team) { |
|
| 100 | + $this->teams[] = $team2; |
|
| 101 | + } |
|
| 99 | 102 | $team2->groupResults[$this->id] = [ |
| 100 | 103 | 'group' => $this, |
| 101 | 104 | 'points' => 0, |
@@ -107,8 +110,9 @@ discard block |
||
| 107 | 110 | 'third' => 0 |
| 108 | 111 | ]; |
| 109 | 112 | } |
| 113 | + } else { |
|
| 114 | + throw new \Exception('Trying to add team which is not an instance of Team class'); |
|
| 110 | 115 | } |
| 111 | - else throw new \Exception('Trying to add team which is not an instance of Team class'); |
|
| 112 | 116 | } |
| 113 | 117 | return $this; |
| 114 | 118 | } |
@@ -137,7 +141,9 @@ discard block |
||
| 137 | 141 | |
| 138 | 142 | public function splitTeams(...$groups) { |
| 139 | 143 | |
| 140 | - if (count($groups) === 0) $groups = $this->getGroups(); |
|
| 144 | + if (count($groups) === 0) { |
|
| 145 | + $groups = $this->getGroups(); |
|
| 146 | + } |
|
| 141 | 147 | |
| 142 | 148 | foreach ($groups as $key => $value) { |
| 143 | 149 | if (gettype($value) === 'array') { |
@@ -152,7 +158,9 @@ discard block |
||
| 152 | 158 | while (count($teams) > 0) { |
| 153 | 159 | foreach ($groups as $group) { |
| 154 | 160 | if ($group instanceof Group) { |
| 155 | - if (count($teams) > 0) $group->addTeam(array_shift($teams)); |
|
| 161 | + if (count($teams) > 0) { |
|
| 162 | + $group->addTeam(array_shift($teams)); |
|
| 163 | + } |
|
| 156 | 164 | } |
| 157 | 165 | } |
| 158 | 166 | } |
@@ -33,11 +33,17 @@ discard block |
||
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | public function progress(bool $blank = false) { |
| 36 | - if ($blank) $teams = $this->from->isPlayed() ? $this->from->sortTeams($this->filters) : $this->from->simulate($this->filters); |
|
| 37 | - else $teams = $this->from->sortTeams($this->filters); |
|
| 36 | + if ($blank) { |
|
| 37 | + $teams = $this->from->isPlayed() ? $this->from->sortTeams($this->filters) : $this->from->simulate($this->filters); |
|
| 38 | + } else { |
|
| 39 | + $teams = $this->from->sortTeams($this->filters); |
|
| 40 | + } |
|
| 38 | 41 | |
| 39 | - if (count($this->filters) === 0 || $this->len !== null || $this->start !== 0) $next = array_splice($teams, $this->start, ($this->len === null ? count($teams) : $this->len)); |
|
| 40 | - else $next = $teams; |
|
| 42 | + if (count($this->filters) === 0 || $this->len !== null || $this->start !== 0) { |
|
| 43 | + $next = array_splice($teams, $this->start, ($this->len === null ? count($teams) : $this->len)); |
|
| 44 | + } else { |
|
| 45 | + $next = $teams; |
|
| 46 | + } |
|
| 41 | 47 | |
| 42 | 48 | $i = 1; |
| 43 | 49 | |
@@ -45,12 +51,15 @@ discard block |
||
| 45 | 51 | if ($blank) { |
| 46 | 52 | $this->to->addTeam(new BlankTeam($this.' - '.$i, $team)); |
| 47 | 53 | $i++; |
| 54 | + } else { |
|
| 55 | + $team->sumPoints += $this->from->progressPoints; |
|
| 48 | 56 | } |
| 49 | - else $team->sumPoints += $this->from->progressPoints; |
|
| 50 | 57 | } |
| 51 | 58 | |
| 52 | 59 | $this->from->addProgressed($next); |
| 53 | - if (!$blank) $this->to->addTeam($next); |
|
| 60 | + if (!$blank) { |
|
| 61 | + $this->to->addTeam($next); |
|
| 62 | + } |
|
| 54 | 63 | return $this; |
| 55 | 64 | } |
| 56 | 65 | |
@@ -21,8 +21,11 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | public function addRound(Round ...$rounds){ |
| 23 | 23 | foreach ($rounds as $round) { |
| 24 | - if ($round instanceof Round) $this->rounds[] = $round; |
|
| 25 | - else throw new \Exception('Trying to add round which is not an instance of Round class.'); |
|
| 24 | + if ($round instanceof Round) { |
|
| 25 | + $this->rounds[] = $round; |
|
| 26 | + } else { |
|
| 27 | + throw new \Exception('Trying to add round which is not an instance of Round class.'); |
|
| 28 | + } |
|
| 26 | 29 | } |
| 27 | 30 | return $this; |
| 28 | 31 | } |
@@ -63,7 +66,9 @@ discard block |
||
| 63 | 66 | return $t; |
| 64 | 67 | } |
| 65 | 68 | public function getTeams() { |
| 66 | - if (count($this->teams) > 0) return $this->teams; |
|
| 69 | + if (count($this->teams) > 0) { |
|
| 70 | + return $this->teams; |
|
| 71 | + } |
|
| 67 | 72 | $teams = []; |
| 68 | 73 | foreach ($this->rounds as $round) { |
| 69 | 74 | $teams = array_merge($teams, $round->getTeams()); |
@@ -82,7 +87,9 @@ discard block |
||
| 82 | 87 | |
| 83 | 88 | public function splitTeams(...$rounds) { |
| 84 | 89 | |
| 85 | - if (count($rounds) === 0) $rounds = $this->getRounds(); |
|
| 90 | + if (count($rounds) === 0) { |
|
| 91 | + $rounds = $this->getRounds(); |
|
| 92 | + } |
|
| 86 | 93 | |
| 87 | 94 | $teams = $this->getTeams(); |
| 88 | 95 | shuffle($teams); |
@@ -102,7 +109,9 @@ discard block |
||
| 102 | 109 | |
| 103 | 110 | public function genGamesSimulate() { |
| 104 | 111 | $games = []; |
| 105 | - if (count($this->rounds) <= 0) throw new \Exception('There are no rounds to simulate games from.'); |
|
| 112 | + if (count($this->rounds) <= 0) { |
|
| 113 | + throw new \Exception('There are no rounds to simulate games from.'); |
|
| 114 | + } |
|
| 106 | 115 | foreach ($this->rounds as $round) { |
| 107 | 116 | $games = array_merge($games, $round->genGames()); |
| 108 | 117 | $round->simulate()->progress(true)->resetGames(); |
@@ -86,8 +86,11 @@ discard block |
||
| 86 | 86 | |
| 87 | 87 | public function addCategory(Category ...$categories){ |
| 88 | 88 | foreach ($categories as $category) { |
| 89 | - if ($category instanceof Category) $this->categories[] = $category; |
|
| 90 | - else throw new \Exception('Trying to add category which is not an instance of the Category class.'); |
|
| 89 | + if ($category instanceof Category) { |
|
| 90 | + $this->categories[] = $category; |
|
| 91 | + } else { |
|
| 92 | + throw new \Exception('Trying to add category which is not an instance of the Category class.'); |
|
| 93 | + } |
|
| 91 | 94 | } |
| 92 | 95 | return $this; |
| 93 | 96 | } |
@@ -102,8 +105,11 @@ discard block |
||
| 102 | 105 | |
| 103 | 106 | public function addRound(Round ...$rounds) { |
| 104 | 107 | foreach ($rounds as $round) { |
| 105 | - if ($round instanceof Round) $this->rounds[] = $round; |
|
| 106 | - else throw new \Exception('Trying to add round which is not an instance of the Round class.'); |
|
| 108 | + if ($round instanceof Round) { |
|
| 109 | + $this->rounds[] = $round; |
|
| 110 | + } else { |
|
| 111 | + throw new \Exception('Trying to add round which is not an instance of the Round class.'); |
|
| 112 | + } |
|
| 107 | 113 | } |
| 108 | 114 | return $this; |
| 109 | 115 | } |
@@ -143,7 +149,9 @@ discard block |
||
| 143 | 149 | $teams = array_merge($teams, $round->getTeams()); |
| 144 | 150 | } |
| 145 | 151 | $this->teams = \array_unique($teams); |
| 146 | - if ($ordered) $this->sortTeams($ordering); |
|
| 152 | + if ($ordered) { |
|
| 153 | + $this->sortTeams($ordering); |
|
| 154 | + } |
|
| 147 | 155 | return $this->teams; |
| 148 | 156 | } |
| 149 | 157 | public function sortTeams($ordering = \TournamentGenerator\Constants::POINTS) { |
@@ -166,7 +174,9 @@ discard block |
||
| 166 | 174 | |
| 167 | 175 | public function splitTeams(Round ...$wheres) { |
| 168 | 176 | |
| 169 | - if (count($wheres) === 0) $wheres = $this->getRounds(); |
|
| 177 | + if (count($wheres) === 0) { |
|
| 178 | + $wheres = $this->getRounds(); |
|
| 179 | + } |
|
| 170 | 180 | |
| 171 | 181 | foreach ($wheres as $key => $value) { |
| 172 | 182 | if (gettype($value) === 'array') { |
@@ -181,7 +191,9 @@ discard block |
||
| 181 | 191 | |
| 182 | 192 | while (count($teams) > 0) { |
| 183 | 193 | foreach ($wheres as $where) { |
| 184 | - if (count($teams) > 0) $where->addTeam(array_shift($teams)); |
|
| 194 | + if (count($teams) > 0) { |
|
| 195 | + $where->addTeam(array_shift($teams)); |
|
| 196 | + } |
|
| 185 | 197 | } |
| 186 | 198 | } |
| 187 | 199 | foreach ($wheres as $where) { |
@@ -193,13 +205,17 @@ discard block |
||
| 193 | 205 | public function genGamesSimulate(bool $returnTime = false) { |
| 194 | 206 | $games = Utilis\Simulator::simulateTournament($this); |
| 195 | 207 | |
| 196 | - if ($returnTime) return $this->getTournamentTime(); |
|
| 208 | + if ($returnTime) { |
|
| 209 | + return $this->getTournamentTime(); |
|
| 210 | + } |
|
| 197 | 211 | return $games; |
| 198 | 212 | } |
| 199 | 213 | public function genGamesSimulateReal(bool $returnTime = false) { |
| 200 | 214 | $games = Utilis\Simulator::simulateTournamentReal($this); |
| 201 | 215 | |
| 202 | - if ($returnTime) return $this->getTournamentTime(); |
|
| 216 | + if ($returnTime) { |
|
| 217 | + return $this->getTournamentTime(); |
|
| 218 | + } |
|
| 203 | 219 | return $games; |
| 204 | 220 | } |
| 205 | 221 | |