@@ -22,7 +22,10 @@ discard block |
||
| 22 | 22 | function circle_genGames2(array $teams = [], Group $group = null) { |
| 23 | 23 | $bracket = []; // ARRAY OF GAMES |
| 24 | 24 | |
| 25 | - if (count($teams) % 2 != 0) $teams[] = DUMMY_TEAM; // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY |
|
| 25 | + if (count($teams) % 2 != 0) { |
|
| 26 | + $teams[] = DUMMY_TEAM; |
|
| 27 | + } |
|
| 28 | + // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY |
|
| 26 | 29 | |
| 27 | 30 | shuffle($teams); // SHUFFLE TEAMS FOR MORE RANDOMNESS |
| 28 | 31 | |
@@ -47,7 +50,10 @@ discard block |
||
| 47 | 50 | $reverse = array_reverse($teams); |
| 48 | 51 | $away = $reverse[$i]; |
| 49 | 52 | |
| 50 | - if (($home == DUMMY_TEAM || $away == DUMMY_TEAM)) continue; // SKIP WHEN DUMMY_TEAM IS PRESENT |
|
| 53 | + if (($home == DUMMY_TEAM || $away == DUMMY_TEAM)) { |
|
| 54 | + continue; |
|
| 55 | + } |
|
| 56 | + // SKIP WHEN DUMMY_TEAM IS PRESENT |
|
| 51 | 57 | |
| 52 | 58 | $bracket[] = new Game([$home, $away], $group); |
| 53 | 59 | |
@@ -15,7 +15,9 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | $countTeams = count($this->getTeams()); |
| 17 | 17 | |
| 18 | - if ($countTeams < 3) throw new \Exception('Double elimination is possible for minimum of 3 teams - '.$countTeams.' teams given.'); |
|
| 18 | + if ($countTeams < 3) { |
|
| 19 | + throw new \Exception('Double elimination is possible for minimum of 3 teams - '.$countTeams.' teams given.'); |
|
| 20 | + } |
|
| 19 | 21 | |
| 20 | 22 | |
| 21 | 23 | // CALCULATE BYES |
@@ -79,15 +81,19 @@ discard block |
||
| 79 | 81 | if ($r === 2) { // FIRST LOSING ROUND |
| 80 | 82 | $previousGroups[2*($g-1)]->progression($group, 1, 1); // PROGRESS FROM STARTING GROUP |
| 81 | 83 | $previousGroups[(2*($g-1))+1]->progression($group, 1, 1); // PROGREESS FROM STARTING GROUP |
| 82 | - } |
|
| 83 | - elseif ($losingGroupTeamsCount >= 2) { |
|
| 84 | + } elseif ($losingGroupTeamsCount >= 2) { |
|
| 84 | 85 | $previousLosingGroups[$g-1]->progression($group, 0, 1); // PROGRESS FROM LOSING GROUP BEFORE |
| 85 | - if (isset(array_reverse($previousGroups)[$g-1])) array_reverse($previousGroups)[$g-1]->progression($group, 1, 1); // PROGREESS FROM WINNING GROUP BEFORE |
|
| 86 | - else $previousLosingGroups[$g]->progression($group, 0, 1); // PROGRESS OTHER TEAM FROM LOSING GROUP BEEFORE |
|
| 86 | + if (isset(array_reverse($previousGroups)[$g-1])) { |
|
| 87 | + array_reverse($previousGroups)[$g-1]->progression($group, 1, 1); |
|
| 88 | + } |
|
| 89 | + // PROGREESS FROM WINNING GROUP BEFORE |
|
| 90 | + else { |
|
| 91 | + $previousLosingGroups[$g]->progression($group, 0, 1); |
|
| 92 | + } |
|
| 93 | + // PROGRESS OTHER TEAM FROM LOSING GROUP BEEFORE |
|
| 87 | 94 | } |
| 88 | 95 | } |
| 89 | - } |
|
| 90 | - else { // IF THE NUMBER OF TEAMS IS NOT A POWER OF 2, GENERATE GROUPS WITH BYES |
|
| 96 | + } else { // IF THE NUMBER OF TEAMS IS NOT A POWER OF 2, GENERATE GROUPS WITH BYES |
|
| 91 | 97 | // LOOK FOR THE CLOSEST LOWER POWER OF 2 |
| 92 | 98 | $losingByes = $losingGroupTeamsCount-bindec(str_pad(1, strlen(decbin($losingGroupTeamsCount)), 0, STR_PAD_RIGHT)); |
| 93 | 99 | $n = (floor(count($previousLosingGroups)/2)+$losingByes); |
@@ -111,10 +117,12 @@ discard block |
||
| 111 | 117 | if (in_array($g, $byesGroupsNums) && isset($previousGroups[$byesProgressed])) { // EMPTY GROUP FROM BYE |
| 112 | 118 | $previousGroups[$byesProgressed]->progression($group, 1, 1); // PROGRESS FROM WINNING GROUP BEFORE |
| 113 | 119 | $byesProgressed++; |
| 114 | - } |
|
| 115 | - else { |
|
| 120 | + } else { |
|
| 116 | 121 | $previousLosingGroups[$lastGroup]->progression($group, 0, 1); // PROGRESS FROM LOSING GROUP BEFORE |
| 117 | - if (isset($previousLosingGroups[$lastGroup + 1])) $previousLosingGroups[$lastGroup + 1]->progression($group, 0, 1); // PROGREESS FROM LOSING GROUP BEFORE |
|
| 122 | + if (isset($previousLosingGroups[$lastGroup + 1])) { |
|
| 123 | + $previousLosingGroups[$lastGroup + 1]->progression($group, 0, 1); |
|
| 124 | + } |
|
| 125 | + // PROGREESS FROM LOSING GROUP BEFORE |
|
| 118 | 126 | $lastGroup += 2; |
| 119 | 127 | } |
| 120 | 128 | } |
@@ -12,7 +12,9 @@ |
||
| 12 | 12 | |
| 13 | 13 | public function generate() { |
| 14 | 14 | |
| 15 | - if (count($this->getTeams()) === 0) throw new \Exception('Couldn\'t generate 2R2G tournament because there are no teams in the tournament.'); |
|
| 15 | + if (count($this->getTeams()) === 0) { |
|
| 16 | + throw new \Exception('Couldn\'t generate 2R2G tournament because there are no teams in the tournament.'); |
|
| 17 | + } |
|
| 16 | 18 | |
| 17 | 19 | |
| 18 | 20 | $round1 = $this->round('Round 1'); |
@@ -27,8 +27,11 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | public function addGroup(Group ...$groups){ |
| 29 | 29 | foreach ($groups as $group) { |
| 30 | - if ($group instanceof Group) $this->groups[] = $group; |
|
| 31 | - else throw new \Exception('Trying to add group which is not an instance of Group class.'); |
|
| 30 | + if ($group instanceof Group) { |
|
| 31 | + $this->groups[] = $group; |
|
| 32 | + } else { |
|
| 33 | + throw new \Exception('Trying to add group which is not an instance of Group class.'); |
|
| 34 | + } |
|
| 32 | 35 | } |
| 33 | 36 | return $this; |
| 34 | 37 | } |
@@ -78,7 +81,9 @@ discard block |
||
| 78 | 81 | while ($g > 0) { |
| 79 | 82 | foreach ($games as $key => $group) { |
| 80 | 83 | $this->games[] = array_shift($games[$key]); |
| 81 | - if (count($games[$key]) === 0) unset($games[$key]); |
|
| 84 | + if (count($games[$key]) === 0) { |
|
| 85 | + unset($games[$key]); |
|
| 86 | + } |
|
| 82 | 87 | $g--; |
| 83 | 88 | } |
| 84 | 89 | } |
@@ -89,7 +94,9 @@ discard block |
||
| 89 | 94 | } |
| 90 | 95 | public function isPlayed(){ |
| 91 | 96 | foreach ($this->groups as $group) { |
| 92 | - if (!$group->isPlayed()) return false; |
|
| 97 | + if (!$group->isPlayed()) { |
|
| 98 | + return false; |
|
| 99 | + } |
|
| 93 | 100 | } |
| 94 | 101 | return true; |
| 95 | 102 | } |
@@ -98,10 +105,11 @@ discard block |
||
| 98 | 105 | foreach ($teams as $team) { |
| 99 | 106 | if ($team instanceof Team) { |
| 100 | 107 | $this->teams[] = $team; |
| 101 | - } |
|
| 102 | - elseif (gettype($team) === 'array') { |
|
| 108 | + } elseif (gettype($team) === 'array') { |
|
| 103 | 109 | foreach ($team as $team2) { |
| 104 | - if ($team2 instanceof Team) $this->teams[] = $team2; |
|
| 110 | + if ($team2 instanceof Team) { |
|
| 111 | + $this->teams[] = $team2; |
|
| 112 | + } |
|
| 105 | 113 | $team2->groupResults[$this->id] = [ |
| 106 | 114 | 'group' => $this, |
| 107 | 115 | 'points' => 0, |
@@ -113,8 +121,9 @@ discard block |
||
| 113 | 121 | 'third' => 0 |
| 114 | 122 | ]; |
| 115 | 123 | } |
| 124 | + } else { |
|
| 125 | + throw new \Exception('Trying to add team which is not an instance of Team class'); |
|
| 116 | 126 | } |
| 117 | - else throw new \Exception('Trying to add team which is not an instance of Team class'); |
|
| 118 | 127 | } |
| 119 | 128 | return $this; |
| 120 | 129 | } |
@@ -124,7 +133,9 @@ discard block |
||
| 124 | 133 | return $t; |
| 125 | 134 | } |
| 126 | 135 | public function getTeams() { |
| 127 | - if (count($this->teams) > 0) return $this->teams; |
|
| 136 | + if (count($this->teams) > 0) { |
|
| 137 | + return $this->teams; |
|
| 138 | + } |
|
| 128 | 139 | $teams = []; |
| 129 | 140 | foreach ($this->groups as $group) { |
| 130 | 141 | $teams = array_merge($teams, $group->getTeams()); |
@@ -135,7 +146,9 @@ discard block |
||
| 135 | 146 | |
| 136 | 147 | public function splitTeams(...$groups) { |
| 137 | 148 | |
| 138 | - if (count($groups) === 0) $groups = $this->getGroups(); |
|
| 149 | + if (count($groups) === 0) { |
|
| 150 | + $groups = $this->getGroups(); |
|
| 151 | + } |
|
| 139 | 152 | |
| 140 | 153 | foreach ($groups as $key => $value) { |
| 141 | 154 | if (gettype($value) === 'array') { |
@@ -150,7 +163,9 @@ discard block |
||
| 150 | 163 | while (count($teams) > 0) { |
| 151 | 164 | foreach ($groups as $group) { |
| 152 | 165 | if ($group instanceof Group) { |
| 153 | - if (count($teams) > 0) $group->addTeam(array_shift($teams)); |
|
| 166 | + if (count($teams) > 0) { |
|
| 167 | + $group->addTeam(array_shift($teams)); |
|
| 168 | + } |
|
| 154 | 169 | } |
| 155 | 170 | } |
| 156 | 171 | } |
@@ -165,7 +180,9 @@ discard block |
||
| 165 | 180 | } |
| 166 | 181 | |
| 167 | 182 | public function progressBlank(){ |
| 168 | - if (!$this->isPlayed()) $this->simulate(); |
|
| 183 | + if (!$this->isPlayed()) { |
|
| 184 | + $this->simulate(); |
|
| 185 | + } |
|
| 169 | 186 | foreach ($this->groups as $group) { |
| 170 | 187 | $group->progressBlank(); |
| 171 | 188 | } |
@@ -174,7 +191,9 @@ discard block |
||
| 174 | 191 | |
| 175 | 192 | public function simulate() { |
| 176 | 193 | foreach ($this->groups as $group) { |
| 177 | - if ($group->isPlayed()) continue; |
|
| 194 | + if ($group->isPlayed()) { |
|
| 195 | + continue; |
|
| 196 | + } |
|
| 178 | 197 | $group->simulate([], false); |
| 179 | 198 | } |
| 180 | 199 | return $this; |
@@ -46,11 +46,19 @@ discard block |
||
| 46 | 46 | private $groups = []; |
| 47 | 47 | |
| 48 | 48 | function __construct(string $what = 'points', string $how = '>', $val = 0, $groups = []){ |
| 49 | - if (in_array(strtolower($what), ['points', 'score', 'wins', 'draws', 'losses', 'second', 'third', 'team', 'notprogressed', 'progressed'])) $this->what = strtolower($what); |
|
| 50 | - if (in_array($how, ['>', '<', '>=', '<=', '=', '!='])) $this->how = $how; |
|
| 51 | - if ((gettype($val) === 'integer' && strtolower($what) !== 'team') || ($val instanceof Team && strtolower($what) === 'team')) $this->val = $val; |
|
| 49 | + if (in_array(strtolower($what), ['points', 'score', 'wins', 'draws', 'losses', 'second', 'third', 'team', 'notprogressed', 'progressed'])) { |
|
| 50 | + $this->what = strtolower($what); |
|
| 51 | + } |
|
| 52 | + if (in_array($how, ['>', '<', '>=', '<=', '=', '!='])) { |
|
| 53 | + $this->how = $how; |
|
| 54 | + } |
|
| 55 | + if ((gettype($val) === 'integer' && strtolower($what) !== 'team') || ($val instanceof Team && strtolower($what) === 'team')) { |
|
| 56 | + $this->val = $val; |
|
| 57 | + } |
|
| 52 | 58 | foreach ($groups as $group) { |
| 53 | - if ($group instanceof Group) $this->groups[] = $group->id; |
|
| 59 | + if ($group instanceof Group) { |
|
| 60 | + $this->groups[] = $group->id; |
|
| 61 | + } |
|
| 54 | 62 | } |
| 55 | 63 | } |
| 56 | 64 | public function __toString() { |
@@ -58,37 +66,54 @@ discard block |
||
| 58 | 66 | } |
| 59 | 67 | |
| 60 | 68 | public function validate(Team $team, $groupsId, string $operation = 'sum', Group $from = null) { |
| 61 | - if (count($this->groups) > 0) $groupsId = array_unique(array_merge($this->groups, (gettype($groupsId) === 'array' ? $groupsId : [$groupsId])), SORT_REGULAR); |
|
| 69 | + if (count($this->groups) > 0) { |
|
| 70 | + $groupsId = array_unique(array_merge($this->groups, (gettype($groupsId) === 'array' ? $groupsId : [$groupsId])), SORT_REGULAR); |
|
| 71 | + } |
|
| 62 | 72 | if ($this->what == 'team') { |
| 63 | 73 | switch ($this->how) { |
| 64 | 74 | case '=': |
| 65 | - if ($this->val === $team) return true; |
|
| 75 | + if ($this->val === $team) { |
|
| 76 | + return true; |
|
| 77 | + } |
|
| 66 | 78 | break; |
| 67 | 79 | case '!=': |
| 68 | - if ($this->val !== $team) return true; |
|
| 80 | + if ($this->val !== $team) { |
|
| 81 | + return true; |
|
| 82 | + } |
|
| 69 | 83 | break; |
| 70 | 84 | } |
| 71 | 85 | return false; |
| 72 | - } |
|
| 73 | - elseif ($this->what == 'notprogressed') { |
|
| 74 | - if ($from === null) throw new \Exception('Group $from was not defined.'); |
|
| 86 | + } elseif ($this->what == 'notprogressed') { |
|
| 87 | + if ($from === null) { |
|
| 88 | + throw new \Exception('Group $from was not defined.'); |
|
| 89 | + } |
|
| 75 | 90 | return !$from->progressed($team); |
| 76 | - } |
|
| 77 | - elseif ($this->what == 'progressed') { |
|
| 78 | - if ($from === null) throw new \Exception('Group $from was not defined.'); |
|
| 91 | + } elseif ($this->what == 'progressed') { |
|
| 92 | + if ($from === null) { |
|
| 93 | + throw new \Exception('Group $from was not defined.'); |
|
| 94 | + } |
|
| 79 | 95 | return $from->progressed($team); |
| 80 | 96 | } |
| 81 | - 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.'); |
|
| 97 | + if (gettype($groupsId) === 'array' && !in_array(strtolower($operation), ['sum', 'avg', 'max', 'min'])) { |
|
| 98 | + throw new \Exception('Unknown operation of '.$operation.'. Only "sum", "avg", "min", "max" possible.'); |
|
| 99 | + } |
|
| 82 | 100 | $comp = 0; |
| 83 | 101 | if (gettype($groupsId) === 'array' && count($groupsId) > 0) { |
| 84 | 102 | $sum = 0; |
| 85 | 103 | $max = null; |
| 86 | 104 | $min = null; |
| 87 | 105 | foreach ($groupsId as $id) { |
| 88 | - if (!isset($team->groupResults[$id])) continue; // IF TEAM DIDN'T PLAY IN THAT GROUP -> SKIP |
|
| 106 | + if (!isset($team->groupResults[$id])) { |
|
| 107 | + continue; |
|
| 108 | + } |
|
| 109 | + // IF TEAM DIDN'T PLAY IN THAT GROUP -> SKIP |
|
| 89 | 110 | $sum += $team->groupResults[$id][$this->what]; |
| 90 | - if ($team->groupResults[$id][$this->what] > $max || $max === null) $max = $team->groupResults[$id][$this->what]; |
|
| 91 | - if ($team->groupResults[$id][$this->what] < $min || $min === null) $min = $team->groupResults[$id][$this->what]; |
|
| 111 | + if ($team->groupResults[$id][$this->what] > $max || $max === null) { |
|
| 112 | + $max = $team->groupResults[$id][$this->what]; |
|
| 113 | + } |
|
| 114 | + if ($team->groupResults[$id][$this->what] < $min || $min === null) { |
|
| 115 | + $min = $team->groupResults[$id][$this->what]; |
|
| 116 | + } |
|
| 92 | 117 | } |
| 93 | 118 | switch (strtolower($operation)) { |
| 94 | 119 | case 'sum': |
@@ -104,11 +129,9 @@ discard block |
||
| 104 | 129 | $comp = $min; |
| 105 | 130 | break; |
| 106 | 131 | } |
| 107 | - } |
|
| 108 | - elseif (gettype($groupsId) === 'string' && isset($team->groupResults[$groupsId])) { |
|
| 132 | + } elseif (gettype($groupsId) === 'string' && isset($team->groupResults[$groupsId])) { |
|
| 109 | 133 | $comp = $team->groupResults[$groupsId][$this->what]; |
| 110 | - } |
|
| 111 | - else { |
|
| 134 | + } else { |
|
| 112 | 135 | throw new \Exception("Couldn't find group of id ".print_r($groupsId, true)); |
| 113 | 136 | } |
| 114 | 137 | |
@@ -23,8 +23,11 @@ discard block |
||
| 23 | 23 | |
| 24 | 24 | public function addRound(Round ...$rounds){ |
| 25 | 25 | foreach ($rounds as $round) { |
| 26 | - if ($round instanceof Round) $this->rounds[] = $round; |
|
| 27 | - else throw new \Exception('Trying to add round which is not an instance of Round class.'); |
|
| 26 | + if ($round instanceof Round) { |
|
| 27 | + $this->rounds[] = $round; |
|
| 28 | + } else { |
|
| 29 | + throw new \Exception('Trying to add round which is not an instance of Round class.'); |
|
| 30 | + } |
|
| 28 | 31 | } |
| 29 | 32 | return $this; |
| 30 | 33 | } |
@@ -57,13 +60,15 @@ discard block |
||
| 57 | 60 | foreach ($teams as $team) { |
| 58 | 61 | if ($team instanceof Team) { |
| 59 | 62 | $this->teams[] = $team; |
| 60 | - } |
|
| 61 | - elseif (gettype($team) === 'array') { |
|
| 63 | + } elseif (gettype($team) === 'array') { |
|
| 62 | 64 | foreach ($team as $team2) { |
| 63 | - if ($team2 instanceof Team) $this->teams[] = $team2; |
|
| 65 | + if ($team2 instanceof Team) { |
|
| 66 | + $this->teams[] = $team2; |
|
| 67 | + } |
|
| 64 | 68 | } |
| 69 | + } else { |
|
| 70 | + throw new \Exception('Trying to add team which is not an instance of Team class'); |
|
| 65 | 71 | } |
| 66 | - else throw new \Exception('Trying to add team which is not an instance of Team class'); |
|
| 67 | 72 | } |
| 68 | 73 | return $this; |
| 69 | 74 | } |
@@ -73,7 +78,9 @@ discard block |
||
| 73 | 78 | return $t; |
| 74 | 79 | } |
| 75 | 80 | public function getTeams() { |
| 76 | - if (count($this->teams) > 0) return $this->teams; |
|
| 81 | + if (count($this->teams) > 0) { |
|
| 82 | + return $this->teams; |
|
| 83 | + } |
|
| 77 | 84 | $teams = []; |
| 78 | 85 | foreach ($this->rounds as $round) { |
| 79 | 86 | $teams = array_merge($teams, $round->getTeams()); |
@@ -92,7 +99,9 @@ discard block |
||
| 92 | 99 | |
| 93 | 100 | public function splitTeams(...$rounds) { |
| 94 | 101 | |
| 95 | - if (count($rounds) === 0) $rounds = $this->getRounds(); |
|
| 102 | + if (count($rounds) === 0) { |
|
| 103 | + $rounds = $this->getRounds(); |
|
| 104 | + } |
|
| 96 | 105 | |
| 97 | 106 | $teams = $this->getTeams(); |
| 98 | 107 | shuffle($teams); |
@@ -112,7 +121,9 @@ discard block |
||
| 112 | 121 | |
| 113 | 122 | public function genGamesSimulate() { |
| 114 | 123 | $games = []; |
| 115 | - if (count($this->rounds) <= 0) throw new \Exception('There are no rounds to simulate games from.'); |
|
| 124 | + if (count($this->rounds) <= 0) { |
|
| 125 | + throw new \Exception('There are no rounds to simulate games from.'); |
|
| 126 | + } |
|
| 116 | 127 | foreach ($this->rounds as $round) { |
| 117 | 128 | $games = array_merge($games, $round->genGames()); |
| 118 | 129 | $round->simulate()->progressBlank()->resetGames(); |
@@ -29,7 +29,9 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | public function addFilter(...$filters) { |
| 31 | 31 | foreach ($filters as $filter) { |
| 32 | - if (!$filter instanceof TeamFilter) throw new \Exception('Trying to add filter which is not an instance of TeamFilter.'); |
|
| 32 | + if (!$filter instanceof TeamFilter) { |
|
| 33 | + throw new \Exception('Trying to add filter which is not an instance of TeamFilter.'); |
|
| 34 | + } |
|
| 33 | 35 | $this->filters[] = $filter; |
| 34 | 36 | } |
| 35 | 37 | return $this; |
@@ -37,8 +39,11 @@ discard block |
||
| 37 | 39 | |
| 38 | 40 | public function progress() { |
| 39 | 41 | $teams = $this->from->sortTeams($this->filters); |
| 40 | - if (count($this->filters) === 0 || $this->len !== null || $this->start !== 0) $next = array_splice($teams, $this->start, ($this->len === null ? count($teams) : $this->len)); |
|
| 41 | - else $next = $teams; |
|
| 42 | + if (count($this->filters) === 0 || $this->len !== null || $this->start !== 0) { |
|
| 43 | + $next = array_splice($teams, $this->start, ($this->len === null ? count($teams) : $this->len)); |
|
| 44 | + } else { |
|
| 45 | + $next = $teams; |
|
| 46 | + } |
|
| 42 | 47 | $this->from->addProgressed($next); |
| 43 | 48 | $this->to->addTeam($next); |
| 44 | 49 | return $this; |
@@ -46,8 +51,11 @@ discard block |
||
| 46 | 51 | |
| 47 | 52 | public function progressBlank(){ |
| 48 | 53 | $teams = $this->from->isPlayed() ? $this->from->sortTeams($this->filters) : $this->from->simulate($this->filters); |
| 49 | - if (count($this->filters) === 0 || $this->len !== null || $this->start !== 0) $next = array_splice($teams, $this->start, ($this->len === null ? count($teams) : $this->len)); |
|
| 50 | - else $next = $teams; |
|
| 54 | + if (count($this->filters) === 0 || $this->len !== null || $this->start !== 0) { |
|
| 55 | + $next = array_splice($teams, $this->start, ($this->len === null ? count($teams) : $this->len)); |
|
| 56 | + } else { |
|
| 57 | + $next = $teams; |
|
| 58 | + } |
|
| 51 | 59 | $this->from->addProgressed($next); |
| 52 | 60 | $i = 1; |
| 53 | 61 | foreach ($next as $team) { |
@@ -33,27 +33,40 @@ discard block |
||
| 33 | 33 | foreach ($settings as $key => $value) { |
| 34 | 34 | switch ($key) { |
| 35 | 35 | case 'name': |
| 36 | - if (gettype($value) !== 'string') throw new \Exception('Expected string as group name '.gettype($value).' given'); |
|
| 36 | + if (gettype($value) !== 'string') { |
|
| 37 | + throw new \Exception('Expected string as group name '.gettype($value).' given'); |
|
| 38 | + } |
|
| 37 | 39 | $this->name = $value; |
| 38 | 40 | break; |
| 39 | 41 | case 'type': |
| 40 | - if (!in_array($value, groupTypes)) throw new \Exception('Unknown group type: '.$value); |
|
| 42 | + if (!in_array($value, groupTypes)) { |
|
| 43 | + throw new \Exception('Unknown group type: '.$value); |
|
| 44 | + } |
|
| 41 | 45 | $this->type = $value; |
| 42 | 46 | break; |
| 43 | 47 | case 'ordering': |
| 44 | - if (!in_array($value, orderingTypes)) throw new \Exception('Unknown group ordering: '.$value); |
|
| 48 | + if (!in_array($value, orderingTypes)) { |
|
| 49 | + throw new \Exception('Unknown group ordering: '.$value); |
|
| 50 | + } |
|
| 45 | 51 | $this->ordering = $value; |
| 46 | 52 | break; |
| 47 | 53 | case 'inGame': |
| 48 | - if (gettype($value) !== 'integer') throw new \Exception('Expected integer as inGame '.gettype($value).' given'); |
|
| 49 | - else if ($value < 2 || $value > 4) throw new \Exception('Expected 2,3 or 4 as inGame '.$value.' given'); |
|
| 54 | + if (gettype($value) !== 'integer') { |
|
| 55 | + throw new \Exception('Expected integer as inGame '.gettype($value).' given'); |
|
| 56 | + } else if ($value < 2 || $value > 4) { |
|
| 57 | + throw new \Exception('Expected 2,3 or 4 as inGame '.$value.' given'); |
|
| 58 | + } |
|
| 50 | 59 | $this->inGame = $value; |
| 51 | 60 | break; |
| 52 | 61 | case 'maxSize': |
| 53 | - if (gettype($value) === 'integer') $this->maxSize = $value; |
|
| 62 | + if (gettype($value) === 'integer') { |
|
| 63 | + $this->maxSize = $value; |
|
| 64 | + } |
|
| 54 | 65 | break; |
| 55 | 66 | case 'order': |
| 56 | - if (gettype($value) === 'integer') $this->order = $value; |
|
| 67 | + if (gettype($value) === 'integer') { |
|
| 68 | + $this->order = $value; |
|
| 69 | + } |
|
| 57 | 70 | break; |
| 58 | 71 | } |
| 59 | 72 | } |
@@ -92,10 +105,11 @@ discard block |
||
| 92 | 105 | 'second' => 0, |
| 93 | 106 | 'third' => 0 |
| 94 | 107 | ]; |
| 95 | - } |
|
| 96 | - elseif (gettype($team) === 'array') { |
|
| 108 | + } elseif (gettype($team) === 'array') { |
|
| 97 | 109 | foreach ($team as $team2) { |
| 98 | - if ($team2 instanceof Team) $this->teams[] = $team2; |
|
| 110 | + if ($team2 instanceof Team) { |
|
| 111 | + $this->teams[] = $team2; |
|
| 112 | + } |
|
| 99 | 113 | $team2->groupResults[$this->id] = [ |
| 100 | 114 | 'group' => $this, |
| 101 | 115 | 'points' => 0, |
@@ -107,16 +121,20 @@ discard block |
||
| 107 | 121 | 'third' => 0 |
| 108 | 122 | ]; |
| 109 | 123 | } |
| 124 | + } else { |
|
| 125 | + throw new \Exception('Trying to add team which is not an instance of Team class'); |
|
| 110 | 126 | } |
| 111 | - else throw new \Exception('Trying to add team which is not an instance of Team class'); |
|
| 112 | 127 | } |
| 113 | 128 | return $this; |
| 114 | 129 | } |
| 115 | 130 | public function getTeams($filters = []) { |
| 116 | 131 | $teams = $this->teams; |
| 117 | 132 | |
| 118 | - if (gettype($filters) !== 'array' && $filters instanceof TeamFilter) $filters = [$filters]; |
|
| 119 | - elseif (gettype($filters) !== 'array') $filters = []; |
|
| 133 | + if (gettype($filters) !== 'array' && $filters instanceof TeamFilter) { |
|
| 134 | + $filters = [$filters]; |
|
| 135 | + } elseif (gettype($filters) !== 'array') { |
|
| 136 | + $filters = []; |
|
| 137 | + } |
|
| 120 | 138 | |
| 121 | 139 | // APPLY FILTERS |
| 122 | 140 | foreach ($filters as $key => $filter) { |
@@ -124,27 +142,31 @@ discard block |
||
| 124 | 142 | switch (strtolower($key)) { |
| 125 | 143 | case 'and': |
| 126 | 144 | foreach ($teams as $tkey => $team) { |
| 127 | - if (!$this->filterAnd($team, $filter)) unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
| 145 | + if (!$this->filterAnd($team, $filter)) { |
|
| 146 | + unset($teams[$tkey]); |
|
| 147 | + } |
|
| 148 | + // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
| 128 | 149 | } |
| 129 | 150 | break; |
| 130 | 151 | case 'or': |
| 131 | 152 | foreach ($teams as $tkey => $team) { |
| 132 | - if (!$this->filterOr($team, $filter)) unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
| 153 | + if (!$this->filterOr($team, $filter)) { |
|
| 154 | + unset($teams[$tkey]); |
|
| 155 | + } |
|
| 156 | + // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
| 133 | 157 | } |
| 134 | 158 | break; |
| 135 | 159 | default: |
| 136 | 160 | throw new \Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".'); |
| 137 | 161 | break; |
| 138 | 162 | } |
| 139 | - } |
|
| 140 | - elseif ($filter instanceof TeamFilter) { |
|
| 163 | + } elseif ($filter instanceof TeamFilter) { |
|
| 141 | 164 | foreach ($teams as $tkey => $team) { |
| 142 | 165 | if (!$filter->validate($team, $this->id, 'sum', $this)) { |
| 143 | 166 | unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
| 144 | 167 | } |
| 145 | 168 | } |
| 146 | - } |
|
| 147 | - else { |
|
| 169 | + } else { |
|
| 148 | 170 | throw new \Exception('Filer ['.$key.'] is not an instance of TeamFilter class'); |
| 149 | 171 | } |
| 150 | 172 | } |
@@ -155,20 +177,24 @@ discard block |
||
| 155 | 177 | if (gettype($value) === 'array') { |
| 156 | 178 | switch (strtolower($key)) { |
| 157 | 179 | case 'and': |
| 158 | - if ($this->filterAnd($team, $value)) return false; |
|
| 180 | + if ($this->filterAnd($team, $value)) { |
|
| 181 | + return false; |
|
| 182 | + } |
|
| 159 | 183 | break; |
| 160 | 184 | case 'or': |
| 161 | - if ($this->filterOr($team, $value)) return false; |
|
| 185 | + if ($this->filterOr($team, $value)) { |
|
| 186 | + return false; |
|
| 187 | + } |
|
| 162 | 188 | break; |
| 163 | 189 | default: |
| 164 | 190 | throw new \Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".'); |
| 165 | 191 | break; |
| 166 | 192 | } |
| 167 | - } |
|
| 168 | - elseif ($value instanceof TeamFilter) { |
|
| 169 | - if (!$value->validate($team, $this->id, 'sum', $this)) return false; |
|
| 170 | - } |
|
| 171 | - else { |
|
| 193 | + } elseif ($value instanceof TeamFilter) { |
|
| 194 | + if (!$value->validate($team, $this->id, 'sum', $this)) { |
|
| 195 | + return false; |
|
| 196 | + } |
|
| 197 | + } else { |
|
| 172 | 198 | throw new \Exception('Filer ['.$key.'] is not an instance of TeamFilter class'); |
| 173 | 199 | } |
| 174 | 200 | } |
@@ -179,20 +205,24 @@ discard block |
||
| 179 | 205 | if (gettype($value) === 'array') { |
| 180 | 206 | switch (strtolower($key)) { |
| 181 | 207 | case 'and': |
| 182 | - if ($this->filterAnd($team, $value)) return true; |
|
| 208 | + if ($this->filterAnd($team, $value)) { |
|
| 209 | + return true; |
|
| 210 | + } |
|
| 183 | 211 | break; |
| 184 | 212 | case 'or': |
| 185 | - if ($this->filterOr($team, $value)) return true; |
|
| 213 | + if ($this->filterOr($team, $value)) { |
|
| 214 | + return true; |
|
| 215 | + } |
|
| 186 | 216 | break; |
| 187 | 217 | default: |
| 188 | 218 | throw new \Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".'); |
| 189 | 219 | break; |
| 190 | 220 | } |
| 191 | - } |
|
| 192 | - elseif ($value instanceof TeamFilter) { |
|
| 193 | - if (!$value->validate($team, $this->id, 'sum', $this)) return true; |
|
| 194 | - } |
|
| 195 | - else { |
|
| 221 | + } elseif ($value instanceof TeamFilter) { |
|
| 222 | + if (!$value->validate($team, $this->id, 'sum', $this)) { |
|
| 223 | + return true; |
|
| 224 | + } |
|
| 225 | + } else { |
|
| 196 | 226 | throw new \Exception('Filer ['.$key.'] is not an instance of TeamFilter class'); |
| 197 | 227 | } |
| 198 | 228 | } |
@@ -214,16 +244,22 @@ discard block |
||
| 214 | 244 | return $t; |
| 215 | 245 | } |
| 216 | 246 | public function setType(string $type = R_R) { |
| 217 | - if (in_array($type, groupTypes)) $this->type = $type; |
|
| 218 | - else throw new \Exception('Unknown group type: '.$type); |
|
| 247 | + if (in_array($type, groupTypes)) { |
|
| 248 | + $this->type = $type; |
|
| 249 | + } else { |
|
| 250 | + throw new \Exception('Unknown group type: '.$type); |
|
| 251 | + } |
|
| 219 | 252 | return $this; |
| 220 | 253 | } |
| 221 | 254 | public function getType() { |
| 222 | 255 | return $this->type; |
| 223 | 256 | } |
| 224 | 257 | public function setOrdering(string $ordering = POINTS) { |
| 225 | - if (in_array($ordering, orderingTypes)) $this->ordering = $ordering; |
|
| 226 | - else throw new \Exception('Unknown group ordering: '.$ordering); |
|
| 258 | + if (in_array($ordering, orderingTypes)) { |
|
| 259 | + $this->ordering = $ordering; |
|
| 260 | + } else { |
|
| 261 | + throw new \Exception('Unknown group ordering: '.$ordering); |
|
| 262 | + } |
|
| 227 | 263 | return $this; |
| 228 | 264 | } |
| 229 | 265 | public function getOrdering() { |
@@ -233,14 +269,20 @@ discard block |
||
| 233 | 269 | switch ($this->ordering) { |
| 234 | 270 | case POINTS:{ |
| 235 | 271 | usort($this->teams, function($a, $b) { |
| 236 | - if ($a->groupResults[$this->id]["points"] === $b->groupResults[$this->id]["points"] && $a->groupResults[$this->id]["score"] === $b->groupResults[$this->id]["score"]) return 0; |
|
| 237 | - if ($a->groupResults[$this->id]["points"] === $b->groupResults[$this->id]["points"]) return ($a->groupResults[$this->id]["score"] > $b->groupResults[$this->id]["score"] ? -1 : 1); |
|
| 272 | + if ($a->groupResults[$this->id]["points"] === $b->groupResults[$this->id]["points"] && $a->groupResults[$this->id]["score"] === $b->groupResults[$this->id]["score"]) { |
|
| 273 | + return 0; |
|
| 274 | + } |
|
| 275 | + if ($a->groupResults[$this->id]["points"] === $b->groupResults[$this->id]["points"]) { |
|
| 276 | + return ($a->groupResults[$this->id]["score"] > $b->groupResults[$this->id]["score"] ? -1 : 1); |
|
| 277 | + } |
|
| 238 | 278 | return ($a->groupResults[$this->id]["points"] > $b->groupResults[$this->id]["points"] ? -1 : 1); |
| 239 | 279 | }); |
| 240 | 280 | break;} |
| 241 | 281 | case SCORE:{ |
| 242 | 282 | usort($this->teams, function($a, $b) { |
| 243 | - if ($a->groupResults[$this->id]["score"] === $b->groupResults[$this->id]["score"]) return 0; |
|
| 283 | + if ($a->groupResults[$this->id]["score"] === $b->groupResults[$this->id]["score"]) { |
|
| 284 | + return 0; |
|
| 285 | + } |
|
| 244 | 286 | return ($a->groupResults[$this->id]["score"] > $b->groupResults[$this->id]["score"] ? -1 : 1); |
| 245 | 287 | }); |
| 246 | 288 | break;} |
@@ -249,10 +291,14 @@ discard block |
||
| 249 | 291 | } |
| 250 | 292 | public function setInGame(int $inGame) { |
| 251 | 293 | if (gettype($inGame) === 'integer') { |
| 252 | - if ($inGame === 2 || $inGame === 3 || $inGame === 4) $this->inGame = $inGame; |
|
| 253 | - else throw new \Exception('Expected 2,3 or 4 as inGame '.$inGame.' given'); |
|
| 294 | + if ($inGame === 2 || $inGame === 3 || $inGame === 4) { |
|
| 295 | + $this->inGame = $inGame; |
|
| 296 | + } else { |
|
| 297 | + throw new \Exception('Expected 2,3 or 4 as inGame '.$inGame.' given'); |
|
| 298 | + } |
|
| 299 | + } else { |
|
| 300 | + throw new \Exception('Expected integer as inGame '.gettype($inGame).' given'); |
|
| 254 | 301 | } |
| 255 | - else throw new \Exception('Expected integer as inGame '.gettype($inGame).' given'); |
|
| 256 | 302 | } |
| 257 | 303 | public function getInGame() { |
| 258 | 304 | return $this->inGame; |
@@ -280,16 +326,13 @@ discard block |
||
| 280 | 326 | foreach ($teams as $team) { |
| 281 | 327 | if ($team instanceOf Team) { |
| 282 | 328 | $this->progressed[] = $team->id; |
| 283 | - } |
|
| 284 | - elseif (gettype($team) === 'string' || gettype($team) === 'integer') { |
|
| 329 | + } elseif (gettype($team) === 'string' || gettype($team) === 'integer') { |
|
| 285 | 330 | $this->progressed[] = $team; |
| 286 | - } |
|
| 287 | - elseif (gettype($team) === 'array') { |
|
| 331 | + } elseif (gettype($team) === 'array') { |
|
| 288 | 332 | foreach ($team as $teamInner) { |
| 289 | 333 | if ($teamInner instanceOf Team) { |
| 290 | 334 | $this->progressed[] = $teamInner->id; |
| 291 | - } |
|
| 292 | - elseif (gettype($teamInner) === 'string' || gettype($teamInner) === 'integer') { |
|
| 335 | + } elseif (gettype($teamInner) === 'string' || gettype($teamInner) === 'integer') { |
|
| 293 | 336 | $this->progressed[] = $teamInner; |
| 294 | 337 | } |
| 295 | 338 | } |
@@ -325,7 +368,9 @@ discard block |
||
| 325 | 368 | $this->game($tInGame); |
| 326 | 369 | } |
| 327 | 370 | |
| 328 | - 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.' - allow skip '.($this->allowSkip ? 'True' : 'False')); |
|
| 371 | + if (count($discard) > 0 && !$this->allowSkip) { |
|
| 372 | + 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.' - allow skip '.($this->allowSkip ? 'True' : 'False')); |
|
| 373 | + } |
|
| 329 | 374 | break; |
| 330 | 375 | case COND_SPLIT: |
| 331 | 376 | $games = []; |
@@ -341,12 +386,15 @@ discard block |
||
| 341 | 386 | while ($g > 0) { |
| 342 | 387 | foreach ($games as $key => $group) { |
| 343 | 388 | $this->games[] = array_shift($games[$key]); |
| 344 | - if (count($games[$key]) === 0) unset($games[$key]); |
|
| 389 | + if (count($games[$key]) === 0) { |
|
| 390 | + unset($games[$key]); |
|
| 391 | + } |
|
| 345 | 392 | $g--; |
| 346 | 393 | } |
| 347 | 394 | } |
| 395 | + } else { |
|
| 396 | + $this->games = $this->r_rGames(); |
|
| 348 | 397 | } |
| 349 | - else $this->games = $this->r_rGames(); |
|
| 350 | 398 | break; |
| 351 | 399 | } |
| 352 | 400 | return $this->games; |
@@ -358,8 +406,11 @@ discard block |
||
| 358 | 406 | } |
| 359 | 407 | public function addGame(Game ...$games){ |
| 360 | 408 | foreach ($games as $game) { |
| 361 | - if ($game instanceof Game) $this->games[] = $game; |
|
| 362 | - else throw new \Exception('Trying to add game which is not instance of Game object.'); |
|
| 409 | + if ($game instanceof Game) { |
|
| 410 | + $this->games[] = $game; |
|
| 411 | + } else { |
|
| 412 | + throw new \Exception('Trying to add game which is not instance of Game object.'); |
|
| 413 | + } |
|
| 363 | 414 | } |
| 364 | 415 | return $this; |
| 365 | 416 | } |
@@ -387,21 +438,30 @@ discard block |
||
| 387 | 438 | $teams[$team->id] = 0; |
| 388 | 439 | } |
| 389 | 440 | foreach (end($this->games)->getTeams() as $team) { |
| 390 | - if (!isset($teams[$team->id])) $teams[$team->id] = 4; |
|
| 391 | - else $teams[$team->id] += 4; |
|
| 441 | + if (!isset($teams[$team->id])) { |
|
| 442 | + $teams[$team->id] = 4; |
|
| 443 | + } else { |
|
| 444 | + $teams[$team->id] += 4; |
|
| 445 | + } |
|
| 392 | 446 | } |
| 393 | 447 | $g = prev($this->games); |
| 394 | 448 | if ($g instanceof Game) { |
| 395 | 449 | foreach ($g->getTeams() as $team) { |
| 396 | - if (!isset($teams[$team->id])) $teams[$team->id] = 2; |
|
| 397 | - else $teams[$team->id] += 2; |
|
| 450 | + if (!isset($teams[$team->id])) { |
|
| 451 | + $teams[$team->id] = 2; |
|
| 452 | + } else { |
|
| 453 | + $teams[$team->id] += 2; |
|
| 454 | + } |
|
| 398 | 455 | } |
| 399 | 456 | } |
| 400 | 457 | $g = prev($this->games); |
| 401 | 458 | if ($g instanceof Game) { |
| 402 | 459 | foreach ($g->getTeams() as $team) { |
| 403 | - if (!isset($teams[$team->id])) $teams[$team->id] = 1; |
|
| 404 | - else $teams[$team->id]++; |
|
| 460 | + if (!isset($teams[$team->id])) { |
|
| 461 | + $teams[$team->id] = 1; |
|
| 462 | + } else { |
|
| 463 | + $teams[$team->id]++; |
|
| 464 | + } |
|
| 405 | 465 | } |
| 406 | 466 | } |
| 407 | 467 | |
@@ -423,7 +483,9 @@ discard block |
||
| 423 | 483 | break; |
| 424 | 484 | } |
| 425 | 485 | } |
| 426 | - if ($found) continue; |
|
| 486 | + if ($found) { |
|
| 487 | + continue; |
|
| 488 | + } |
|
| 427 | 489 | |
| 428 | 490 | // CYCLE 2 |
| 429 | 491 | // ! TEAM WHICH PLAYED IN LAST TWO GAMES (NOT 6 or 7) |
@@ -444,7 +506,9 @@ discard block |
||
| 444 | 506 | break; |
| 445 | 507 | } |
| 446 | 508 | } |
| 447 | - if ($found) continue; |
|
| 509 | + if ($found) { |
|
| 510 | + continue; |
|
| 511 | + } |
|
| 448 | 512 | |
| 449 | 513 | // CYCLE 3 |
| 450 | 514 | // ! TEAM WHICH PLAYED IN LAST THREE GAMES (NOT 7) |
@@ -475,7 +539,9 @@ discard block |
||
| 475 | 539 | break; |
| 476 | 540 | } |
| 477 | 541 | } |
| 478 | - if ($found) continue; |
|
| 542 | + if ($found) { |
|
| 543 | + continue; |
|
| 544 | + } |
|
| 479 | 545 | |
| 480 | 546 | // CYCLE 4 |
| 481 | 547 | // ! TEAM WHICH PLAYED IN LAST THREE GAMES (NOT 7) |
@@ -496,7 +562,9 @@ discard block |
||
| 496 | 562 | break; |
| 497 | 563 | } |
| 498 | 564 | } |
| 499 | - if ($found) continue; |
|
| 565 | + if ($found) { |
|
| 566 | + continue; |
|
| 567 | + } |
|
| 500 | 568 | |
| 501 | 569 | // CYCLE 5 |
| 502 | 570 | // TEAMS THAT DIDN'T PLAY IN LAST GAME WILL PLAY THIS GAME (< 4) |
@@ -521,7 +589,9 @@ discard block |
||
| 521 | 589 | break; |
| 522 | 590 | } |
| 523 | 591 | } |
| 524 | - if ($found) continue; |
|
| 592 | + if ($found) { |
|
| 593 | + continue; |
|
| 594 | + } |
|
| 525 | 595 | |
| 526 | 596 | // CYCLE 6 |
| 527 | 597 | // FIRST AVAILABLE GAME |
@@ -532,7 +602,9 @@ discard block |
||
| 532 | 602 | } |
| 533 | 603 | public function r_rGames(array $teams = []) { |
| 534 | 604 | $games = []; |
| 535 | - if (count($teams) === 0) $teams = $this->teams; |
|
| 605 | + if (count($teams) === 0) { |
|
| 606 | + $teams = $this->teams; |
|
| 607 | + } |
|
| 536 | 608 | switch ($this->inGame) { |
| 537 | 609 | case 2: |
| 538 | 610 | $games = circle_genGames2($teams, $this); |
@@ -580,7 +652,9 @@ discard block |
||
| 580 | 652 | $game->setResults($results); |
| 581 | 653 | } |
| 582 | 654 | $return = $this->sortTeams($filters); |
| 583 | - if (!$reset) return $return; |
|
| 655 | + if (!$reset) { |
|
| 656 | + return $return; |
|
| 657 | + } |
|
| 584 | 658 | foreach ($this->getGames() as $game) { |
| 585 | 659 | $game->resetResults(); |
| 586 | 660 | } |
@@ -588,13 +662,17 @@ discard block |
||
| 588 | 662 | } |
| 589 | 663 | public function resetGames() { |
| 590 | 664 | foreach ($this->getGames() as $game) { |
| 591 | - if (isset($game)) $game->resetResults(); |
|
| 665 | + if (isset($game)) { |
|
| 666 | + $game->resetResults(); |
|
| 667 | + } |
|
| 592 | 668 | } |
| 593 | 669 | return $this; |
| 594 | 670 | } |
| 595 | 671 | public function isPlayed(){ |
| 596 | 672 | foreach ($this->games as $game) { |
| 597 | - if ((isset($game) || !$this->getSkip()) && !$game->isPlayed()) return false; |
|
| 673 | + if ((isset($game) || !$this->getSkip()) && !$game->isPlayed()) { |
|
| 674 | + return false; |
|
| 675 | + } |
|
| 598 | 676 | } |
| 599 | 677 | return true; |
| 600 | 678 | } |
@@ -44,70 +44,90 @@ |
||
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | public function addWin(string $groupId = ''){ |
| 47 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 47 | + if (!isset($this->groupResults[$groupId])) { |
|
| 48 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 49 | + } |
|
| 48 | 50 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->winPoints; |
| 49 | 51 | $this->sumPoints += $this->groupResults[$groupId]['group']->winPoints; |
| 50 | 52 | $this->groupResults[$groupId]['wins']++; |
| 51 | 53 | return $this; |
| 52 | 54 | } |
| 53 | 55 | public function removeWin(string $groupId = ''){ |
| 54 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 56 | + if (!isset($this->groupResults[$groupId])) { |
|
| 57 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 58 | + } |
|
| 55 | 59 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->winPoints; |
| 56 | 60 | $this->sumPoints -= $this->groupResults[$groupId]['group']->winPoints; |
| 57 | 61 | $this->groupResults[$groupId]['wins']--; |
| 58 | 62 | return $this; |
| 59 | 63 | } |
| 60 | 64 | public function addDraw(string $groupId = ''){ |
| 61 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 65 | + if (!isset($this->groupResults[$groupId])) { |
|
| 66 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 67 | + } |
|
| 62 | 68 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->drawPoints; |
| 63 | 69 | $this->sumPoints += $this->groupResults[$groupId]['group']->drawPoints; |
| 64 | 70 | $this->groupResults[$groupId]['draws']++; |
| 65 | 71 | return $this; |
| 66 | 72 | } |
| 67 | 73 | public function removeDraw(string $groupId = ''){ |
| 68 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 74 | + if (!isset($this->groupResults[$groupId])) { |
|
| 75 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 76 | + } |
|
| 69 | 77 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->drawPointsPoints; |
| 70 | 78 | $this->sumPoints -= $this->groupResults[$groupId]['group']->drawPoints; |
| 71 | 79 | $this->groupResults[$groupId]['draws']--; |
| 72 | 80 | return $this; |
| 73 | 81 | } |
| 74 | 82 | public function addLoss(string $groupId = ''){ |
| 75 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 83 | + if (!isset($this->groupResults[$groupId])) { |
|
| 84 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 85 | + } |
|
| 76 | 86 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->lostPoints; |
| 77 | 87 | $this->sumPoints += $this->groupResults[$groupId]['group']->lostPoints; |
| 78 | 88 | $this->groupResults[$groupId]['losses']++; |
| 79 | 89 | return $this; |
| 80 | 90 | } |
| 81 | 91 | public function removeLoss(string $groupId = ''){ |
| 82 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 92 | + if (!isset($this->groupResults[$groupId])) { |
|
| 93 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 94 | + } |
|
| 83 | 95 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->lostPoints; |
| 84 | 96 | $this->sumPoints -= $this->groupResults[$groupId]['group']->lostPoints; |
| 85 | 97 | $this->groupResults[$groupId]['losses']--; |
| 86 | 98 | return $this; |
| 87 | 99 | } |
| 88 | 100 | public function addSecond(string $groupId = ''){ |
| 89 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 101 | + if (!isset($this->groupResults[$groupId])) { |
|
| 102 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 103 | + } |
|
| 90 | 104 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->secondPoints; |
| 91 | 105 | $this->sumPoints += $this->groupResults[$groupId]['group']->secondPoints; |
| 92 | 106 | $this->groupResults[$groupId]['second']++; |
| 93 | 107 | return $this; |
| 94 | 108 | } |
| 95 | 109 | public function removeSecond(string $groupId = ''){ |
| 96 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 110 | + if (!isset($this->groupResults[$groupId])) { |
|
| 111 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 112 | + } |
|
| 97 | 113 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->secondPoints; |
| 98 | 114 | $this->sumPoints -= $this->groupResults[$groupId]['group']->secondPoints; |
| 99 | 115 | $this->groupResults[$groupId]['second']--; |
| 100 | 116 | return $this; |
| 101 | 117 | } |
| 102 | 118 | public function addThird(string $groupId = ''){ |
| 103 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 119 | + if (!isset($this->groupResults[$groupId])) { |
|
| 120 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 121 | + } |
|
| 104 | 122 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->thirdPoints; |
| 105 | 123 | $this->sumPoints += $this->groupResults[$groupId]['group']->thirdPoints; |
| 106 | 124 | $this->groupResults[$groupId]['third']++; |
| 107 | 125 | return $this; |
| 108 | 126 | } |
| 109 | 127 | public function removeThird(string $groupId = ''){ |
| 110 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 128 | + if (!isset($this->groupResults[$groupId])) { |
|
| 129 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 130 | + } |
|
| 111 | 131 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->thirdPoints; |
| 112 | 132 | $this->sumPoints -= $this->groupResults[$groupId]['group']->thirdPoints; |
| 113 | 133 | $this->groupResults[$groupId]['third']--; |