@@ -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 | } |
@@ -66,17 +66,17 @@ discard block |
||
| 66 | 66 | switch ($this->type) { |
| 67 | 67 | case \R_R:{ |
| 68 | 68 | $this->group->addGame($this->r_rGames()); |
| 69 | - break;} |
|
| 69 | + break; } |
|
| 70 | 70 | case \TWO_TWO: |
| 71 | 71 | $teams = $this->group->getTeams(); |
| 72 | 72 | $discard = []; |
| 73 | 73 | shuffle($teams); |
| 74 | 74 | $count = count($teams); |
| 75 | - while (count($teams) % $this->inGame !== 0) { $discard[] = array_shift($teams); } |
|
| 75 | + while (count($teams)%$this->inGame !== 0) { $discard[] = array_shift($teams); } |
|
| 76 | 76 | |
| 77 | 77 | while (count($teams) > 0) { |
| 78 | 78 | $tInGame = []; |
| 79 | - for ($i=0; $i < $this->inGame; $i++) { $tInGame[] = array_shift($teams); } |
|
| 79 | + for ($i = 0; $i < $this->inGame; $i++) { $tInGame[] = array_shift($teams); } |
|
| 80 | 80 | $this->group->game($tInGame); |
| 81 | 81 | } |
| 82 | 82 | |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | } |
| 123 | 123 | $games = array_merge($games, $gamesTemp); |
| 124 | 124 | } |
| 125 | - break;} |
|
| 125 | + break; } |
|
| 126 | 126 | case 4:{ |
| 127 | 127 | $teamsB = $teams; |
| 128 | 128 | $lockedTeam1 = array_shift($teamsB); |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | $lockedTeam1 = array_shift($teamsB); |
| 140 | 140 | } |
| 141 | 141 | $games[] = new \TournamentGenerator\Game(array_merge([$lockedTeam1], $teamsB), $this->group); |
| 142 | - break;} |
|
| 142 | + break; } |
|
| 143 | 143 | } |
| 144 | 144 | return $games; |
| 145 | 145 | } |
@@ -154,11 +154,11 @@ discard block |
||
| 154 | 154 | public static function circle_genGames2(array $teams = [], \tournamentGenerator\Group $group) { |
| 155 | 155 | $bracket = []; // ARRAY OF GAMES |
| 156 | 156 | |
| 157 | - if (count($teams) % 2 != 0) $teams[] = \DUMMY_TEAM; // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY |
|
| 157 | + if (count($teams)%2 != 0) $teams[] = \DUMMY_TEAM; // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY |
|
| 158 | 158 | |
| 159 | 159 | shuffle($teams); // SHUFFLE TEAMS FOR MORE RANDOMNESS |
| 160 | 160 | |
| 161 | - for ($i=0; $i < count($teams)-1; $i++) { |
|
| 161 | + for ($i = 0; $i < count($teams)-1; $i++) { |
|
| 162 | 162 | $bracket = array_merge($bracket, Generator::circle_saveBracket($teams, $group)); // SAVE CURRENT ROUND |
| 163 | 163 | |
| 164 | 164 | $teams = Generator::circle_rotateBracket($teams); // ROTATE TEAMS IN BRACKET |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | |
| 173 | 173 | $bracket = []; |
| 174 | 174 | |
| 175 | - for ($i=0; $i < count($teams)/2; $i++) { // GO THROUGH HALF OF THE TEAMS |
|
| 175 | + for ($i = 0; $i < count($teams)/2; $i++) { // GO THROUGH HALF OF THE TEAMS |
|
| 176 | 176 | |
| 177 | 177 | $home = $teams[$i]; |
| 178 | 178 | $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 | } |
@@ -80,7 +87,9 @@ discard block |
||
| 80 | 87 | $this->group->game($tInGame); |
| 81 | 88 | } |
| 82 | 89 | |
| 83 | - 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')); |
|
| 90 | + if (count($discard) > 0 && !$this->allowSkip) { |
|
| 91 | + 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')); |
|
| 92 | + } |
|
| 84 | 93 | break; |
| 85 | 94 | case \COND_SPLIT: |
| 86 | 95 | $games = []; |
@@ -95,19 +104,24 @@ discard block |
||
| 95 | 104 | while ($g > 0) { |
| 96 | 105 | foreach ($games as $key => $group) { |
| 97 | 106 | $this->group->addGame(array_shift($games[$key])); |
| 98 | - if (count($games[$key]) === 0) unset($games[$key]); |
|
| 107 | + if (count($games[$key]) === 0) { |
|
| 108 | + unset($games[$key]); |
|
| 109 | + } |
|
| 99 | 110 | $g--; |
| 100 | 111 | } |
| 101 | 112 | } |
| 113 | + } else { |
|
| 114 | + $this->group->addGame($this->r_rGames()); |
|
| 102 | 115 | } |
| 103 | - else $this->group->addGame($this->r_rGames()); |
|
| 104 | 116 | break; |
| 105 | 117 | } |
| 106 | 118 | return $this->group->getGames(); |
| 107 | 119 | } |
| 108 | 120 | public function r_rGames(array $teams = []) { |
| 109 | 121 | $games = []; |
| 110 | - if (count($teams) === 0) $teams = $this->group->getTeams(); |
|
| 122 | + if (count($teams) === 0) { |
|
| 123 | + $teams = $this->group->getTeams(); |
|
| 124 | + } |
|
| 111 | 125 | switch ($this->inGame) { |
| 112 | 126 | case 2: |
| 113 | 127 | $games = Generator::circle_genGames2($teams, $this->group); |
@@ -154,7 +168,10 @@ discard block |
||
| 154 | 168 | public static function circle_genGames2(array $teams = [], \tournamentGenerator\Group $group) { |
| 155 | 169 | $bracket = []; // ARRAY OF GAMES |
| 156 | 170 | |
| 157 | - if (count($teams) % 2 != 0) $teams[] = \DUMMY_TEAM; // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY |
|
| 171 | + if (count($teams) % 2 != 0) { |
|
| 172 | + $teams[] = \DUMMY_TEAM; |
|
| 173 | + } |
|
| 174 | + // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY |
|
| 158 | 175 | |
| 159 | 176 | shuffle($teams); // SHUFFLE TEAMS FOR MORE RANDOMNESS |
| 160 | 177 | |
@@ -178,7 +195,10 @@ discard block |
||
| 178 | 195 | $reverse = array_reverse($teams); |
| 179 | 196 | $away = $reverse[$i]; |
| 180 | 197 | |
| 181 | - if (($home == \DUMMY_TEAM || $away == \DUMMY_TEAM)) continue; // SKIP WHEN DUMMY_TEAM IS PRESENT |
|
| 198 | + if (($home == \DUMMY_TEAM || $away == \DUMMY_TEAM)) { |
|
| 199 | + continue; |
|
| 200 | + } |
|
| 201 | + // SKIP WHEN DUMMY_TEAM IS PRESENT |
|
| 182 | 202 | |
| 183 | 203 | $bracket[] = new \TournamentGenerator\Game([$home, $away], $group); |
| 184 | 204 | |
@@ -18,13 +18,13 @@ discard block |
||
| 18 | 18 | if ($a->groupResults[$group->id]["points"] === $b->groupResults[$group->id]["points"]) return ($a->groupResults[$group->id]["score"] > $b->groupResults[$group->id]["score"] ? -1 : 1); |
| 19 | 19 | return ($a->groupResults[$group->id]["points"] > $b->groupResults[$group->id]["points"] ? -1 : 1); |
| 20 | 20 | }); |
| 21 | - break;} |
|
| 21 | + break; } |
|
| 22 | 22 | case \SCORE:{ |
| 23 | 23 | uasort($teams, function($a, $b) use ($group) { |
| 24 | 24 | if ($a->groupResults[$group->id]["score"] === $b->groupResults[$group->id]["score"]) return 0; |
| 25 | 25 | return ($a->groupResults[$group->id]["score"] > $b->groupResults[$group->id]["score"] ? -1 : 1); |
| 26 | 26 | }); |
| 27 | - break;} |
|
| 27 | + break; } |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | return $teams; |
@@ -41,13 +41,13 @@ discard block |
||
| 41 | 41 | if ($a->sumPoints($groupsIds) === $b->sumPoints($groupsIds)) return ($a->sumScore($groupsIds) > $b->sumScore($groupsIds) ? -1 : 1); |
| 42 | 42 | return ($a->sumPoints($groupsIds) > $b->sumPoints($groupsIds) ? -1 : 1); |
| 43 | 43 | }); |
| 44 | - break;} |
|
| 44 | + break; } |
|
| 45 | 45 | case \SCORE:{ |
| 46 | 46 | uasort($teams, function($a, $b) use ($groupsIds) { |
| 47 | 47 | if ($a->sumScore($groupsIds) === $b->sumScore($groupsIds)) return 0; |
| 48 | 48 | return ($a->sumScore($groupsIds) > $b->sumScore($groupsIds) ? -1 : 1); |
| 49 | 49 | }); |
| 50 | - break;} |
|
| 50 | + break; } |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | return $teams; |
@@ -9,19 +9,27 @@ discard block |
||
| 9 | 9 | { |
| 10 | 10 | |
| 11 | 11 | public static function sortGroup(array &$teams, \TournamentGenerator\Group $group, string $ordering = POINTS) { |
| 12 | - if (!in_array($ordering, orderingTypes)) throw new \Exception('Unknown ordering type `'.$ordering.'`'); |
|
| 12 | + if (!in_array($ordering, orderingTypes)) { |
|
| 13 | + throw new \Exception('Unknown ordering type `'.$ordering.'`'); |
|
| 14 | + } |
|
| 13 | 15 | |
| 14 | 16 | switch ($ordering) { |
| 15 | 17 | case \POINTS:{ |
| 16 | 18 | uasort($teams, function($a, $b) use ($group) { |
| 17 | - if ($a->groupResults[$group->id]["points"] === $b->groupResults[$group->id]["points"] && $a->groupResults[$group->id]["score"] === $b->groupResults[$group->id]["score"]) return 0; |
|
| 18 | - if ($a->groupResults[$group->id]["points"] === $b->groupResults[$group->id]["points"]) return ($a->groupResults[$group->id]["score"] > $b->groupResults[$group->id]["score"] ? -1 : 1); |
|
| 19 | + if ($a->groupResults[$group->id]["points"] === $b->groupResults[$group->id]["points"] && $a->groupResults[$group->id]["score"] === $b->groupResults[$group->id]["score"]) { |
|
| 20 | + return 0; |
|
| 21 | + } |
|
| 22 | + if ($a->groupResults[$group->id]["points"] === $b->groupResults[$group->id]["points"]) { |
|
| 23 | + return ($a->groupResults[$group->id]["score"] > $b->groupResults[$group->id]["score"] ? -1 : 1); |
|
| 24 | + } |
|
| 19 | 25 | return ($a->groupResults[$group->id]["points"] > $b->groupResults[$group->id]["points"] ? -1 : 1); |
| 20 | 26 | }); |
| 21 | 27 | break;} |
| 22 | 28 | case \SCORE:{ |
| 23 | 29 | uasort($teams, function($a, $b) use ($group) { |
| 24 | - if ($a->groupResults[$group->id]["score"] === $b->groupResults[$group->id]["score"]) return 0; |
|
| 30 | + if ($a->groupResults[$group->id]["score"] === $b->groupResults[$group->id]["score"]) { |
|
| 31 | + return 0; |
|
| 32 | + } |
|
| 25 | 33 | return ($a->groupResults[$group->id]["score"] > $b->groupResults[$group->id]["score"] ? -1 : 1); |
| 26 | 34 | }); |
| 27 | 35 | break;} |
@@ -30,21 +38,29 @@ discard block |
||
| 30 | 38 | return $teams; |
| 31 | 39 | } |
| 32 | 40 | public static function sortRound(array &$teams, \TournamentGenerator\Round $round, string $ordering = POINTS) { |
| 33 | - if (!in_array($ordering, orderingTypes)) throw new \Exception('Unknown ordering type `'.$ordering.'`'); |
|
| 41 | + if (!in_array($ordering, orderingTypes)) { |
|
| 42 | + throw new \Exception('Unknown ordering type `'.$ordering.'`'); |
|
| 43 | + } |
|
| 34 | 44 | |
| 35 | 45 | $groupsIds = $round->getGroupsIds(); |
| 36 | 46 | |
| 37 | 47 | switch ($ordering) { |
| 38 | 48 | case \POINTS:{ |
| 39 | 49 | uasort($teams, function($a, $b) use ($groupsIds) { |
| 40 | - if ($a->sumPoints($groupsIds) === $b->sumPoints($groupsIds) && $a->sumScore($groupsIds) === $b->sumScore($groupsIds)) return 0; |
|
| 41 | - if ($a->sumPoints($groupsIds) === $b->sumPoints($groupsIds)) return ($a->sumScore($groupsIds) > $b->sumScore($groupsIds) ? -1 : 1); |
|
| 50 | + if ($a->sumPoints($groupsIds) === $b->sumPoints($groupsIds) && $a->sumScore($groupsIds) === $b->sumScore($groupsIds)) { |
|
| 51 | + return 0; |
|
| 52 | + } |
|
| 53 | + if ($a->sumPoints($groupsIds) === $b->sumPoints($groupsIds)) { |
|
| 54 | + return ($a->sumScore($groupsIds) > $b->sumScore($groupsIds) ? -1 : 1); |
|
| 55 | + } |
|
| 42 | 56 | return ($a->sumPoints($groupsIds) > $b->sumPoints($groupsIds) ? -1 : 1); |
| 43 | 57 | }); |
| 44 | 58 | break;} |
| 45 | 59 | case \SCORE:{ |
| 46 | 60 | uasort($teams, function($a, $b) use ($groupsIds) { |
| 47 | - if ($a->sumScore($groupsIds) === $b->sumScore($groupsIds)) return 0; |
|
| 61 | + if ($a->sumScore($groupsIds) === $b->sumScore($groupsIds)) { |
|
| 62 | + return 0; |
|
| 63 | + } |
|
| 48 | 64 | return ($a->sumScore($groupsIds) > $b->sumScore($groupsIds) ? -1 : 1); |
| 49 | 65 | }); |
| 50 | 66 | break;} |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | return $this->name; |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | - public function addGroup(Group ...$groups){ |
|
| 26 | + public function addGroup(Group ...$groups) { |
|
| 27 | 27 | foreach ($groups as $group) { |
| 28 | 28 | if ($group instanceof Group) $this->groups[] = $group; |
| 29 | 29 | else throw new \Exception('Trying to add group which is not an instance of Group class.'); |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | $this->groups[] = $g->setSkip($this->allowSkip); |
| 36 | 36 | return $g; |
| 37 | 37 | } |
| 38 | - public function getGroups(){ |
|
| 38 | + public function getGroups() { |
|
| 39 | 39 | $this->orderGroups(); |
| 40 | 40 | return $this->groups; |
| 41 | 41 | } |
@@ -44,16 +44,16 @@ discard block |
||
| 44 | 44 | return array_map(function($a) { return $a->id; }, $this->groups); |
| 45 | 45 | } |
| 46 | 46 | public function orderGroups() { |
| 47 | - usort($this->groups, function($a, $b){ |
|
| 48 | - return $a->order - $b->order; |
|
| 47 | + usort($this->groups, function($a, $b) { |
|
| 48 | + return $a->order-$b->order; |
|
| 49 | 49 | }); |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - public function allowSkip(){ |
|
| 52 | + public function allowSkip() { |
|
| 53 | 53 | $this->allowSkip = true; |
| 54 | 54 | return $this; |
| 55 | 55 | } |
| 56 | - public function disallowSkip(){ |
|
| 56 | + public function disallowSkip() { |
|
| 57 | 57 | $this->allowSkip = false; |
| 58 | 58 | return $this; |
| 59 | 59 | } |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | return $this->allowSkip; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - public function genGames(){ |
|
| 68 | + public function genGames() { |
|
| 69 | 69 | foreach ($this->groups as $group) { |
| 70 | 70 | $group->genGames(); |
| 71 | 71 | $this->games = array_merge($this->games, $group->orderGames()); |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | public function getGames() { |
| 76 | 76 | return $this->games; |
| 77 | 77 | } |
| 78 | - public function isPlayed(){ |
|
| 78 | + public function isPlayed() { |
|
| 79 | 79 | foreach ($this->groups as $group) { |
| 80 | 80 | if (!$group->isPlayed()) return false; |
| 81 | 81 | } |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | |
| 85 | 85 | public function addTeam(...$teams) { |
| 86 | 86 | foreach ($teams as $team) { |
| 87 | - if ($team instanceof Team) { |
|
| 87 | + if ($team instanceof Team) { |
|
| 88 | 88 | $this->teams[] = $team; |
| 89 | 89 | } |
| 90 | 90 | elseif (gettype($team) === 'array') { |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | return $this; |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - public function progress(bool $blank = false){ |
|
| 156 | + public function progress(bool $blank = false) { |
|
| 157 | 157 | foreach ($this->groups as $group) { |
| 158 | 158 | $group->progress($blank); |
| 159 | 159 | } |
@@ -25,8 +25,11 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | public function addGroup(Group ...$groups){ |
| 27 | 27 | foreach ($groups as $group) { |
| 28 | - if ($group instanceof Group) $this->groups[] = $group; |
|
| 29 | - else throw new \Exception('Trying to add group which is not an instance of Group class.'); |
|
| 28 | + if ($group instanceof Group) { |
|
| 29 | + $this->groups[] = $group; |
|
| 30 | + } else { |
|
| 31 | + throw new \Exception('Trying to add group which is not an instance of Group class.'); |
|
| 32 | + } |
|
| 30 | 33 | } |
| 31 | 34 | return $this; |
| 32 | 35 | } |
@@ -77,7 +80,9 @@ discard block |
||
| 77 | 80 | } |
| 78 | 81 | public function isPlayed(){ |
| 79 | 82 | foreach ($this->groups as $group) { |
| 80 | - if (!$group->isPlayed()) return false; |
|
| 83 | + if (!$group->isPlayed()) { |
|
| 84 | + return false; |
|
| 85 | + } |
|
| 81 | 86 | } |
| 82 | 87 | return true; |
| 83 | 88 | } |
@@ -86,10 +91,11 @@ discard block |
||
| 86 | 91 | foreach ($teams as $team) { |
| 87 | 92 | if ($team instanceof Team) { |
| 88 | 93 | $this->teams[] = $team; |
| 89 | - } |
|
| 90 | - elseif (gettype($team) === 'array') { |
|
| 94 | + } elseif (gettype($team) === 'array') { |
|
| 91 | 95 | foreach ($team as $team2) { |
| 92 | - if ($team2 instanceof Team) $this->teams[] = $team2; |
|
| 96 | + if ($team2 instanceof Team) { |
|
| 97 | + $this->teams[] = $team2; |
|
| 98 | + } |
|
| 93 | 99 | $team2->groupResults[$this->id] = [ |
| 94 | 100 | 'group' => $this, |
| 95 | 101 | 'points' => 0, |
@@ -101,8 +107,9 @@ discard block |
||
| 101 | 107 | 'third' => 0 |
| 102 | 108 | ]; |
| 103 | 109 | } |
| 110 | + } else { |
|
| 111 | + throw new \Exception('Trying to add team which is not an instance of Team class'); |
|
| 104 | 112 | } |
| 105 | - else throw new \Exception('Trying to add team which is not an instance of Team class'); |
|
| 106 | 113 | } |
| 107 | 114 | return $this; |
| 108 | 115 | } |
@@ -131,7 +138,9 @@ discard block |
||
| 131 | 138 | |
| 132 | 139 | public function splitTeams(...$groups) { |
| 133 | 140 | |
| 134 | - if (count($groups) === 0) $groups = $this->getGroups(); |
|
| 141 | + if (count($groups) === 0) { |
|
| 142 | + $groups = $this->getGroups(); |
|
| 143 | + } |
|
| 135 | 144 | |
| 136 | 145 | foreach ($groups as $key => $value) { |
| 137 | 146 | if (gettype($value) === 'array') { |
@@ -146,7 +155,9 @@ discard block |
||
| 146 | 155 | while (count($teams) > 0) { |
| 147 | 156 | foreach ($groups as $group) { |
| 148 | 157 | if ($group instanceof Group) { |
| 149 | - if (count($teams) > 0) $group->addTeam(array_shift($teams)); |
|
| 158 | + if (count($teams) > 0) { |
|
| 159 | + $group->addTeam(array_shift($teams)); |
|
| 160 | + } |
|
| 150 | 161 | } |
| 151 | 162 | } |
| 152 | 163 | } |
@@ -162,7 +173,9 @@ discard block |
||
| 162 | 173 | |
| 163 | 174 | public function simulate() { |
| 164 | 175 | foreach ($this->groups as $group) { |
| 165 | - if ($group->isPlayed()) continue; |
|
| 176 | + if ($group->isPlayed()) { |
|
| 177 | + continue; |
|
| 178 | + } |
|
| 166 | 179 | $group->simulate([], false); |
| 167 | 180 | } |
| 168 | 181 | return $this; |
@@ -26,27 +26,31 @@ discard block |
||
| 26 | 26 | switch (strtolower($key)) { |
| 27 | 27 | case 'and': |
| 28 | 28 | foreach ($teams as $tkey => $team) { |
| 29 | - if (!$this->filterAnd($team, $filter)) unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
| 29 | + if (!$this->filterAnd($team, $filter)) { |
|
| 30 | + unset($teams[$tkey]); |
|
| 31 | + } |
|
| 32 | + // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
| 30 | 33 | } |
| 31 | 34 | break; |
| 32 | 35 | case 'or': |
| 33 | 36 | foreach ($teams as $tkey => $team) { |
| 34 | - if (!$this->filterOr($team, $filter)) unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
| 37 | + if (!$this->filterOr($team, $filter)) { |
|
| 38 | + unset($teams[$tkey]); |
|
| 39 | + } |
|
| 40 | + // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
| 35 | 41 | } |
| 36 | 42 | break; |
| 37 | 43 | default: |
| 38 | 44 | throw new \Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".'); |
| 39 | 45 | break; |
| 40 | 46 | } |
| 41 | - } |
|
| 42 | - elseif ($filter instanceof TeamFilter) { |
|
| 47 | + } elseif ($filter instanceof TeamFilter) { |
|
| 43 | 48 | foreach ($teams as $tkey => $team) { |
| 44 | 49 | if (!$filter->validate($team, $this->id, 'sum', $this)) { |
| 45 | 50 | unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
| 46 | 51 | } |
| 47 | 52 | } |
| 48 | - } |
|
| 49 | - else { |
|
| 53 | + } else { |
|
| 50 | 54 | throw new \Exception('Filer ['.$key.'] is not an instance of TeamFilter class'); |
| 51 | 55 | } |
| 52 | 56 | } |
@@ -58,20 +62,24 @@ discard block |
||
| 58 | 62 | if (gettype($value) === 'array') { |
| 59 | 63 | switch (strtolower($key)) { |
| 60 | 64 | case 'and': |
| 61 | - if ($this->filterAnd($team, $value)) return false; |
|
| 65 | + if ($this->filterAnd($team, $value)) { |
|
| 66 | + return false; |
|
| 67 | + } |
|
| 62 | 68 | break; |
| 63 | 69 | case 'or': |
| 64 | - if ($this->filterOr($team, $value)) return false; |
|
| 70 | + if ($this->filterOr($team, $value)) { |
|
| 71 | + return false; |
|
| 72 | + } |
|
| 65 | 73 | break; |
| 66 | 74 | default: |
| 67 | 75 | throw new \Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".'); |
| 68 | 76 | break; |
| 69 | 77 | } |
| 70 | - } |
|
| 71 | - elseif ($value instanceof TeamFilter) { |
|
| 72 | - if (!$value->validate($team, $this->id, 'sum', $this)) return false; |
|
| 73 | - } |
|
| 74 | - else { |
|
| 78 | + } elseif ($value instanceof TeamFilter) { |
|
| 79 | + if (!$value->validate($team, $this->id, 'sum', $this)) { |
|
| 80 | + return false; |
|
| 81 | + } |
|
| 82 | + } else { |
|
| 75 | 83 | throw new \Exception('Filer ['.$key.'] is not an instance of TeamFilter class'); |
| 76 | 84 | } |
| 77 | 85 | } |
@@ -82,20 +90,24 @@ discard block |
||
| 82 | 90 | if (gettype($value) === 'array') { |
| 83 | 91 | switch (strtolower($key)) { |
| 84 | 92 | case 'and': |
| 85 | - if ($this->filterAnd($team, $value)) return true; |
|
| 93 | + if ($this->filterAnd($team, $value)) { |
|
| 94 | + return true; |
|
| 95 | + } |
|
| 86 | 96 | break; |
| 87 | 97 | case 'or': |
| 88 | - if ($this->filterOr($team, $value)) return true; |
|
| 98 | + if ($this->filterOr($team, $value)) { |
|
| 99 | + return true; |
|
| 100 | + } |
|
| 89 | 101 | break; |
| 90 | 102 | default: |
| 91 | 103 | throw new \Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".'); |
| 92 | 104 | break; |
| 93 | 105 | } |
| 94 | - } |
|
| 95 | - elseif ($value instanceof TeamFilter) { |
|
| 96 | - if (!$value->validate($team, $this->id, 'sum', $this)) return true; |
|
| 97 | - } |
|
| 98 | - else { |
|
| 106 | + } elseif ($value instanceof TeamFilter) { |
|
| 107 | + if (!$value->validate($team, $this->id, 'sum', $this)) { |
|
| 108 | + return true; |
|
| 109 | + } |
|
| 110 | + } else { |
|
| 99 | 111 | throw new \Exception('Filer ['.$key.'] is not an instance of TeamFilter class'); |
| 100 | 112 | } |
| 101 | 113 | } |
@@ -57,11 +57,11 @@ discard block |
||
| 57 | 57 | return 'Group '.$this->name; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - public function allowSkip(){ |
|
| 60 | + public function allowSkip() { |
|
| 61 | 61 | $this->generator->allowSkip(); |
| 62 | 62 | return $this; |
| 63 | 63 | } |
| 64 | - public function disallowSkip(){ |
|
| 64 | + public function disallowSkip() { |
|
| 65 | 65 | $this->generator->disallowSkip(); |
| 66 | 66 | return $this; |
| 67 | 67 | } |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | |
| 76 | 76 | public function addTeam(...$teams) { |
| 77 | 77 | foreach ($teams as $team) { |
| 78 | - if ($team instanceof Team) { |
|
| 78 | + if ($team instanceof Team) { |
|
| 79 | 79 | $this->teams[] = $team; |
| 80 | 80 | $team->groupResults[$this->id] = [ |
| 81 | 81 | 'group' => $this, |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | $this->games[] = $g; |
| 219 | 219 | return $g; |
| 220 | 220 | } |
| 221 | - public function addGame(...$games){ |
|
| 221 | + public function addGame(...$games) { |
|
| 222 | 222 | foreach ($games as $key => $game) { |
| 223 | 223 | if (gettype($game) === 'array') { |
| 224 | 224 | unset($games[$key]); |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | } |
| 263 | 263 | return $this; |
| 264 | 264 | } |
| 265 | - public function isPlayed(){ |
|
| 265 | + public function isPlayed() { |
|
| 266 | 266 | foreach ($this->games as $game) { |
| 267 | 267 | if ((isset($game) || !$this->getSkip()) && !$game->isPlayed()) return false; |
| 268 | 268 | } |
@@ -30,14 +30,18 @@ discard block |
||
| 30 | 30 | foreach ($settings as $key => $value) { |
| 31 | 31 | switch ($key) { |
| 32 | 32 | case 'name': |
| 33 | - if (gettype($value) !== 'string') throw new \Exception('Expected string as group name '.gettype($value).' given'); |
|
| 33 | + if (gettype($value) !== 'string') { |
|
| 34 | + throw new \Exception('Expected string as group name '.gettype($value).' given'); |
|
| 35 | + } |
|
| 34 | 36 | $this->name = $value; |
| 35 | 37 | break; |
| 36 | 38 | case 'type': |
| 37 | 39 | $this->generator->setType($value); |
| 38 | 40 | break; |
| 39 | 41 | case 'ordering': |
| 40 | - if (!in_array($value, orderingTypes)) throw new \Exception('Unknown group ordering: '.$value); |
|
| 42 | + if (!in_array($value, orderingTypes)) { |
|
| 43 | + throw new \Exception('Unknown group ordering: '.$value); |
|
| 44 | + } |
|
| 41 | 45 | $this->ordering = $value; |
| 42 | 46 | break; |
| 43 | 47 | case 'inGame': |
@@ -45,7 +49,9 @@ discard block |
||
| 45 | 49 | break; |
| 46 | 50 | case 'maxSize': |
| 47 | 51 | $value = (int) $value; |
| 48 | - if ($value > 1) $this->generator->setMaxSize($value); |
|
| 52 | + if ($value > 1) { |
|
| 53 | + $this->generator->setMaxSize($value); |
|
| 54 | + } |
|
| 49 | 55 | break; |
| 50 | 56 | case 'order': |
| 51 | 57 | $this->order = (int) $value; |
@@ -87,10 +93,11 @@ discard block |
||
| 87 | 93 | 'second' => 0, |
| 88 | 94 | 'third' => 0 |
| 89 | 95 | ]; |
| 90 | - } |
|
| 91 | - elseif (gettype($team) === 'array') { |
|
| 96 | + } elseif (gettype($team) === 'array') { |
|
| 92 | 97 | foreach ($team as $team2) { |
| 93 | - if ($team2 instanceof Team) $this->teams[] = $team2; |
|
| 98 | + if ($team2 instanceof Team) { |
|
| 99 | + $this->teams[] = $team2; |
|
| 100 | + } |
|
| 94 | 101 | $team2->groupResults[$this->id] = [ |
| 95 | 102 | 'group' => $this, |
| 96 | 103 | 'points' => 0, |
@@ -102,16 +109,20 @@ discard block |
||
| 102 | 109 | 'third' => 0 |
| 103 | 110 | ]; |
| 104 | 111 | } |
| 112 | + } else { |
|
| 113 | + throw new \Exception('Trying to add team which is not an instance of Team class'); |
|
| 105 | 114 | } |
| 106 | - else throw new \Exception('Trying to add team which is not an instance of Team class'); |
|
| 107 | 115 | } |
| 108 | 116 | return $this; |
| 109 | 117 | } |
| 110 | 118 | public function getTeams($filters = []) { |
| 111 | 119 | $teams = $this->teams; |
| 112 | 120 | |
| 113 | - if (gettype($filters) !== 'array' && $filters instanceof TeamFilter) $filters = [$filters]; |
|
| 114 | - elseif (gettype($filters) !== 'array') $filters = []; |
|
| 121 | + if (gettype($filters) !== 'array' && $filters instanceof TeamFilter) { |
|
| 122 | + $filters = [$filters]; |
|
| 123 | + } elseif (gettype($filters) !== 'array') { |
|
| 124 | + $filters = []; |
|
| 125 | + } |
|
| 115 | 126 | |
| 116 | 127 | // APPLY FILTERS |
| 117 | 128 | $filter = new Filter($this, $filters); |
@@ -136,7 +147,9 @@ discard block |
||
| 136 | 147 | return $t; |
| 137 | 148 | } |
| 138 | 149 | public function sortTeams($filters = [], $ordering = null) { |
| 139 | - if (!isset($ordering)) $ordering = $this->ordering; |
|
| 150 | + if (!isset($ordering)) { |
|
| 151 | + $ordering = $this->ordering; |
|
| 152 | + } |
|
| 140 | 153 | Utilis\Sorter\Teams::sortGroup($this->teams, $this, $ordering); |
| 141 | 154 | return $this->getTeams($filters); |
| 142 | 155 | } |
@@ -150,8 +163,11 @@ discard block |
||
| 150 | 163 | } |
| 151 | 164 | |
| 152 | 165 | public function setOrdering(string $ordering = \POINTS) { |
| 153 | - if (in_array($ordering, orderingTypes)) $this->ordering = $ordering; |
|
| 154 | - else throw new \Exception('Unknown group ordering: '.$ordering); |
|
| 166 | + if (in_array($ordering, orderingTypes)) { |
|
| 167 | + $this->ordering = $ordering; |
|
| 168 | + } else { |
|
| 169 | + throw new \Exception('Unknown group ordering: '.$ordering); |
|
| 170 | + } |
|
| 155 | 171 | return $this; |
| 156 | 172 | } |
| 157 | 173 | public function getOrdering() { |
@@ -184,16 +200,13 @@ discard block |
||
| 184 | 200 | foreach ($teams as $team) { |
| 185 | 201 | if ($team instanceOf Team) { |
| 186 | 202 | $this->progressed[] = $team->id; |
| 187 | - } |
|
| 188 | - elseif (gettype($team) === 'string' || gettype($team) === 'integer') { |
|
| 203 | + } elseif (gettype($team) === 'string' || gettype($team) === 'integer') { |
|
| 189 | 204 | $this->progressed[] = $team; |
| 190 | - } |
|
| 191 | - elseif (gettype($team) === 'array') { |
|
| 205 | + } elseif (gettype($team) === 'array') { |
|
| 192 | 206 | foreach ($team as $teamInner) { |
| 193 | 207 | if ($teamInner instanceOf Team) { |
| 194 | 208 | $this->progressed[] = $teamInner->id; |
| 195 | - } |
|
| 196 | - elseif (gettype($teamInner) === 'string' || gettype($teamInner) === 'integer') { |
|
| 209 | + } elseif (gettype($teamInner) === 'string' || gettype($teamInner) === 'integer') { |
|
| 197 | 210 | $this->progressed[] = $teamInner; |
| 198 | 211 | } |
| 199 | 212 | } |
@@ -226,8 +239,11 @@ discard block |
||
| 226 | 239 | } |
| 227 | 240 | } |
| 228 | 241 | foreach ($games as $game) { |
| 229 | - if ($game instanceof Game) $this->games[] = $game; |
|
| 230 | - else throw new \Exception('Trying to add game which is not instance of Game object.'); |
|
| 242 | + if ($game instanceof Game) { |
|
| 243 | + $this->games[] = $game; |
|
| 244 | + } else { |
|
| 245 | + throw new \Exception('Trying to add game which is not instance of Game object.'); |
|
| 246 | + } |
|
| 231 | 247 | } |
| 232 | 248 | return $this; |
| 233 | 249 | } |
@@ -235,7 +251,9 @@ discard block |
||
| 235 | 251 | return $this->games; |
| 236 | 252 | } |
| 237 | 253 | public function orderGames() { |
| 238 | - if (count($this->games) <= 4) return $this->games; |
|
| 254 | + if (count($this->games) <= 4) { |
|
| 255 | + return $this->games; |
|
| 256 | + } |
|
| 239 | 257 | $this->games = $this->generator->orderGames(); |
| 240 | 258 | return $this->games; |
| 241 | 259 | } |
@@ -250,7 +268,9 @@ discard block |
||
| 250 | 268 | $game->setResults($results); |
| 251 | 269 | } |
| 252 | 270 | $return = $this->sortTeams($filters); |
| 253 | - if (!$reset) return $return; |
|
| 271 | + if (!$reset) { |
|
| 272 | + return $return; |
|
| 273 | + } |
|
| 254 | 274 | foreach ($this->getGames() as $game) { |
| 255 | 275 | $game->resetResults(); |
| 256 | 276 | } |
@@ -258,13 +278,17 @@ discard block |
||
| 258 | 278 | } |
| 259 | 279 | public function resetGames() { |
| 260 | 280 | foreach ($this->getGames() as $game) { |
| 261 | - if (isset($game)) $game->resetResults(); |
|
| 281 | + if (isset($game)) { |
|
| 282 | + $game->resetResults(); |
|
| 283 | + } |
|
| 262 | 284 | } |
| 263 | 285 | return $this; |
| 264 | 286 | } |
| 265 | 287 | public function isPlayed(){ |
| 266 | 288 | foreach ($this->games as $game) { |
| 267 | - if ((isset($game) || !$this->getSkip()) && !$game->isPlayed()) return false; |
|
| 289 | + if ((isset($game) || !$this->getSkip()) && !$game->isPlayed()) { |
|
| 290 | + return false; |
|
| 291 | + } |
|
| 268 | 292 | } |
| 269 | 293 | return true; |
| 270 | 294 | } |