@@ -75,20 +75,26 @@ 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 getGameWith(Team $team = null, Group $group = null) { |
| 90 | 94 | if (isset($group)) { |
| 91 | - if (isset($team)) return $this->gamesWith[$group->getId()][$team->getId()]; |
|
| 95 | + if (isset($team)) { |
|
| 96 | + return $this->gamesWith[$group->getId()][$team->getId()]; |
|
| 97 | + } |
|
| 92 | 98 | return $this->gamesWith[$group->getId()]; |
| 93 | 99 | } |
| 94 | 100 | if (isset($team)) { |
@@ -97,25 +103,35 @@ discard block |
||
| 97 | 103 | $filter = array_filter($games, function($key) use ($team){ |
| 98 | 104 | return $key === $team->getId(); |
| 99 | 105 | }, ARRAY_FILTER_USE_KEY); |
| 100 | - if (count($filter) > 0) $return[$id] = $filter; |
|
| 106 | + if (count($filter) > 0) { |
|
| 107 | + $return[$id] = $filter; |
|
| 108 | + } |
|
| 101 | 109 | } |
| 102 | 110 | return $return; |
| 103 | 111 | } |
| 104 | 112 | return $this->gamesWith; |
| 105 | 113 | } |
| 106 | 114 | public function addGroup(Group $group) { |
| 107 | - if (!isset($this->games[$group->getId()])) $this->games[$group->getId()] = []; |
|
| 115 | + if (!isset($this->games[$group->getId()])) { |
|
| 116 | + $this->games[$group->getId()] = []; |
|
| 117 | + } |
|
| 108 | 118 | return $this; |
| 109 | 119 | } |
| 110 | 120 | public function addGame(Game $game) { |
| 111 | 121 | $group = $game->getGroup(); |
| 112 | - if (!isset($this->games[$group->getId()])) $this->games[$group->getId()] = []; |
|
| 122 | + if (!isset($this->games[$group->getId()])) { |
|
| 123 | + $this->games[$group->getId()] = []; |
|
| 124 | + } |
|
| 113 | 125 | $this->games[$group->getId()][] = $game; |
| 114 | 126 | return $this; |
| 115 | 127 | } |
| 116 | 128 | public function getGames(Group $group = null, $groupId = null) { |
| 117 | - if (isset($group) && isset($this->games[$group->getId()])) return $this->games[$group->getId()]; |
|
| 118 | - if (isset($groupId) && isset($this->games[$groupId])) return $this->games[$groupId]; |
|
| 129 | + if (isset($group) && isset($this->games[$group->getId()])) { |
|
| 130 | + return $this->games[$group->getId()]; |
|
| 131 | + } |
|
| 132 | + if (isset($groupId) && isset($this->games[$groupId])) { |
|
| 133 | + return $this->games[$groupId]; |
|
| 134 | + } |
|
| 119 | 135 | return $this->games; |
| 120 | 136 | } |
| 121 | 137 | |
@@ -127,14 +143,18 @@ discard block |
||
| 127 | 143 | } |
| 128 | 144 | |
| 129 | 145 | public function addWin(string $groupId = ''){ |
| 130 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 146 | + if (!isset($this->groupResults[$groupId])) { |
|
| 147 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 148 | + } |
|
| 131 | 149 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->winPoints; |
| 132 | 150 | $this->sumPoints += $this->groupResults[$groupId]['group']->winPoints; |
| 133 | 151 | $this->groupResults[$groupId]['wins']++; |
| 134 | 152 | return $this; |
| 135 | 153 | } |
| 136 | 154 | public function removeWin(string $groupId = ''){ |
| 137 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 155 | + if (!isset($this->groupResults[$groupId])) { |
|
| 156 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 157 | + } |
|
| 138 | 158 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->winPoints; |
| 139 | 159 | $this->sumPoints -= $this->groupResults[$groupId]['group']->winPoints; |
| 140 | 160 | $this->groupResults[$groupId]['wins']--; |
@@ -142,14 +162,18 @@ discard block |
||
| 142 | 162 | } |
| 143 | 163 | |
| 144 | 164 | public function addDraw(string $groupId = ''){ |
| 145 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 165 | + if (!isset($this->groupResults[$groupId])) { |
|
| 166 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 167 | + } |
|
| 146 | 168 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->drawPoints; |
| 147 | 169 | $this->sumPoints += $this->groupResults[$groupId]['group']->drawPoints; |
| 148 | 170 | $this->groupResults[$groupId]['draws']++; |
| 149 | 171 | return $this; |
| 150 | 172 | } |
| 151 | 173 | public function removeDraw(string $groupId = ''){ |
| 152 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 174 | + if (!isset($this->groupResults[$groupId])) { |
|
| 175 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 176 | + } |
|
| 153 | 177 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->drawPoints; |
| 154 | 178 | $this->sumPoints -= $this->groupResults[$groupId]['group']->drawPoints; |
| 155 | 179 | $this->groupResults[$groupId]['draws']--; |
@@ -157,14 +181,18 @@ discard block |
||
| 157 | 181 | } |
| 158 | 182 | |
| 159 | 183 | public function addLoss(string $groupId = ''){ |
| 160 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 184 | + if (!isset($this->groupResults[$groupId])) { |
|
| 185 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 186 | + } |
|
| 161 | 187 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->lostPoints; |
| 162 | 188 | $this->sumPoints += $this->groupResults[$groupId]['group']->lostPoints; |
| 163 | 189 | $this->groupResults[$groupId]['losses']++; |
| 164 | 190 | return $this; |
| 165 | 191 | } |
| 166 | 192 | public function removeLoss(string $groupId = ''){ |
| 167 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 193 | + if (!isset($this->groupResults[$groupId])) { |
|
| 194 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 195 | + } |
|
| 168 | 196 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->lostPoints; |
| 169 | 197 | $this->sumPoints -= $this->groupResults[$groupId]['group']->lostPoints; |
| 170 | 198 | $this->groupResults[$groupId]['losses']--; |
@@ -172,14 +200,18 @@ discard block |
||
| 172 | 200 | } |
| 173 | 201 | |
| 174 | 202 | public function addSecond(string $groupId = ''){ |
| 175 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 203 | + if (!isset($this->groupResults[$groupId])) { |
|
| 204 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 205 | + } |
|
| 176 | 206 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->secondPoints; |
| 177 | 207 | $this->sumPoints += $this->groupResults[$groupId]['group']->secondPoints; |
| 178 | 208 | $this->groupResults[$groupId]['second']++; |
| 179 | 209 | return $this; |
| 180 | 210 | } |
| 181 | 211 | public function removeSecond(string $groupId = ''){ |
| 182 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 212 | + if (!isset($this->groupResults[$groupId])) { |
|
| 213 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 214 | + } |
|
| 183 | 215 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->secondPoints; |
| 184 | 216 | $this->sumPoints -= $this->groupResults[$groupId]['group']->secondPoints; |
| 185 | 217 | $this->groupResults[$groupId]['second']--; |
@@ -187,14 +219,18 @@ discard block |
||
| 187 | 219 | } |
| 188 | 220 | |
| 189 | 221 | public function addThird(string $groupId = ''){ |
| 190 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 222 | + if (!isset($this->groupResults[$groupId])) { |
|
| 223 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 224 | + } |
|
| 191 | 225 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->thirdPoints; |
| 192 | 226 | $this->sumPoints += $this->groupResults[$groupId]['group']->thirdPoints; |
| 193 | 227 | $this->groupResults[$groupId]['third']++; |
| 194 | 228 | return $this; |
| 195 | 229 | } |
| 196 | 230 | public function removeThird(string $groupId = ''){ |
| 197 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 231 | + if (!isset($this->groupResults[$groupId])) { |
|
| 232 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 233 | + } |
|
| 198 | 234 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->thirdPoints; |
| 199 | 235 | $this->sumPoints -= $this->groupResults[$groupId]['group']->thirdPoints; |
| 200 | 236 | $this->groupResults[$groupId]['third']--; |
@@ -202,7 +238,9 @@ discard block |
||
| 202 | 238 | } |
| 203 | 239 | |
| 204 | 240 | public function sumPoints(array $groupIds = []) { |
| 205 | - if (count($groupIds) === 0) return $this->sumPoints; |
|
| 241 | + if (count($groupIds) === 0) { |
|
| 242 | + return $this->sumPoints; |
|
| 243 | + } |
|
| 206 | 244 | $sum = 0; |
| 207 | 245 | foreach ($groupIds as $gid) { |
| 208 | 246 | $sum += $this->groupResults[$gid]['points'] ?? 0; |
@@ -210,7 +248,9 @@ discard block |
||
| 210 | 248 | return $sum; |
| 211 | 249 | } |
| 212 | 250 | public function sumScore(array $groupIds = []) { |
| 213 | - if (count($groupIds) === 0) return $this->sumScore; |
|
| 251 | + if (count($groupIds) === 0) { |
|
| 252 | + return $this->sumScore; |
|
| 253 | + } |
|
| 214 | 254 | $sum = 0; |
| 215 | 255 | foreach ($groupIds as $gid) { |
| 216 | 256 | $sum += $this->groupResults[$gid]['score'] ?? 0; |
@@ -25,8 +25,7 @@ discard block |
||
| 25 | 25 | if (gettype($filter) === 'array') { |
| 26 | 26 | $this->filterMulti($teams, $filter, $key); |
| 27 | 27 | continue; |
| 28 | - } |
|
| 29 | - elseif ($filter instanceof TeamFilter) { |
|
| 28 | + } elseif ($filter instanceof TeamFilter) { |
|
| 30 | 29 | $teams = array_filter($teams, function($team) use ($filter) {return $filter->validate($team, [$this->group->getId()], 'sum', $this->group); }); |
| 31 | 30 | continue; |
| 32 | 31 | } |
@@ -39,12 +38,18 @@ discard block |
||
| 39 | 38 | switch (strtolower($how)) { |
| 40 | 39 | case 'and': |
| 41 | 40 | foreach ($teams as $tkey => $team) { |
| 42 | - if (!$this->filterAnd($team, $filters)) unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
| 41 | + if (!$this->filterAnd($team, $filters)) { |
|
| 42 | + unset($teams[$tkey]); |
|
| 43 | + } |
|
| 44 | + // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
| 43 | 45 | } |
| 44 | 46 | return true; |
| 45 | 47 | case 'or': |
| 46 | 48 | foreach ($teams as $tkey => $team) { |
| 47 | - if (!$this->filterOr($team, $filters)) unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
| 49 | + if (!$this->filterOr($team, $filters)) { |
|
| 50 | + unset($teams[$tkey]); |
|
| 51 | + } |
|
| 52 | + // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
| 48 | 53 | } |
| 49 | 54 | return true; |
| 50 | 55 | } |
@@ -56,18 +61,23 @@ discard block |
||
| 56 | 61 | if (is_array($value)) { |
| 57 | 62 | switch (strtolower($key)) { |
| 58 | 63 | case 'and': |
| 59 | - if (!$this->filterAnd($team, $value)) return false; |
|
| 64 | + if (!$this->filterAnd($team, $value)) { |
|
| 65 | + return false; |
|
| 66 | + } |
|
| 60 | 67 | break; |
| 61 | 68 | case 'or': |
| 62 | - if (!$this->filterOr($team, $value)) return false; |
|
| 69 | + if (!$this->filterOr($team, $value)) { |
|
| 70 | + return false; |
|
| 71 | + } |
|
| 63 | 72 | break; |
| 64 | 73 | default: |
| 65 | 74 | throw new \Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".'); |
| 66 | 75 | } |
| 67 | 76 | continue; |
| 68 | - } |
|
| 69 | - elseif ($value instanceof TeamFilter) { |
|
| 70 | - if (!$value->validate($team, $this->group->getId(), 'sum', $this->group)) return false; |
|
| 77 | + } elseif ($value instanceof TeamFilter) { |
|
| 78 | + if (!$value->validate($team, $this->group->getId(), 'sum', $this->group)) { |
|
| 79 | + return false; |
|
| 80 | + } |
|
| 71 | 81 | continue; |
| 72 | 82 | } |
| 73 | 83 | throw new \Exception('Filter ['.$key.'] is not an instance of TeamFilter class'); |
@@ -79,18 +89,23 @@ discard block |
||
| 79 | 89 | if (is_array($value)) { |
| 80 | 90 | switch (strtolower($key)) { |
| 81 | 91 | case 'and': |
| 82 | - if ($this->filterAnd($team, $value)) return true; |
|
| 92 | + if ($this->filterAnd($team, $value)) { |
|
| 93 | + return true; |
|
| 94 | + } |
|
| 83 | 95 | break; |
| 84 | 96 | case 'or': |
| 85 | - if ($this->filterOr($team, $value)) return true; |
|
| 97 | + if ($this->filterOr($team, $value)) { |
|
| 98 | + return true; |
|
| 99 | + } |
|
| 86 | 100 | break; |
| 87 | 101 | default: |
| 88 | 102 | throw new \Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".'); |
| 89 | 103 | } |
| 90 | 104 | continue; |
| 91 | - } |
|
| 92 | - elseif ($value instanceof TeamFilter) { |
|
| 93 | - if ($value->validate($team, $this->group->getId(), 'sum', $this->group)) return true; |
|
| 105 | + } elseif ($value instanceof TeamFilter) { |
|
| 106 | + if ($value->validate($team, $this->group->getId(), 'sum', $this->group)) { |
|
| 107 | + return true; |
|
| 108 | + } |
|
| 94 | 109 | continue; |
| 95 | 110 | } |
| 96 | 111 | throw new \Exception('Filter ['.$key.'] is not an instance of TeamFilter class'); |
@@ -43,14 +43,14 @@ |
||
| 43 | 43 | |
| 44 | 44 | private $groups = []; |
| 45 | 45 | |
| 46 | - function __construct(string $what = 'points', string $how = '>', $val = 0, array $groups = []){ |
|
| 46 | + function __construct(string $what = 'points', string $how = '>', $val = 0, array $groups = []) { |
|
| 47 | 47 | if (!in_array(strtolower($what), ['points', 'score', 'wins', 'draws', 'losses', 'second', 'third', 'team', 'notprogressed', 'progressed'])) throw new \Exception('Trying to filter unexisting type ('.$what.')'); |
| 48 | 48 | $this->what = strtolower($what); |
| 49 | 49 | if (!in_array($how, ['>', '<', '>=', '<=', '=', '!='])) throw new \Exception('Trying to filter with unexisting operator ('.$how.')'); |
| 50 | 50 | $this->how = $how; |
| 51 | 51 | if (!(gettype($val) === 'integer' && strtolower($what) !== 'team') && !($val instanceof Team && strtolower($what) === 'team')) throw new \Exception('Unsupported filter value type ('.typeof($val).')'); |
| 52 | 52 | $this->val = $val; |
| 53 | - $this->groups = array_map(function($a) { return $a->getId(); }, array_filter($groups, function($a) {return ($a instanceof Group);})); |
|
| 53 | + $this->groups = array_map(function($a) { return $a->getId(); }, array_filter($groups, function($a) {return ($a instanceof Group); })); |
|
| 54 | 54 | } |
| 55 | 55 | public function __toString() { |
| 56 | 56 | return 'Filter: '.$this->what.' '.($this->what !== 'notprogressed' && $this->what !== 'progressed' ? $this->how.' '.$this->val : ''); |
@@ -44,11 +44,17 @@ discard block |
||
| 44 | 44 | private $groups = []; |
| 45 | 45 | |
| 46 | 46 | function __construct(string $what = 'points', string $how = '>', $val = 0, array $groups = []){ |
| 47 | - if (!in_array(strtolower($what), ['points', 'score', 'wins', 'draws', 'losses', 'second', 'third', 'team', 'notprogressed', 'progressed'])) throw new \Exception('Trying to filter unexisting type ('.$what.')'); |
|
| 47 | + if (!in_array(strtolower($what), ['points', 'score', 'wins', 'draws', 'losses', 'second', 'third', 'team', 'notprogressed', 'progressed'])) { |
|
| 48 | + throw new \Exception('Trying to filter unexisting type ('.$what.')'); |
|
| 49 | + } |
|
| 48 | 50 | $this->what = strtolower($what); |
| 49 | - if (!in_array($how, ['>', '<', '>=', '<=', '=', '!='])) throw new \Exception('Trying to filter with unexisting operator ('.$how.')'); |
|
| 51 | + if (!in_array($how, ['>', '<', '>=', '<=', '=', '!='])) { |
|
| 52 | + throw new \Exception('Trying to filter with unexisting operator ('.$how.')'); |
|
| 53 | + } |
|
| 50 | 54 | $this->how = $how; |
| 51 | - if (!(gettype($val) === 'integer' && strtolower($what) !== 'team') && !($val instanceof Team && strtolower($what) === 'team')) throw new \Exception('Unsupported filter value type ('.typeof($val).')'); |
|
| 55 | + if (!(gettype($val) === 'integer' && strtolower($what) !== 'team') && !($val instanceof Team && strtolower($what) === 'team')) { |
|
| 56 | + throw new \Exception('Unsupported filter value type ('.typeof($val).')'); |
|
| 57 | + } |
|
| 52 | 58 | $this->val = $val; |
| 53 | 59 | $this->groups = array_map(function($a) { return $a->getId(); }, array_filter($groups, function($a) {return ($a instanceof Group);})); |
| 54 | 60 | } |
@@ -57,11 +63,17 @@ discard block |
||
| 57 | 63 | } |
| 58 | 64 | |
| 59 | 65 | public function validate(Team $team, $groupsId, string $operation = 'sum', Group $from = null) { |
| 60 | - if (count($this->groups) > 0) $groupsId = array_unique(array_merge($this->groups, (gettype($groupsId) === 'array' ? $groupsId : [$groupsId])), SORT_REGULAR); |
|
| 66 | + if (count($this->groups) > 0) { |
|
| 67 | + $groupsId = array_unique(array_merge($this->groups, (gettype($groupsId) === 'array' ? $groupsId : [$groupsId])), SORT_REGULAR); |
|
| 68 | + } |
|
| 61 | 69 | |
| 62 | - if ($this->what == 'team') return ($this->how === '!=' ? !$this->validateTeam($team) : $this->validateTeam($team)); |
|
| 63 | - elseif ($this->what == 'notprogressed') return !$this->validateProgressed($team, $from); |
|
| 64 | - elseif ($this->what == 'progressed') return $this->validateProgressed($team, $from); |
|
| 70 | + if ($this->what == 'team') { |
|
| 71 | + return ($this->how === '!=' ? !$this->validateTeam($team) : $this->validateTeam($team)); |
|
| 72 | + } elseif ($this->what == 'notprogressed') { |
|
| 73 | + return !$this->validateProgressed($team, $from); |
|
| 74 | + } elseif ($this->what == 'progressed') { |
|
| 75 | + return $this->validateProgressed($team, $from); |
|
| 76 | + } |
|
| 65 | 77 | |
| 66 | 78 | return $this->validateCalc($team, $groupsId, $operation); |
| 67 | 79 | } |
@@ -70,11 +82,15 @@ discard block |
||
| 70 | 82 | return $this->val === $team; |
| 71 | 83 | } |
| 72 | 84 | private function validateProgressed(Team $team, Group $from = null) { |
| 73 | - if ($from === null) throw new \Exception('Group $from was not defined.'); |
|
| 85 | + if ($from === null) { |
|
| 86 | + throw new \Exception('Group $from was not defined.'); |
|
| 87 | + } |
|
| 74 | 88 | return $from->isProgressed($team); |
| 75 | 89 | } |
| 76 | 90 | private function validateCalc(Team $team, array $groupsId, string $operation = 'sum') { |
| 77 | - if (gettype($groupsId) === 'array' && !in_array(strtolower($operation), ['sum', 'avg', 'max', 'min'])) throw new \Exception('Unknown operation of '.$operation.'. Only "sum", "avg", "min", "max" possible.'); |
|
| 91 | + if (gettype($groupsId) === 'array' && !in_array(strtolower($operation), ['sum', 'avg', 'max', 'min'])) { |
|
| 92 | + throw new \Exception('Unknown operation of '.$operation.'. Only "sum", "avg", "min", "max" possible.'); |
|
| 93 | + } |
|
| 78 | 94 | $comp = 0; |
| 79 | 95 | $return = false; |
| 80 | 96 | switch (strtolower($operation)) { |
@@ -106,7 +122,9 @@ discard block |
||
| 106 | 122 | private function calcSum(Team $team, array $groupsId) { |
| 107 | 123 | $sum = 0; |
| 108 | 124 | foreach ($groupsId as $id) { |
| 109 | - if (isset($team->groupResults[$id])) $sum += $team->groupResults[$id][$this->what]; |
|
| 125 | + if (isset($team->groupResults[$id])) { |
|
| 126 | + $sum += $team->groupResults[$id][$this->what]; |
|
| 127 | + } |
|
| 110 | 128 | } |
| 111 | 129 | return $sum; |
| 112 | 130 | } |
@@ -116,12 +134,16 @@ discard block |
||
| 116 | 134 | $games = $team->getGames(null, reset($groupsId)); |
| 117 | 135 | foreach ($games as $game) { |
| 118 | 136 | $results = $game->getResults()[$team->getId()]; |
| 119 | - if (($results[$this->what] > $max || $max === null)) $max = $results[$this->what]; |
|
| 137 | + if (($results[$this->what] > $max || $max === null)) { |
|
| 138 | + $max = $results[$this->what]; |
|
| 139 | + } |
|
| 120 | 140 | } |
| 121 | 141 | return $max; |
| 122 | 142 | } |
| 123 | 143 | foreach ($groupsId as $id) { |
| 124 | - if (isset($team->groupResults[$id]) && ($team->groupResults[$id][$this->what] > $max || $max === null)) $max = $team->groupResults[$id][$this->what]; |
|
| 144 | + if (isset($team->groupResults[$id]) && ($team->groupResults[$id][$this->what] > $max || $max === null)) { |
|
| 145 | + $max = $team->groupResults[$id][$this->what]; |
|
| 146 | + } |
|
| 125 | 147 | } |
| 126 | 148 | return $max; |
| 127 | 149 | } |
@@ -131,12 +153,16 @@ discard block |
||
| 131 | 153 | $games = $team->getGames(null, reset($groupsId)); |
| 132 | 154 | foreach ($games as $game) { |
| 133 | 155 | $results = $game->getResults()[$team->getId()]; |
| 134 | - if (($results[$this->what] < $min || $min === null)) $min = $results[$this->what]; |
|
| 156 | + if (($results[$this->what] < $min || $min === null)) { |
|
| 157 | + $min = $results[$this->what]; |
|
| 158 | + } |
|
| 135 | 159 | } |
| 136 | 160 | return $min; |
| 137 | 161 | } |
| 138 | 162 | foreach ($groupsId as $id) { |
| 139 | - if (isset($team->groupResults[$id]) && ($team->groupResults[$id][$this->what] < $min || $min === null)) $min = $team->groupResults[$id][$this->what]; |
|
| 163 | + if (isset($team->groupResults[$id]) && ($team->groupResults[$id][$this->what] < $min || $min === null)) { |
|
| 164 | + $min = $team->groupResults[$id][$this->what]; |
|
| 165 | + } |
|
| 140 | 166 | } |
| 141 | 167 | return $min; |
| 142 | 168 | } |