@@ -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; |