@@ -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 | } |
@@ -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; |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | $this->setId(isset($id) ? $id : uniqid()); |
19 | 19 | } |
20 | 20 | |
21 | - public function addGroup(Group ...$groups){ |
|
21 | + public function addGroup(Group ...$groups) { |
|
22 | 22 | foreach ($groups as $group) { |
23 | 23 | $this->groups[] = $group; |
24 | 24 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | $this->groups[] = $g->setSkip($this->allowSkip); |
30 | 30 | return $g; |
31 | 31 | } |
32 | - public function getGroups(){ |
|
32 | + public function getGroups() { |
|
33 | 33 | $this->orderGroups(); |
34 | 34 | return $this->groups; |
35 | 35 | } |
@@ -38,17 +38,17 @@ discard block |
||
38 | 38 | return array_map(function($a) { return $a->getId(); }, $this->groups); |
39 | 39 | } |
40 | 40 | public function orderGroups() { |
41 | - usort($this->groups, function($a, $b){ |
|
42 | - return $a->getOrder() - $b->getOrder(); |
|
41 | + usort($this->groups, function($a, $b) { |
|
42 | + return $a->getOrder()-$b->getOrder(); |
|
43 | 43 | }); |
44 | 44 | return $this->groups; |
45 | 45 | } |
46 | 46 | |
47 | - public function allowSkip(){ |
|
47 | + public function allowSkip() { |
|
48 | 48 | $this->allowSkip = true; |
49 | 49 | return $this; |
50 | 50 | } |
51 | - public function disallowSkip(){ |
|
51 | + public function disallowSkip() { |
|
52 | 52 | $this->allowSkip = false; |
53 | 53 | return $this; |
54 | 54 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | return $this->allowSkip; |
61 | 61 | } |
62 | 62 | |
63 | - public function genGames(){ |
|
63 | + public function genGames() { |
|
64 | 64 | foreach ($this->groups as $group) { |
65 | 65 | $group->genGames(); |
66 | 66 | $this->games = array_merge($this->games, $group->orderGames()); |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | public function getGames() { |
71 | 71 | return $this->games; |
72 | 72 | } |
73 | - public function isPlayed(){ |
|
73 | + public function isPlayed() { |
|
74 | 74 | if (count($this->games) === 0) return false; |
75 | 75 | foreach ($this->groups as $group) { |
76 | 76 | if (!$group->isPlayed()) return false; |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | return $this; |
123 | 123 | } |
124 | 124 | |
125 | - public function progress(bool $blank = false){ |
|
125 | + public function progress(bool $blank = false) { |
|
126 | 126 | foreach ($this->groups as $group) { |
127 | 127 | $group->progress($blank); |
128 | 128 | } |
@@ -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 |
@@ -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 | } |
@@ -28,11 +28,11 @@ discard block |
||
28 | 28 | $this->setId(isset($id) ? $id : uniqid()); |
29 | 29 | } |
30 | 30 | |
31 | - public function allowSkip(){ |
|
31 | + public function allowSkip() { |
|
32 | 32 | $this->generator->allowSkip(); |
33 | 33 | return $this; |
34 | 34 | } |
35 | - public function disallowSkip(){ |
|
35 | + public function disallowSkip() { |
|
36 | 36 | $this->generator->disallowSkip(); |
37 | 37 | return $this; |
38 | 38 | } |
@@ -139,9 +139,9 @@ discard block |
||
139 | 139 | } |
140 | 140 | } |
141 | 141 | public function addProgressed(...$teams) { |
142 | - $this->progressed = array_merge($this->progressed, array_map(function ($a) {return $a->getId();}, array_filter($teams, function($a){return $a instanceof Team;}))); |
|
143 | - foreach (array_filter($teams, function($a){return is_array($a);}) as $team) { |
|
144 | - $this->progressed = array_merge($this->progressed, array_map(function ($a) {return $a->getId();}, array_filter($team, function($a) { |
|
142 | + $this->progressed = array_merge($this->progressed, array_map(function($a) {return $a->getId(); }, array_filter($teams, function($a) {return $a instanceof Team; }))); |
|
143 | + foreach (array_filter($teams, function($a) {return is_array($a); }) as $team) { |
|
144 | + $this->progressed = array_merge($this->progressed, array_map(function($a) {return $a->getId(); }, array_filter($team, function($a) { |
|
145 | 145 | return ($a instanceof Team); |
146 | 146 | }))); |
147 | 147 | } |
@@ -161,11 +161,11 @@ discard block |
||
161 | 161 | $this->games[] = $g; |
162 | 162 | return $g; |
163 | 163 | } |
164 | - public function addGame(...$games){ |
|
165 | - $this->games = array_merge($this->games, array_filter($games, function($a){ return ($a instanceof Game); })); |
|
164 | + public function addGame(...$games) { |
|
165 | + $this->games = array_merge($this->games, array_filter($games, function($a) { return ($a instanceof Game); })); |
|
166 | 166 | |
167 | - foreach (array_filter($games, function($a){return is_array($a);}) as $key => $game) { |
|
168 | - $this->games = array_merge($this->games, array_filter($game, function($a){ return ($a instanceof Game); })); |
|
167 | + foreach (array_filter($games, function($a) {return is_array($a); }) as $key => $game) { |
|
168 | + $this->games = array_merge($this->games, array_filter($game, function($a) { return ($a instanceof Game); })); |
|
169 | 169 | } |
170 | 170 | return $this; |
171 | 171 | } |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | } |
188 | 188 | return $this; |
189 | 189 | } |
190 | - public function isPlayed(){ |
|
190 | + public function isPlayed() { |
|
191 | 191 | if (count($this->games) === 0) return false; |
192 | 192 | foreach ($this->games as $game) { |
193 | 193 | if (!$game->isPlayed()) return false; |
@@ -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'); |
@@ -52,7 +52,9 @@ discard block |
||
52 | 52 | private static function calcSum(\TournamentGenerator\Team $team, array $groupsId) { |
53 | 53 | $sum = 0; |
54 | 54 | foreach ($groupsId as $id) { |
55 | - if (isset($team->groupResults[$id])) $sum += $team->groupResults[$id][self::$what]; |
|
55 | + if (isset($team->groupResults[$id])) { |
|
56 | + $sum += $team->groupResults[$id][self::$what]; |
|
57 | + } |
|
56 | 58 | } |
57 | 59 | return $sum; |
58 | 60 | } |
@@ -62,12 +64,16 @@ discard block |
||
62 | 64 | $games = $team->getGames(null, reset($groupsId)); |
63 | 65 | foreach ($games as $game) { |
64 | 66 | $results = $game->getResults()[$team->getId()]; |
65 | - if (($results[self::$what] > $max || $max === null)) $max = $results[self::$what]; |
|
67 | + if (($results[self::$what] > $max || $max === null)) { |
|
68 | + $max = $results[self::$what]; |
|
69 | + } |
|
66 | 70 | } |
67 | 71 | return $max; |
68 | 72 | } |
69 | 73 | foreach ($groupsId as $id) { |
70 | - if (isset($team->groupResults[$id]) && ($team->groupResults[$id][self::$what] > $max || $max === null)) $max = $team->groupResults[$id][self::$what]; |
|
74 | + if (isset($team->groupResults[$id]) && ($team->groupResults[$id][self::$what] > $max || $max === null)) { |
|
75 | + $max = $team->groupResults[$id][self::$what]; |
|
76 | + } |
|
71 | 77 | } |
72 | 78 | return $max; |
73 | 79 | } |
@@ -77,12 +83,16 @@ discard block |
||
77 | 83 | $games = $team->getGames(null, reset($groupsId)); |
78 | 84 | foreach ($games as $game) { |
79 | 85 | $results = $game->getResults()[$team->getId()]; |
80 | - if (($results[self::$what] < $min || $min === null)) $min = $results[self::$what]; |
|
86 | + if (($results[self::$what] < $min || $min === null)) { |
|
87 | + $min = $results[self::$what]; |
|
88 | + } |
|
81 | 89 | } |
82 | 90 | return $min; |
83 | 91 | } |
84 | 92 | foreach ($groupsId as $id) { |
85 | - if (isset($team->groupResults[$id]) && ($team->groupResults[$id][self::$what] < $min || $min === null)) $min = $team->groupResults[$id][self::$what]; |
|
93 | + if (isset($team->groupResults[$id]) && ($team->groupResults[$id][self::$what] < $min || $min === null)) { |
|
94 | + $min = $team->groupResults[$id][self::$what]; |
|
95 | + } |
|
86 | 96 | } |
87 | 97 | return $min; |
88 | 98 | } |
@@ -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 ('.gettype($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 ('.gettype($val).')'); |
|
55 | + if (!(gettype($val) === 'integer' && strtolower($what) !== 'team') && !($val instanceof Team && strtolower($what) === 'team')) { |
|
56 | + throw new \Exception('Unsupported filter value type ('.gettype($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 | |
79 | 95 | return Utilis\FilterComparator::compare($operation, $this->val, $this->how, $this->what, $team, $groupsId); |
80 | 96 |