@@ -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->id, '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, $filter)) unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
41 | + if (!$this->filterAnd($team, $filter)) { |
|
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, $filter)) unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
49 | + if (!$this->filterOr($team, $filter)) { |
|
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,19 +61,24 @@ discard block |
||
56 | 61 | if (gettype($value) === 'array') { |
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 | break; |
67 | 76 | } |
68 | 77 | continue; |
69 | - } |
|
70 | - elseif ($value instanceof TeamFilter) { |
|
71 | - if (!$value->validate($team, $this->group->id, 'sum', $this->group)) return false; |
|
78 | + } elseif ($value instanceof TeamFilter) { |
|
79 | + if (!$value->validate($team, $this->group->id, 'sum', $this->group)) { |
|
80 | + return false; |
|
81 | + } |
|
72 | 82 | continue; |
73 | 83 | } |
74 | 84 | throw new \Exception('Filer ['.$key.'] is not an instance of TeamFilter class'); |
@@ -80,19 +90,24 @@ discard block |
||
80 | 90 | if (gettype($value) === 'array') { |
81 | 91 | switch (strtolower($key)) { |
82 | 92 | case 'and': |
83 | - if ($this->filterAnd($team, $value)) return true; |
|
93 | + if ($this->filterAnd($team, $value)) { |
|
94 | + return true; |
|
95 | + } |
|
84 | 96 | break; |
85 | 97 | case 'or': |
86 | - if ($this->filterOr($team, $value)) return true; |
|
98 | + if ($this->filterOr($team, $value)) { |
|
99 | + return true; |
|
100 | + } |
|
87 | 101 | break; |
88 | 102 | default: |
89 | 103 | throw new \Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".'); |
90 | 104 | break; |
91 | 105 | } |
92 | 106 | continue; |
93 | - } |
|
94 | - elseif ($value instanceof TeamFilter) { |
|
95 | - if (!$value->validate($team, $this->group->id, 'sum', $this->group)) return true; |
|
107 | + } elseif ($value instanceof TeamFilter) { |
|
108 | + if (!$value->validate($team, $this->group->id, 'sum', $this->group)) { |
|
109 | + return true; |
|
110 | + } |
|
96 | 111 | continue; |
97 | 112 | } |
98 | 113 | throw new \Exception('Filer ['.$key.'] is not an instance of TeamFilter class'); |
@@ -18,11 +18,11 @@ discard block |
||
18 | 18 | $this->group = $group; |
19 | 19 | } |
20 | 20 | |
21 | - public function allowSkip(){ |
|
21 | + public function allowSkip() { |
|
22 | 22 | $this->allowSkip = true; |
23 | 23 | return $this; |
24 | 24 | } |
25 | - public function disallowSkip(){ |
|
25 | + public function disallowSkip() { |
|
26 | 26 | $this->allowSkip = false; |
27 | 27 | return $this; |
28 | 28 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | } |
46 | 46 | |
47 | 47 | public function setInGame(int $inGame) { |
48 | - if ($inGame < 2 || $inGame > 4) throw new \Exception('Expected 2,3 or 4 as inGame '.$inGame.' given'); |
|
48 | + if ($inGame < 2 || $inGame > 4) throw new \Exception('Expected 2,3 or 4 as inGame '.$inGame.' given'); |
|
49 | 49 | $this->inGame = $inGame; |
50 | 50 | return $this; |
51 | 51 | } |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | } |
94 | 94 | $games = array_merge($games, $gamesTemp); |
95 | 95 | } |
96 | - break;} |
|
96 | + break; } |
|
97 | 97 | case 4:{ |
98 | 98 | $teamsB = $teams; |
99 | 99 | $lockedTeam1 = array_shift($teamsB); |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | $lockedTeam1 = array_shift($teamsB); |
111 | 111 | } |
112 | 112 | $games[] = new \TournamentGenerator\Game(array_merge([$lockedTeam1], $teamsB), $this->group); |
113 | - break;} |
|
113 | + break; } |
|
114 | 114 | } |
115 | 115 | return $games; |
116 | 116 | } |
@@ -119,11 +119,11 @@ discard block |
||
119 | 119 | $discard = []; |
120 | 120 | shuffle($teams); |
121 | 121 | $count = count($teams); |
122 | - while (count($teams) % $this->inGame !== 0) { $discard[] = array_shift($teams); } |
|
122 | + while (count($teams)%$this->inGame !== 0) { $discard[] = array_shift($teams); } |
|
123 | 123 | |
124 | 124 | while (count($teams) > 0) { |
125 | 125 | $tInGame = []; |
126 | - for ($i=0; $i < $this->inGame; $i++) { $tInGame[] = array_shift($teams); } |
|
126 | + for ($i = 0; $i < $this->inGame; $i++) { $tInGame[] = array_shift($teams); } |
|
127 | 127 | $this->group->game($tInGame); |
128 | 128 | } |
129 | 129 | |
@@ -165,11 +165,11 @@ discard block |
||
165 | 165 | public static function circle_genGames2(array $teams = [], \tournamentGenerator\Group $group) { |
166 | 166 | $bracket = []; // ARRAY OF GAMES |
167 | 167 | |
168 | - if (count($teams) % 2 != 0) $teams[] = \DUMMY_TEAM; // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY |
|
168 | + if (count($teams)%2 != 0) $teams[] = \DUMMY_TEAM; // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY |
|
169 | 169 | |
170 | 170 | shuffle($teams); // SHUFFLE TEAMS FOR MORE RANDOMNESS |
171 | 171 | |
172 | - for ($i=0; $i < count($teams)-1; $i++) { |
|
172 | + for ($i = 0; $i < count($teams)-1; $i++) { |
|
173 | 173 | $bracket = array_merge($bracket, Generator::circle_saveBracket($teams, $group)); // SAVE CURRENT ROUND |
174 | 174 | |
175 | 175 | $teams = Generator::circle_rotateBracket($teams); // ROTATE TEAMS IN BRACKET |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | |
184 | 184 | $bracket = []; |
185 | 185 | |
186 | - for ($i=0; $i < count($teams)/2; $i++) { // GO THROUGH HALF OF THE TEAMS |
|
186 | + for ($i = 0; $i < count($teams)/2; $i++) { // GO THROUGH HALF OF THE TEAMS |
|
187 | 187 | |
188 | 188 | $home = $teams[$i]; |
189 | 189 | $reverse = array_reverse($teams); |
@@ -36,8 +36,11 @@ discard block |
||
36 | 36 | |
37 | 37 | |
38 | 38 | public function setType(/** @scrutinizer ignore-all */ string $type = \R_R) { |
39 | - if (in_array($type, \groupTypes)) $this->type = $type; |
|
40 | - else throw new \Exception('Unknown group type: '.$type); |
|
39 | + if (in_array($type, \groupTypes)) { |
|
40 | + $this->type = $type; |
|
41 | + } else { |
|
42 | + throw new \Exception('Unknown group type: '.$type); |
|
43 | + } |
|
41 | 44 | return $this; |
42 | 45 | } |
43 | 46 | public function getType() { |
@@ -45,7 +48,9 @@ discard block |
||
45 | 48 | } |
46 | 49 | |
47 | 50 | public function setInGame(int $inGame) { |
48 | - if ($inGame < 2 || $inGame > 4) throw new \Exception('Expected 2,3 or 4 as inGame '.$inGame.' given'); |
|
51 | + if ($inGame < 2 || $inGame > 4) { |
|
52 | + throw new \Exception('Expected 2,3 or 4 as inGame '.$inGame.' given'); |
|
53 | + } |
|
49 | 54 | $this->inGame = $inGame; |
50 | 55 | return $this; |
51 | 56 | } |
@@ -54,7 +59,9 @@ discard block |
||
54 | 59 | } |
55 | 60 | |
56 | 61 | public function setMaxSize(int $maxSize) { |
57 | - if ($maxSize < 2) throw new \Exception('Max group size has to be at least 2, '.$maxSize.' given'); |
|
62 | + if ($maxSize < 2) { |
|
63 | + throw new \Exception('Max group size has to be at least 2, '.$maxSize.' given'); |
|
64 | + } |
|
58 | 65 | $this->maxSize = $maxSize; |
59 | 66 | return $this; |
60 | 67 | } |
@@ -78,7 +85,9 @@ discard block |
||
78 | 85 | } |
79 | 86 | private function r_rGames(array $teams = []) { |
80 | 87 | $games = []; |
81 | - if (count($teams) === 0) $teams = $this->group->getTeams(); |
|
88 | + if (count($teams) === 0) { |
|
89 | + $teams = $this->group->getTeams(); |
|
90 | + } |
|
82 | 91 | switch ($this->inGame) { |
83 | 92 | case 2: |
84 | 93 | $games = Generator::circle_genGames2($teams, $this->group); |
@@ -115,7 +124,9 @@ discard block |
||
115 | 124 | return $games; |
116 | 125 | } |
117 | 126 | private function two_twoGames(array $teams = []) { |
118 | - if (count($teams) === 0) $teams = $this->group->getTeams(); |
|
127 | + if (count($teams) === 0) { |
|
128 | + $teams = $this->group->getTeams(); |
|
129 | + } |
|
119 | 130 | $discard = []; |
120 | 131 | shuffle($teams); |
121 | 132 | $count = count($teams); |
@@ -127,13 +138,17 @@ discard block |
||
127 | 138 | $this->group->game($tInGame); |
128 | 139 | } |
129 | 140 | |
130 | - if (count($discard) > 0 && !$this->allowSkip) throw new \Exception('Couldn\'t make games with all teams. Expected k*'.$this->inGame.' teams '.$count.' teams given - discarting '.count($discard).' teams ('.implode(', ', $discard).') in group '.$this->group.' - allow skip '.($this->allowSkip ? 'True' : 'False')); |
|
141 | + if (count($discard) > 0 && !$this->allowSkip) { |
|
142 | + throw new \Exception('Couldn\'t make games with all teams. Expected k*'.$this->inGame.' teams '.$count.' teams given - discarting '.count($discard).' teams ('.implode(', ', $discard).') in group '.$this->group.' - allow skip '.($this->allowSkip ? 'True' : 'False')); |
|
143 | + } |
|
131 | 144 | |
132 | 145 | return $this; |
133 | 146 | } |
134 | 147 | private function cond_splitGames(array $teams = []) { |
135 | 148 | $games = []; |
136 | - if (count($teams) === 0) $teams = $this->group->getTeams(); |
|
149 | + if (count($teams) === 0) { |
|
150 | + $teams = $this->group->getTeams(); |
|
151 | + } |
|
137 | 152 | if (count($teams) > $this->maxSize) { |
138 | 153 | $groups = array_chunk($teams, /** @scrutinizer ignore-type */ ceil(count($teams)/ceil(count($teams)/$this->maxSize))); // SPLIT TEAMS INTO GROUP OF MAXIMUM SIZE OF $this->maxSize |
139 | 154 | foreach ($groups as $group) { $games[] = $this->r_rGames($group); } |
@@ -144,7 +159,9 @@ discard block |
||
144 | 159 | while ($g > 0) { |
145 | 160 | foreach ($games as $key => $group) { |
146 | 161 | $this->group->addGame(array_shift($games[$key])); |
147 | - if (count($games[$key]) === 0) unset($games[$key]); |
|
162 | + if (count($games[$key]) === 0) { |
|
163 | + unset($games[$key]); |
|
164 | + } |
|
148 | 165 | $g--; |
149 | 166 | } |
150 | 167 | } |
@@ -165,7 +182,10 @@ discard block |
||
165 | 182 | public static function circle_genGames2(array $teams = [], \tournamentGenerator\Group $group) { |
166 | 183 | $bracket = []; // ARRAY OF GAMES |
167 | 184 | |
168 | - if (count($teams) % 2 != 0) $teams[] = \DUMMY_TEAM; // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY |
|
185 | + if (count($teams) % 2 != 0) { |
|
186 | + $teams[] = \DUMMY_TEAM; |
|
187 | + } |
|
188 | + // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY |
|
169 | 189 | |
170 | 190 | shuffle($teams); // SHUFFLE TEAMS FOR MORE RANDOMNESS |
171 | 191 | |
@@ -189,7 +209,10 @@ discard block |
||
189 | 209 | $reverse = array_reverse($teams); |
190 | 210 | $away = $reverse[$i]; |
191 | 211 | |
192 | - if (($home == \DUMMY_TEAM || $away == \DUMMY_TEAM)) continue; // SKIP WHEN DUMMY_TEAM IS PRESENT |
|
212 | + if (($home == \DUMMY_TEAM || $away == \DUMMY_TEAM)) { |
|
213 | + continue; |
|
214 | + } |
|
215 | + // SKIP WHEN DUMMY_TEAM IS PRESENT |
|
193 | 216 | |
194 | 217 | $bracket[] = new \TournamentGenerator\Game([$home, $away], $group); |
195 | 218 |