@@ -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 | |
@@ -44,61 +44,81 @@ |
||
| 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->groupResults[$groupId]['wins']++; |
| 50 | 52 | return $this; |
| 51 | 53 | } |
| 52 | 54 | public function removeWin(string $groupId = ''){ |
| 53 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 55 | + if (!isset($this->groupResults[$groupId])) { |
|
| 56 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 57 | + } |
|
| 54 | 58 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->winPoints; |
| 55 | 59 | $this->groupResults[$groupId]['wins']--; |
| 56 | 60 | return $this; |
| 57 | 61 | } |
| 58 | 62 | public function addDraw(string $groupId = ''){ |
| 59 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 63 | + if (!isset($this->groupResults[$groupId])) { |
|
| 64 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 65 | + } |
|
| 60 | 66 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->drawPoints; |
| 61 | 67 | $this->groupResults[$groupId]['draws']++; |
| 62 | 68 | return $this; |
| 63 | 69 | } |
| 64 | 70 | public function removeDraw(string $groupId = ''){ |
| 65 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 71 | + if (!isset($this->groupResults[$groupId])) { |
|
| 72 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 73 | + } |
|
| 66 | 74 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->drawPointsPoints; |
| 67 | 75 | $this->groupResults[$groupId]['draws']--; |
| 68 | 76 | return $this; |
| 69 | 77 | } |
| 70 | 78 | public function addLoss(string $groupId = ''){ |
| 71 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 79 | + if (!isset($this->groupResults[$groupId])) { |
|
| 80 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 81 | + } |
|
| 72 | 82 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->lostPoints; |
| 73 | 83 | $this->groupResults[$groupId]['losses']++; |
| 74 | 84 | return $this; |
| 75 | 85 | } |
| 76 | 86 | public function removeLoss(string $groupId = ''){ |
| 77 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 87 | + if (!isset($this->groupResults[$groupId])) { |
|
| 88 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 89 | + } |
|
| 78 | 90 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->lostPoints; |
| 79 | 91 | $this->groupResults[$groupId]['losses']--; |
| 80 | 92 | return $this; |
| 81 | 93 | } |
| 82 | 94 | public function addSecond(string $groupId = ''){ |
| 83 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 95 | + if (!isset($this->groupResults[$groupId])) { |
|
| 96 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 97 | + } |
|
| 84 | 98 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->secondPoints; |
| 85 | 99 | $this->groupResults[$groupId]['second']++; |
| 86 | 100 | return $this; |
| 87 | 101 | } |
| 88 | 102 | public function removeSecond(string $groupId = ''){ |
| 89 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 103 | + if (!isset($this->groupResults[$groupId])) { |
|
| 104 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 105 | + } |
|
| 90 | 106 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->secondPoints; |
| 91 | 107 | $this->groupResults[$groupId]['second']--; |
| 92 | 108 | return $this; |
| 93 | 109 | } |
| 94 | 110 | public function addThird(string $groupId = ''){ |
| 95 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 111 | + if (!isset($this->groupResults[$groupId])) { |
|
| 112 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
| 113 | + } |
|
| 96 | 114 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->thirdPoints; |
| 97 | 115 | $this->groupResults[$groupId]['third']++; |
| 98 | 116 | return $this; |
| 99 | 117 | } |
| 100 | 118 | public function removeThird(string $groupId = ''){ |
| 101 | - 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 | + } |
|
| 102 | 122 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->thirdPoints; |
| 103 | 123 | $this->groupResults[$groupId]['third']--; |
| 104 | 124 | return $this; |
@@ -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 | |
@@ -80,8 +80,11 @@ discard block |
||
| 80 | 80 | |
| 81 | 81 | public function addCategory(Category ...$categories){ |
| 82 | 82 | foreach ($categories as $category) { |
| 83 | - if ($category instanceof Category) $this->categories[] = $category; |
|
| 84 | - else throw new \Exception('Trying to add category which is not an instance of the Category class.'); |
|
| 83 | + if ($category instanceof Category) { |
|
| 84 | + $this->categories[] = $category; |
|
| 85 | + } else { |
|
| 86 | + throw new \Exception('Trying to add category which is not an instance of the Category class.'); |
|
| 87 | + } |
|
| 85 | 88 | } |
| 86 | 89 | return $this; |
| 87 | 90 | } |
@@ -96,8 +99,11 @@ discard block |
||
| 96 | 99 | |
| 97 | 100 | public function addRound(Round ...$rounds) { |
| 98 | 101 | foreach ($rounds as $round) { |
| 99 | - if ($round instanceof Round) $this->rounds[] = $round; |
|
| 100 | - else throw new \Exception('Trying to add round which is not an instance of the Round class.'); |
|
| 102 | + if ($round instanceof Round) { |
|
| 103 | + $this->rounds[] = $round; |
|
| 104 | + } else { |
|
| 105 | + throw new \Exception('Trying to add round which is not an instance of the Round class.'); |
|
| 106 | + } |
|
| 101 | 107 | } |
| 102 | 108 | return $this; |
| 103 | 109 | } |
@@ -121,13 +127,15 @@ discard block |
||
| 121 | 127 | foreach ($teams as $team) { |
| 122 | 128 | if ($team instanceof Team) { |
| 123 | 129 | $this->teams[] = $team; |
| 124 | - } |
|
| 125 | - elseif (gettype($team) === 'array') { |
|
| 130 | + } elseif (gettype($team) === 'array') { |
|
| 126 | 131 | foreach ($team as $team2) { |
| 127 | - if ($team2 instanceof Team) $this->teams[] = $team2; |
|
| 132 | + if ($team2 instanceof Team) { |
|
| 133 | + $this->teams[] = $team2; |
|
| 134 | + } |
|
| 128 | 135 | } |
| 136 | + } else { |
|
| 137 | + throw new \Exception('Trying to add team which is not an instance of Team class'); |
|
| 129 | 138 | } |
| 130 | - else throw new \Exception('Trying to add team which is not an instance of Team class'); |
|
| 131 | 139 | } |
| 132 | 140 | return $this; |
| 133 | 141 | } |
@@ -137,7 +145,9 @@ discard block |
||
| 137 | 145 | return $t; |
| 138 | 146 | } |
| 139 | 147 | public function getTeams() { |
| 140 | - if (count($this->teams) > 0) return $this->teams; |
|
| 148 | + if (count($this->teams) > 0) { |
|
| 149 | + return $this->teams; |
|
| 150 | + } |
|
| 141 | 151 | $teams = []; |
| 142 | 152 | foreach ($this->categories as $category) { |
| 143 | 153 | $teams = array_merge($teams, $category->getTeams()); |
@@ -159,7 +169,9 @@ discard block |
||
| 159 | 169 | |
| 160 | 170 | public function splitTeams(...$wheres) { |
| 161 | 171 | |
| 162 | - if (count($wheres) === 0) $wheres = array_merge($this->getRounds(), $this->getCategories()); |
|
| 172 | + if (count($wheres) === 0) { |
|
| 173 | + $wheres = array_merge($this->getRounds(), $this->getCategories()); |
|
| 174 | + } |
|
| 163 | 175 | |
| 164 | 176 | foreach ($wheres as $key => $value) { |
| 165 | 177 | if (gettype($value) === 'array') { |
@@ -174,10 +186,13 @@ discard block |
||
| 174 | 186 | while (count($teams) > 0) { |
| 175 | 187 | foreach ($wheres as $where) { |
| 176 | 188 | if ($where instanceof Round) { |
| 177 | - if (count($teams) > 0) $where->addTeam(array_shift($teams)); |
|
| 178 | - } |
|
| 179 | - elseif ($where instanceof Category) { |
|
| 180 | - if (count($teams) > 0) $where->addTeam(array_shift($teams)); |
|
| 189 | + if (count($teams) > 0) { |
|
| 190 | + $where->addTeam(array_shift($teams)); |
|
| 191 | + } |
|
| 192 | + } elseif ($where instanceof Category) { |
|
| 193 | + if (count($teams) > 0) { |
|
| 194 | + $where->addTeam(array_shift($teams)); |
|
| 195 | + } |
|
| 181 | 196 | } |
| 182 | 197 | } |
| 183 | 198 | } |
@@ -193,8 +208,7 @@ discard block |
||
| 193 | 208 | foreach ($this->categories as $category) { |
| 194 | 209 | $games = array_merge($games, $category->genGamesSimulate()); |
| 195 | 210 | } |
| 196 | - } |
|
| 197 | - elseif (count($this->rounds) > 0) { |
|
| 211 | + } elseif (count($this->rounds) > 0) { |
|
| 198 | 212 | foreach ($this->rounds as $round) { |
| 199 | 213 | $games = array_merge($games, $round->genGames()); |
| 200 | 214 | $round->simulate()->progressBlank(); |
@@ -202,11 +216,12 @@ discard block |
||
| 202 | 216 | foreach ($this->rounds as $round) { |
| 203 | 217 | $round->resetGames(); |
| 204 | 218 | } |
| 205 | - } |
|
| 206 | - else { |
|
| 219 | + } else { |
|
| 207 | 220 | throw new \Exception('There are no rounds or categories to simulate games from.'); |
| 208 | 221 | } |
| 209 | - if ($returnTime) return $this->getTournamentTime(); |
|
| 222 | + if ($returnTime) { |
|
| 223 | + return $this->getTournamentTime(); |
|
| 224 | + } |
|
| 210 | 225 | return $games; |
| 211 | 226 | } |
| 212 | 227 | public function genGamesSimulateReal(bool $returnTime = false) { |
@@ -215,18 +230,18 @@ discard block |
||
| 215 | 230 | foreach ($this->categories as $category) { |
| 216 | 231 | $games = array_merge($games, $category->genGamesSimulate()); |
| 217 | 232 | } |
| 218 | - } |
|
| 219 | - elseif (count($this->rounds) > 0) { |
|
| 233 | + } elseif (count($this->rounds) > 0) { |
|
| 220 | 234 | foreach ($this->rounds as $round) { |
| 221 | 235 | $games = array_merge($games, $round->genGames()); |
| 222 | 236 | $round->simulate(); |
| 223 | 237 | $round->progress(); |
| 224 | 238 | } |
| 225 | - } |
|
| 226 | - else { |
|
| 239 | + } else { |
|
| 227 | 240 | throw new \Exception('There are no rounds or categories to simulate games from.'); |
| 228 | 241 | } |
| 229 | - if ($returnTime) return $this->getTournamentTime(); |
|
| 242 | + if ($returnTime) { |
|
| 243 | + return $this->getTournamentTime(); |
|
| 244 | + } |
|
| 230 | 245 | return $games; |
| 231 | 246 | } |
| 232 | 247 | |
@@ -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(); |
@@ -27,9 +27,10 @@ discard block |
||
| 27 | 27 | if (!$team instanceof Team) { |
| 28 | 28 | $error[] = $team; |
| 29 | 29 | unset($teams[$key]); |
| 30 | - } |
|
| 31 | - else { |
|
| 32 | - if (!isset($team->games[$group->id])) $team->games[$group->id] = []; |
|
| 30 | + } else { |
|
| 31 | + if (!isset($team->games[$group->id])) { |
|
| 32 | + $team->games[$group->id] = []; |
|
| 33 | + } |
|
| 33 | 34 | $team->games[$group->id][] = $this; |
| 34 | 35 | $tids[] = $team->id; |
| 35 | 36 | } |
@@ -38,12 +39,16 @@ discard block |
||
| 38 | 39 | foreach ($this->teams as $team) { |
| 39 | 40 | foreach ($tids as $id) { |
| 40 | 41 | if ($team->id !== $id) { |
| 41 | - if (!isset($team->gamesWith[$group->id][$id])) $team->gamesWith[$group->id][$id] = 0; |
|
| 42 | + if (!isset($team->gamesWith[$group->id][$id])) { |
|
| 43 | + $team->gamesWith[$group->id][$id] = 0; |
|
| 44 | + } |
|
| 42 | 45 | $team->gamesWith[$group->id][$id]++; |
| 43 | 46 | } |
| 44 | 47 | } |
| 45 | 48 | } |
| 46 | - 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)); |
|
| 49 | + if (count($error) > 0) { |
|
| 50 | + throw new \Exception('Trying to add teams ('.count($error).') that are not instance of Team class'.PHP_EOL.print_r($error, true)); |
|
| 51 | + } |
|
| 47 | 52 | } |
| 48 | 53 | |
| 49 | 54 | public function addTeam(...$teams) { |
@@ -51,9 +56,13 @@ discard block |
||
| 51 | 56 | foreach ($this->teams as $team) { |
| 52 | 57 | foreach ($teams as $team2) { |
| 53 | 58 | if ($team2 instanceof Team) { |
| 54 | - if (!isset($team->gamesWith[$this->group->id][$team2->id])) $team->gamesWith[$this->group->id][$team2->id] = 0; |
|
| 59 | + if (!isset($team->gamesWith[$this->group->id][$team2->id])) { |
|
| 60 | + $team->gamesWith[$this->group->id][$team2->id] = 0; |
|
| 61 | + } |
|
| 55 | 62 | $team->gamesWith[$this->group->id][$team2->id]++; |
| 56 | - if (!isset($team2->gamesWith[$this->group->id][$team->id])) $team2->gamesWith[$this->group->id][$team->id] = 0; |
|
| 63 | + if (!isset($team2->gamesWith[$this->group->id][$team->id])) { |
|
| 64 | + $team2->gamesWith[$this->group->id][$team->id] = 0; |
|
| 65 | + } |
|
| 57 | 66 | $team2->gamesWith[$this->group->id][$team->id]++; |
| 58 | 67 | } |
| 59 | 68 | } |
@@ -61,21 +70,26 @@ discard block |
||
| 61 | 70 | foreach ($teams as $key => $team) { |
| 62 | 71 | if ($team instanceof Team) { |
| 63 | 72 | $this->teams[] = $team; |
| 64 | - if (!isset($team->games[$this->group->id])) $team->games[$this->group->id] = []; |
|
| 73 | + if (!isset($team->games[$this->group->id])) { |
|
| 74 | + $team->games[$this->group->id] = []; |
|
| 75 | + } |
|
| 65 | 76 | $team->games[$this->group->id][] = $this; |
| 66 | 77 | foreach ($teams as $key2 => $team2) { |
| 67 | 78 | if ($team2 instanceof Team) { |
| 68 | - if (!isset($team->gamesWith[$this->group->id][$team2->id])) $team->gamesWith[$this->group->id][$team2->id] = 0; |
|
| 79 | + if (!isset($team->gamesWith[$this->group->id][$team2->id])) { |
|
| 80 | + $team->gamesWith[$this->group->id][$team2->id] = 0; |
|
| 81 | + } |
|
| 69 | 82 | $team->gamesWith[$this->group->id][$team2->id]++; |
| 70 | 83 | } |
| 71 | 84 | } |
| 72 | - } |
|
| 73 | - else { |
|
| 85 | + } else { |
|
| 74 | 86 | $error[] = $team; |
| 75 | 87 | unset($teams[$key]); |
| 76 | 88 | } |
| 77 | 89 | } |
| 78 | - 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)); |
|
| 90 | + if (count($error) > 0) { |
|
| 91 | + throw new \Exception('Trying to add teams ('.count($error).') that are not instance of Team class'.PHP_EOL.print_r($error, true)); |
|
| 92 | + } |
|
| 79 | 93 | return $this; |
| 80 | 94 | } |
| 81 | 95 | public function getTeams(){ |
@@ -90,7 +104,9 @@ discard block |
||
| 90 | 104 | } |
| 91 | 105 | public function getTeam(string $id) { |
| 92 | 106 | foreach ($this->teams as $team) { |
| 93 | - if ($team->id === $id) return $team; |
|
| 107 | + if ($team->id === $id) { |
|
| 108 | + return $team; |
|
| 109 | + } |
|
| 94 | 110 | } |
| 95 | 111 | return false; |
| 96 | 112 | } |
@@ -101,12 +117,16 @@ discard block |
||
| 101 | 117 | * ) |
| 102 | 118 | */ |
| 103 | 119 | public function setResults(array $results = []) { |
| 104 | - if (count($this->results) === 0) $this->resetResults(); |
|
| 120 | + if (count($this->results) === 0) { |
|
| 121 | + $this->resetResults(); |
|
| 122 | + } |
|
| 105 | 123 | arsort($results); |
| 106 | 124 | $i = 1; |
| 107 | 125 | foreach ($results as $id => $score) { |
| 108 | 126 | $team = $this->getTeam($id); |
| 109 | - if ($team === false) throw new \Exception('Couldn\'t find team with id of "'.$id.'"'); |
|
| 127 | + if ($team === false) { |
|
| 128 | + throw new \Exception('Couldn\'t find team with id of "'.$id.'"'); |
|
| 129 | + } |
|
| 110 | 130 | $this->results[$team->id] = ['score' => $score]; |
| 111 | 131 | $prev = prev($results); |
| 112 | 132 | next($results); |
@@ -117,13 +137,11 @@ discard block |
||
| 117 | 137 | $this->drawIds[] = $team->id; |
| 118 | 138 | $team->addDraw($this->group->id); |
| 119 | 139 | $this->results[$team->id] += ['points' => $this->group->drawPoints, 'type' => 'draw']; |
| 120 | - } |
|
| 121 | - elseif ($i === 1) { |
|
| 140 | + } elseif ($i === 1) { |
|
| 122 | 141 | $this->winId = $team->id; |
| 123 | 142 | $team->addWin($this->group->id); |
| 124 | 143 | $this->results[$team->id] += ['points' => $this->group->winPoints, 'type' => 'win']; |
| 125 | - } |
|
| 126 | - else { |
|
| 144 | + } else { |
|
| 127 | 145 | $this->lossId = $team->id; |
| 128 | 146 | $team->addLoss($this->group->id); |
| 129 | 147 | $this->results[$team->id] += ['points' => $this->group->lostPoints, 'type' => 'loss']; |
@@ -220,7 +238,9 @@ discard block |
||
| 220 | 238 | } |
| 221 | 239 | |
| 222 | 240 | public function isPlayed() { |
| 223 | - if (count($this->results) > 0) return true; |
|
| 241 | + if (count($this->results) > 0) { |
|
| 242 | + return true; |
|
| 243 | + } |
|
| 224 | 244 | return false; |
| 225 | 245 | } |
| 226 | 246 | } |