@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | return $this->id; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - public function addGroup(Group ...$groups){ |
|
| 43 | + public function addGroup(Group ...$groups) { |
|
| 44 | 44 | foreach ($groups as $group) { |
| 45 | 45 | $this->groups[] = $group; |
| 46 | 46 | } |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | $this->groups[] = $g->setSkip($this->allowSkip); |
| 52 | 52 | return $g; |
| 53 | 53 | } |
| 54 | - public function getGroups(){ |
|
| 54 | + public function getGroups() { |
|
| 55 | 55 | $this->orderGroups(); |
| 56 | 56 | return $this->groups; |
| 57 | 57 | } |
@@ -60,17 +60,17 @@ discard block |
||
| 60 | 60 | return array_map(function($a) { return $a->getId(); }, $this->groups); |
| 61 | 61 | } |
| 62 | 62 | public function orderGroups() { |
| 63 | - usort($this->groups, function($a, $b){ |
|
| 64 | - return $a->getOrder() - $b->getOrder(); |
|
| 63 | + usort($this->groups, function($a, $b) { |
|
| 64 | + return $a->getOrder()-$b->getOrder(); |
|
| 65 | 65 | }); |
| 66 | 66 | return $this->groups; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - public function allowSkip(){ |
|
| 69 | + public function allowSkip() { |
|
| 70 | 70 | $this->allowSkip = true; |
| 71 | 71 | return $this; |
| 72 | 72 | } |
| 73 | - public function disallowSkip(){ |
|
| 73 | + public function disallowSkip() { |
|
| 74 | 74 | $this->allowSkip = false; |
| 75 | 75 | return $this; |
| 76 | 76 | } |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | return $this->allowSkip; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - public function genGames(){ |
|
| 85 | + public function genGames() { |
|
| 86 | 86 | foreach ($this->groups as $group) { |
| 87 | 87 | $group->genGames(); |
| 88 | 88 | $this->games = array_merge($this->games, $group->orderGames()); |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | public function getGames() { |
| 93 | 93 | return $this->games; |
| 94 | 94 | } |
| 95 | - public function isPlayed(){ |
|
| 95 | + public function isPlayed() { |
|
| 96 | 96 | if (count($this->games) === 0) return false; |
| 97 | 97 | foreach ($this->groups as $group) { |
| 98 | 98 | if (!$group->isPlayed()) return false; |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | return $this; |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - public function progress(bool $blank = false){ |
|
| 157 | + public function progress(bool $blank = false) { |
|
| 158 | 158 | foreach ($this->groups as $group) { |
| 159 | 159 | $group->progress($blank); |
| 160 | 160 | } |
@@ -93,9 +93,13 @@ discard block |
||
| 93 | 93 | return $this->games; |
| 94 | 94 | } |
| 95 | 95 | public function isPlayed(){ |
| 96 | - if (count($this->games) === 0) return false; |
|
| 96 | + if (count($this->games) === 0) { |
|
| 97 | + return false; |
|
| 98 | + } |
|
| 97 | 99 | foreach ($this->groups as $group) { |
| 98 | - if (!$group->isPlayed()) return false; |
|
| 100 | + if (!$group->isPlayed()) { |
|
| 101 | + return false; |
|
| 102 | + } |
|
| 99 | 103 | } |
| 100 | 104 | return true; |
| 101 | 105 | } |
@@ -131,14 +135,18 @@ discard block |
||
| 131 | 135 | |
| 132 | 136 | public function splitTeams(Group ...$groups) { |
| 133 | 137 | |
| 134 | - if (count($groups) === 0) $groups = $this->getGroups(); |
|
| 138 | + if (count($groups) === 0) { |
|
| 139 | + $groups = $this->getGroups(); |
|
| 140 | + } |
|
| 135 | 141 | |
| 136 | 142 | $teams = $this->getTeams(); |
| 137 | 143 | shuffle($teams); |
| 138 | 144 | |
| 139 | 145 | while (count($teams) > 0) { |
| 140 | 146 | foreach ($groups as $group) { |
| 141 | - if (count($teams) > 0) $group->addTeam(array_shift($teams)); |
|
| 147 | + if (count($teams) > 0) { |
|
| 148 | + $group->addTeam(array_shift($teams)); |
|
| 149 | + } |
|
| 142 | 150 | } |
| 143 | 151 | } |
| 144 | 152 | return $this; |
@@ -80,10 +80,10 @@ |
||
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /** |
| 83 | - * $results = array ( |
|
| 84 | - * * team->getId() => team->score |
|
| 85 | - * ) |
|
| 86 | - */ |
|
| 83 | + * $results = array ( |
|
| 84 | + * * team->getId() => team->score |
|
| 85 | + * ) |
|
| 86 | + */ |
|
| 87 | 87 | public function setResults(array $results = []) { |
| 88 | 88 | if (count($this->results) === 0) $this->resetResults(); |
| 89 | 89 | arsort($results); |
@@ -66,14 +66,14 @@ discard block |
||
| 66 | 66 | if (count($error) > 0) throw new \Exception('Trying to add teams ('.count($error).') that are not instance of Team class'.PHP_EOL.print_r($error, true)); |
| 67 | 67 | return $this; |
| 68 | 68 | } |
| 69 | - public function getTeams(){ |
|
| 69 | + public function getTeams() { |
|
| 70 | 70 | return $this->teams; |
| 71 | 71 | } |
| 72 | - public function getTeamsIds(){ |
|
| 73 | - return array_map(function($a){ return $a->getId(); }, $this->teams); |
|
| 72 | + public function getTeamsIds() { |
|
| 73 | + return array_map(function($a) { return $a->getId(); }, $this->teams); |
|
| 74 | 74 | } |
| 75 | 75 | public function getTeam($id) { |
| 76 | - $key = array_search($id, array_map(function($a){ return $a->getId();}, $this->teams)); |
|
| 76 | + $key = array_search($id, array_map(function($a) { return $a->getId(); }, $this->teams)); |
|
| 77 | 77 | return ($key !== false ? $this->teams[$key] : false); |
| 78 | 78 | } |
| 79 | 79 | |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | return $this; |
| 111 | 111 | } |
| 112 | 112 | private function setResults2($i, $score, $results, $team) { |
| 113 | - if (count(array_filter($results, function($a) use ($score){return $a === $score;})) > 1) { |
|
| 113 | + if (count(array_filter($results, function($a) use ($score){return $a === $score; })) > 1) { |
|
| 114 | 114 | $this->drawIds[] = $team->getId(); |
| 115 | 115 | $team->addDraw($this->group->getId()); |
| 116 | 116 | $this->results[$team->getId()] += ['points' => $this->group->drawPoints, 'type' => 'draw']; |
@@ -33,11 +33,15 @@ discard block |
||
| 33 | 33 | $this->teams = $teams; |
| 34 | 34 | foreach ($this->teams as $team) { |
| 35 | 35 | foreach ($this->teams as $team2) { |
| 36 | - if ($team === $team2) continue; |
|
| 36 | + if ($team === $team2) { |
|
| 37 | + continue; |
|
| 38 | + } |
|
| 37 | 39 | $team->addGameWith($team2, $group); |
| 38 | 40 | } |
| 39 | 41 | } |
| 40 | - if (count($error) > 0) throw new \Exception('Trying to add teams ('.count($error).') that are not instance of Team class'.PHP_EOL.print_r($error, true)); |
|
| 42 | + if (count($error) > 0) { |
|
| 43 | + throw new \Exception('Trying to add teams ('.count($error).') that are not instance of Team class'.PHP_EOL.print_r($error, true)); |
|
| 44 | + } |
|
| 41 | 45 | } |
| 42 | 46 | |
| 43 | 47 | public function getGroup() { |
@@ -56,14 +60,18 @@ discard block |
||
| 56 | 60 | $team->addGame($this); |
| 57 | 61 | |
| 58 | 62 | foreach ($this->teams as $team2) { |
| 59 | - if ($team === $team2) continue; |
|
| 63 | + if ($team === $team2) { |
|
| 64 | + continue; |
|
| 65 | + } |
|
| 60 | 66 | if ($team instanceof Team) { |
| 61 | 67 | $team->addGameWith($team2, $this->group); |
| 62 | 68 | $team2->addGameWith($team, $this->group); |
| 63 | 69 | } |
| 64 | 70 | } |
| 65 | 71 | } |
| 66 | - if (count($error) > 0) throw new \Exception('Trying to add teams ('.count($error).') that are not instance of Team class'.PHP_EOL.print_r($error, true)); |
|
| 72 | + if (count($error) > 0) { |
|
| 73 | + throw new \Exception('Trying to add teams ('.count($error).') that are not instance of Team class'.PHP_EOL.print_r($error, true)); |
|
| 74 | + } |
|
| 67 | 75 | return $this; |
| 68 | 76 | } |
| 69 | 77 | public function getTeams(){ |
@@ -83,14 +91,20 @@ discard block |
||
| 83 | 91 | * ) |
| 84 | 92 | */ |
| 85 | 93 | public function setResults(array $results = []) { |
| 86 | - if (count($this->results) === 0) $this->resetResults(); |
|
| 94 | + if (count($this->results) === 0) { |
|
| 95 | + $this->resetResults(); |
|
| 96 | + } |
|
| 87 | 97 | arsort($results); |
| 88 | 98 | $inGame = /** @scrutinizer ignore-call */ $this->group->getInGame(); |
| 89 | 99 | $i = 1; |
| 90 | 100 | foreach ($results as $id => $score) { |
| 91 | - if (!is_numeric($score)) throw new \TypeError('Score passed to TournamentGenerator\Game::setResults() must be of the type numeric, '.gettype($score).' given'); |
|
| 101 | + if (!is_numeric($score)) { |
|
| 102 | + throw new \TypeError('Score passed to TournamentGenerator\Game::setResults() must be of the type numeric, '.gettype($score).' given'); |
|
| 103 | + } |
|
| 92 | 104 | $team = $this->getTeam($id); |
| 93 | - if (!$team instanceof Team) throw new \Exception('Couldn\'t find team with id of "'.$id.'"'); |
|
| 105 | + if (!$team instanceof Team) { |
|
| 106 | + throw new \Exception('Couldn\'t find team with id of "'.$id.'"'); |
|
| 107 | + } |
|
| 94 | 108 | $this->results[$team->getId()] = ['score' => $score]; |
| 95 | 109 | $team->addScore($score); |
| 96 | 110 | switch ($inGame) { |
@@ -114,13 +128,11 @@ discard block |
||
| 114 | 128 | $this->drawIds[] = $team->getId(); |
| 115 | 129 | $team->addDraw($this->group->getId()); |
| 116 | 130 | $this->results[$team->getId()] += ['points' => $this->group->drawPoints, 'type' => 'draw']; |
| 117 | - } |
|
| 118 | - elseif ($i === 1) { |
|
| 131 | + } elseif ($i === 1) { |
|
| 119 | 132 | $this->winId = $team->getId(); |
| 120 | 133 | $team->addWin($this->group->getId()); |
| 121 | 134 | $this->results[$team->getId()] += ['points' => $this->group->winPoints, 'type' => 'win']; |
| 122 | - } |
|
| 123 | - else { |
|
| 135 | + } else { |
|
| 124 | 136 | $this->lossId = $team->getId(); |
| 125 | 137 | $team->addLoss($this->group->getId()); |
| 126 | 138 | $this->results[$team->getId()] += ['points' => $this->group->lostPoints, 'type' => 'loss']; |
@@ -220,7 +232,9 @@ discard block |
||
| 220 | 232 | } |
| 221 | 233 | |
| 222 | 234 | public function isPlayed() { |
| 223 | - if (count($this->results) > 0) return true; |
|
| 235 | + if (count($this->results) > 0) { |
|
| 236 | + return true; |
|
| 237 | + } |
|
| 224 | 238 | return false; |
| 225 | 239 | } |
| 226 | 240 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | private $allowSkip = false; |
| 22 | 22 | |
| 23 | - function __construct(string $name = ''){ |
|
| 23 | + function __construct(string $name = '') { |
|
| 24 | 24 | $this->name = $name; |
| 25 | 25 | } |
| 26 | 26 | public function __toString() { |
@@ -63,16 +63,16 @@ discard block |
||
| 63 | 63 | public function getCategoryWait() { |
| 64 | 64 | return $this->expectedCategoryWait; |
| 65 | 65 | } |
| 66 | - public function getTournamentTime(){ |
|
| 66 | + public function getTournamentTime() { |
|
| 67 | 67 | $games = count($this->getGames()); |
| 68 | 68 | return $games*$this->expectedPlay+$games*$this->expectedGameWait+count($this->getRounds())*$this->expectedRoundWait+count($this->getCategories())*$this->expectedCategoryWait; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - public function allowSkip(){ |
|
| 71 | + public function allowSkip() { |
|
| 72 | 72 | $this->allowSkip = true; |
| 73 | 73 | return $this; |
| 74 | 74 | } |
| 75 | - public function disallowSkip(){ |
|
| 75 | + public function disallowSkip() { |
|
| 76 | 76 | $this->allowSkip = false; |
| 77 | 77 | return $this; |
| 78 | 78 | } |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | return $this->allowSkip; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - public function addCategory(Category ...$categories){ |
|
| 87 | + public function addCategory(Category ...$categories) { |
|
| 88 | 88 | foreach ($categories as $category) { |
| 89 | 89 | $this->categories[] = $category; |
| 90 | 90 | } |
@@ -141,7 +141,9 @@ discard block |
||
| 141 | 141 | $teams = array_merge($teams, $round->getTeams()); |
| 142 | 142 | } |
| 143 | 143 | $this->teams = \array_unique($teams); |
| 144 | - if ($ordered) $this->sortTeams($ordering); |
|
| 144 | + if ($ordered) { |
|
| 145 | + $this->sortTeams($ordering); |
|
| 146 | + } |
|
| 145 | 147 | return $this->teams; |
| 146 | 148 | } |
| 147 | 149 | public function sortTeams($ordering = \TournamentGenerator\Constants::POINTS) { |
@@ -164,14 +166,18 @@ discard block |
||
| 164 | 166 | |
| 165 | 167 | public function splitTeams(Round ...$wheres) { |
| 166 | 168 | |
| 167 | - if (count($wheres) === 0) $wheres = $this->getRounds(); |
|
| 169 | + if (count($wheres) === 0) { |
|
| 170 | + $wheres = $this->getRounds(); |
|
| 171 | + } |
|
| 168 | 172 | |
| 169 | 173 | $teams = $this->getTeams(); |
| 170 | 174 | shuffle($teams); |
| 171 | 175 | |
| 172 | 176 | while (count($teams) > 0) { |
| 173 | 177 | foreach ($wheres as $where) { |
| 174 | - if (count($teams) > 0) $where->addTeam(array_shift($teams)); |
|
| 178 | + if (count($teams) > 0) { |
|
| 179 | + $where->addTeam(array_shift($teams)); |
|
| 180 | + } |
|
| 175 | 181 | } |
| 176 | 182 | } |
| 177 | 183 | foreach ($wheres as $where) { |
@@ -183,13 +189,17 @@ discard block |
||
| 183 | 189 | public function genGamesSimulate(bool $returnTime = false) { |
| 184 | 190 | $games = Utilis\Simulator::simulateTournament($this); |
| 185 | 191 | |
| 186 | - if ($returnTime) return $this->getTournamentTime(); |
|
| 192 | + if ($returnTime) { |
|
| 193 | + return $this->getTournamentTime(); |
|
| 194 | + } |
|
| 187 | 195 | return $games; |
| 188 | 196 | } |
| 189 | 197 | public function genGamesSimulateReal(bool $returnTime = false) { |
| 190 | 198 | $games = Utilis\Simulator::simulateTournamentReal($this); |
| 191 | 199 | |
| 192 | - if ($returnTime) return $this->getTournamentTime(); |
|
| 200 | + if ($returnTime) { |
|
| 201 | + return $this->getTournamentTime(); |
|
| 202 | + } |
|
| 193 | 203 | return $games; |
| 194 | 204 | } |
| 195 | 205 | |
@@ -50,11 +50,11 @@ discard block |
||
| 50 | 50 | return $this->id; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - public function allowSkip(){ |
|
| 53 | + public function allowSkip() { |
|
| 54 | 54 | $this->generator->allowSkip(); |
| 55 | 55 | return $this; |
| 56 | 56 | } |
| 57 | - public function disallowSkip(){ |
|
| 57 | + public function disallowSkip() { |
|
| 58 | 58 | $this->generator->disallowSkip(); |
| 59 | 59 | return $this; |
| 60 | 60 | } |
@@ -161,8 +161,8 @@ discard block |
||
| 161 | 161 | } |
| 162 | 162 | } |
| 163 | 163 | public function addProgressed(...$teams) { |
| 164 | - $this->progressed = array_merge($this->progressed, array_filter($teams, function($a){return $a instanceof Team;})); |
|
| 165 | - foreach (array_filter($teams, function($a){return is_array($a);}) as $team) { |
|
| 164 | + $this->progressed = array_merge($this->progressed, array_filter($teams, function($a) {return $a instanceof Team; })); |
|
| 165 | + foreach (array_filter($teams, function($a) {return is_array($a); }) as $team) { |
|
| 166 | 166 | $this->progressed = array_merge($this->progressed, array_filter($team, function($a) { |
| 167 | 167 | return ($a instanceof Team); |
| 168 | 168 | })); |
@@ -183,11 +183,11 @@ discard block |
||
| 183 | 183 | $this->games[] = $g; |
| 184 | 184 | return $g; |
| 185 | 185 | } |
| 186 | - public function addGame(...$games){ |
|
| 187 | - $this->games = array_merge($this->games, array_filter($games, function($a){ return ($a instanceof Game); })); |
|
| 186 | + public function addGame(...$games) { |
|
| 187 | + $this->games = array_merge($this->games, array_filter($games, function($a) { return ($a instanceof Game); })); |
|
| 188 | 188 | |
| 189 | - foreach (array_filter($games, function($a){return is_array($a);}) as $key => $game) { |
|
| 190 | - $this->games = array_merge($this->games, array_filter($game, function($a){ return ($a instanceof Game); })); |
|
| 189 | + foreach (array_filter($games, function($a) {return is_array($a); }) as $key => $game) { |
|
| 190 | + $this->games = array_merge($this->games, array_filter($game, function($a) { return ($a instanceof Game); })); |
|
| 191 | 191 | } |
| 192 | 192 | return $this; |
| 193 | 193 | } |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | } |
| 210 | 210 | return $this; |
| 211 | 211 | } |
| 212 | - public function isPlayed(){ |
|
| 212 | + public function isPlayed() { |
|
| 213 | 213 | if (count($this->games) === 0) return false; |
| 214 | 214 | foreach ($this->games as $game) { |
| 215 | 215 | if (!$game->isPlayed()) return false; |
@@ -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 | } |
@@ -195,7 +199,9 @@ discard block |
||
| 195 | 199 | return $this->games; |
| 196 | 200 | } |
| 197 | 201 | public function orderGames() { |
| 198 | - if (count($this->games) <= 4) return $this->games; |
|
| 202 | + if (count($this->games) <= 4) { |
|
| 203 | + return $this->games; |
|
| 204 | + } |
|
| 199 | 205 | $this->games = $this->generator->orderGames(); |
| 200 | 206 | return $this->games; |
| 201 | 207 | } |
@@ -210,9 +216,13 @@ discard block |
||
| 210 | 216 | return $this; |
| 211 | 217 | } |
| 212 | 218 | public function isPlayed(){ |
| 213 | - if (count($this->games) === 0) return false; |
|
| 219 | + if (count($this->games) === 0) { |
|
| 220 | + return false; |
|
| 221 | + } |
|
| 214 | 222 | foreach ($this->games as $game) { |
| 215 | - if (!$game->isPlayed()) return false; |
|
| 223 | + if (!$game->isPlayed()) { |
|
| 224 | + return false; |
|
| 225 | + } |
|
| 216 | 226 | } |
| 217 | 227 | return true; |
| 218 | 228 | } |
@@ -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 | } |