@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | // CALCULATE BYES |
| 18 | 18 | $byes = 0; |
| 19 | - if ( !\TournamentGenerator\isPowerOf2($countTeams) ) { |
|
| 19 | + if (!\TournamentGenerator\isPowerOf2($countTeams)) { |
|
| 20 | 20 | $nextPow = bindec(str_pad(1, strlen(decbin($countTeams))+1, 0, STR_PAD_RIGHT)); |
| 21 | 21 | $byes = $nextPow-$countTeams; |
| 22 | 22 | } |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | $previousGroups = []; |
| 29 | 29 | |
| 30 | - for ($i=1; $i <= (($countTeams+$byes)/2); $i++) { |
|
| 30 | + for ($i = 1; $i <= (($countTeams+$byes)/2); $i++) { |
|
| 31 | 31 | $g = $startRound->group([ |
| 32 | 32 | 'name' => 'Round 1 - '.$i, |
| 33 | 33 | 'inGame' => 2, |
@@ -38,10 +38,10 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | $this->splitTeams(); |
| 40 | 40 | |
| 41 | - for ($r=2; $r <= $roundsNum; $r++) { |
|
| 41 | + for ($r = 2; $r <= $roundsNum; $r++) { |
|
| 42 | 42 | $groups = []; |
| 43 | 43 | $round = $this->round('Round '.$r); |
| 44 | - for ($g=1; $g <= (($countTeams+$byes)/pow(2, $r)); $g++) { |
|
| 44 | + for ($g = 1; $g <= (($countTeams+$byes)/pow(2, $r)); $g++) { |
|
| 45 | 45 | $group = $round->group([ |
| 46 | 46 | 'name' => 'Round '.$r.' - '.$g, |
| 47 | 47 | 'inGame' => 2, |
@@ -50,7 +50,7 @@ |
||
| 50 | 50 | |
| 51 | 51 | $this->splitTeams($round1); |
| 52 | 52 | |
| 53 | - if (count($this->getTeams()) % 4 == 2) { |
|
| 53 | + if (count($this->getTeams())%4 == 2) { |
|
| 54 | 54 | $group_top = $round2->group([ |
| 55 | 55 | 'name' => 'TOP', |
| 56 | 56 | 'type' => TWO_TWO |
@@ -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'); |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | // CALCULATE BYES |
| 20 | 20 | $byes = 0; |
| 21 | 21 | $nextPow = $countTeams; |
| 22 | - if ( !\TournamentGenerator\isPowerOf2($countTeams) ) { |
|
| 22 | + if (!\TournamentGenerator\isPowerOf2($countTeams)) { |
|
| 23 | 23 | $nextPow = bindec(str_pad(1, strlen(decbin($countTeams))+1, 0, STR_PAD_RIGHT)); |
| 24 | 24 | $byes = $nextPow-$countTeams; |
| 25 | 25 | } |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | $groupIds = []; |
| 39 | 39 | $allGroups = []; |
| 40 | 40 | |
| 41 | - for ($i=1; $i <= $startGroups; $i++) { |
|
| 41 | + for ($i = 1; $i <= $startGroups; $i++) { |
|
| 42 | 42 | $g = $startRound->group([ |
| 43 | 43 | 'name' => 'Start group - '.$i, |
| 44 | 44 | 'inGame' => 2, |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | // SPLIT TEAMS EVENLY |
| 53 | 53 | $this->splitTeams(); |
| 54 | 54 | |
| 55 | - for ($r=2; $r <= $roundsNum-1; $r++) { |
|
| 55 | + for ($r = 2; $r <= $roundsNum-1; $r++) { |
|
| 56 | 56 | $groups = []; |
| 57 | 57 | $losingGroups = []; |
| 58 | 58 | $round = $this->round('Round '.$r); |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | $losingGroupTeamsCount = count($previousLosingGroups)+count($previousGroups); |
| 64 | 64 | $order = 2; |
| 65 | 65 | if (\TournamentGenerator\isPowerOf2($losingGroupTeamsCount)) { // IF THE NUMBER OF TEAMS IS A POWER OF 2, GENERATE GROUPS WITHOUT BYES |
| 66 | - for ($g=1; $g <= $losingGroupTeamsCount/2; $g++) { |
|
| 66 | + for ($g = 1; $g <= $losingGroupTeamsCount/2; $g++) { |
|
| 67 | 67 | $group = $round->group([ |
| 68 | 68 | 'name' => 'Round '.$r.' - loss '.$g, |
| 69 | 69 | 'inGame' => 2, |
@@ -91,11 +91,11 @@ discard block |
||
| 91 | 91 | $n = (floor(count($previousLosingGroups)/2)+$losingByes); |
| 92 | 92 | $byesGroupsNums = []; |
| 93 | 93 | $byesProgressed = 0; |
| 94 | - for ($i=0; $i < $losingByes; $i++) { |
|
| 94 | + for ($i = 0; $i < $losingByes; $i++) { |
|
| 95 | 95 | $byesGroupsNums[] = $n-($i*2); |
| 96 | 96 | } |
| 97 | 97 | $lastGroup = 0; |
| 98 | - for ($g=1; $g <= ((count($previousLosingGroups)/2)+$losingByes); $g++) { |
|
| 98 | + for ($g = 1; $g <= ((count($previousLosingGroups)/2)+$losingByes); $g++) { |
|
| 99 | 99 | $group = $round->group([ |
| 100 | 100 | 'name' => 'Round '.$r.' - loss '.$g, |
| 101 | 101 | 'inGame' => 2, |
@@ -112,14 +112,14 @@ discard block |
||
| 112 | 112 | } |
| 113 | 113 | else { |
| 114 | 114 | $previousLosingGroups[$lastGroup]->progression($group, 0, 1); // PROGRESS FROM LOSING GROUP BEFORE |
| 115 | - if (isset($previousLosingGroups[$lastGroup + 1])) $previousLosingGroups[$lastGroup + 1]->progression($group, 0, 1); // PROGREESS FROM LOSING GROUP BEFORE |
|
| 115 | + if (isset($previousLosingGroups[$lastGroup+1])) $previousLosingGroups[$lastGroup+1]->progression($group, 0, 1); // PROGREESS FROM LOSING GROUP BEFORE |
|
| 116 | 116 | $lastGroup += 2; |
| 117 | 117 | } |
| 118 | 118 | } |
| 119 | 119 | } |
| 120 | 120 | // WINNING SIDE LIKE SINGLE ELIMINATION |
| 121 | 121 | $order = 1; |
| 122 | - for ($g=1; $g <= (($countTeams+$byes)/pow(2, $r)); $g++) { |
|
| 122 | + for ($g = 1; $g <= (($countTeams+$byes)/pow(2, $r)); $g++) { |
|
| 123 | 123 | $group = $round->group([ |
| 124 | 124 | 'name' => 'Round '.$r.' - win '.$g, |
| 125 | 125 | 'inGame' => 2, |
@@ -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 | } |
@@ -94,10 +94,10 @@ |
||
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
| 97 | - * $results = array ( |
|
| 98 | - * * team->id => team->score |
|
| 99 | - * ) |
|
| 100 | - */ |
|
| 97 | + * $results = array ( |
|
| 98 | + * * team->id => team->score |
|
| 99 | + * ) |
|
| 100 | + */ |
|
| 101 | 101 | public function setResults(array $results = []) { |
| 102 | 102 | if (count($this->results) === 0) $this->resetResults(); |
| 103 | 103 | arsort($results); |
@@ -78,10 +78,10 @@ discard block |
||
| 78 | 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)); |
| 79 | 79 | return $this; |
| 80 | 80 | } |
| 81 | - public function getTeams(){ |
|
| 81 | + public function getTeams() { |
|
| 82 | 82 | return $this->teams; |
| 83 | 83 | } |
| 84 | - public function getTeamsIds(){ |
|
| 84 | + public function getTeamsIds() { |
|
| 85 | 85 | $ids = []; |
| 86 | 86 | foreach ($this->teams as $team) { |
| 87 | 87 | $ids[] = $team->id; |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | $team->addLoss($this->group->id); |
| 129 | 129 | $this->results[$team->id] += ['points' => $this->group->lostPoints, 'type' => 'loss']; |
| 130 | 130 | } |
| 131 | - break;} |
|
| 131 | + break; } |
|
| 132 | 132 | case 3:{ |
| 133 | 133 | switch ($i) { |
| 134 | 134 | case 1: |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | $this->results[$team->id] += ['points' => $this->group->lostPoints, 'type' => 'loss']; |
| 148 | 148 | break; |
| 149 | 149 | } |
| 150 | - break;} |
|
| 150 | + break; } |
|
| 151 | 151 | case 4:{ |
| 152 | 152 | switch ($i) { |
| 153 | 153 | case 1: |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | $this->results[$team->id] += ['points' => $this->group->lostPoints, 'type' => 'loss']; |
| 172 | 172 | break; |
| 173 | 173 | } |
| 174 | - break;} |
|
| 174 | + break; } |
|
| 175 | 175 | } |
| 176 | 176 | $team->groupResults[$this->group->id]['score'] += $score; |
| 177 | 177 | $i++; |
@@ -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 | } |
@@ -14,20 +14,20 @@ |
||
| 14 | 14 | public $gamesWith = []; |
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | - * ARRAY WITH GROUPS AND IT'S RESULTS |
|
| 18 | - * array ( |
|
| 19 | - * * groupId => array ( |
|
| 20 | - * * * "group" => Group, # GROUP OBJECT |
|
| 21 | - * * * "points" => int 0, # NUMBER OF POINTS AQUIRED |
|
| 22 | - * * * "score" => int 0, # SUM OF SCORE AQUIRED |
|
| 23 | - * * * "wins" => int 0, # NUMBER OF WINS |
|
| 24 | - * * * "draws" => int 0, # NUMBER OF DRAWS |
|
| 25 | - * * * "losses" => int 0, # NUMBER OF LOSSES |
|
| 26 | - * * * "second" => int 0, # NUMBER OF TIMES BEING SECOND (ONLY FOR INGAME OPTION OF 3 OR 4) |
|
| 27 | - * * * "third" => int 0 # NUMBER OF TIMES BEING THIRD (ONLY FOR INGAME OPTION OF 4) |
|
| 28 | - * * ) |
|
| 29 | - *) |
|
| 30 | - */ |
|
| 17 | + * ARRAY WITH GROUPS AND IT'S RESULTS |
|
| 18 | + * array ( |
|
| 19 | + * * groupId => array ( |
|
| 20 | + * * * "group" => Group, # GROUP OBJECT |
|
| 21 | + * * * "points" => int 0, # NUMBER OF POINTS AQUIRED |
|
| 22 | + * * * "score" => int 0, # SUM OF SCORE AQUIRED |
|
| 23 | + * * * "wins" => int 0, # NUMBER OF WINS |
|
| 24 | + * * * "draws" => int 0, # NUMBER OF DRAWS |
|
| 25 | + * * * "losses" => int 0, # NUMBER OF LOSSES |
|
| 26 | + * * * "second" => int 0, # NUMBER OF TIMES BEING SECOND (ONLY FOR INGAME OPTION OF 3 OR 4) |
|
| 27 | + * * * "third" => int 0 # NUMBER OF TIMES BEING THIRD (ONLY FOR INGAME OPTION OF 4) |
|
| 28 | + * * ) |
|
| 29 | + *) |
|
| 30 | + */ |
|
| 31 | 31 | public $groupResults = []; |
| 32 | 32 | |
| 33 | 33 | function __construct(string $name = 'team') { |
@@ -43,61 +43,61 @@ |
||
| 43 | 43 | return array_filter($this->groupResults[$groupId], function($k) { return $k !== 'group'; }, ARRAY_FILTER_USE_KEY); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - public function addWin(string $groupId = ''){ |
|
| 46 | + public function addWin(string $groupId = '') { |
|
| 47 | 47 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
| 48 | 48 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->winPoints; |
| 49 | 49 | $this->groupResults[$groupId]['wins']++; |
| 50 | 50 | return $this; |
| 51 | 51 | } |
| 52 | - public function removeWin(string $groupId = ''){ |
|
| 52 | + public function removeWin(string $groupId = '') { |
|
| 53 | 53 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
| 54 | 54 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->winPoints; |
| 55 | 55 | $this->groupResults[$groupId]['wins']--; |
| 56 | 56 | return $this; |
| 57 | 57 | } |
| 58 | - public function addDraw(string $groupId = ''){ |
|
| 58 | + public function addDraw(string $groupId = '') { |
|
| 59 | 59 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
| 60 | 60 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->drawPoints; |
| 61 | 61 | $this->groupResults[$groupId]['draws']++; |
| 62 | 62 | return $this; |
| 63 | 63 | } |
| 64 | - public function removeDraw(string $groupId = ''){ |
|
| 64 | + public function removeDraw(string $groupId = '') { |
|
| 65 | 65 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
| 66 | 66 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->drawPointsPoints; |
| 67 | 67 | $this->groupResults[$groupId]['draws']--; |
| 68 | 68 | return $this; |
| 69 | 69 | } |
| 70 | - public function addLoss(string $groupId = ''){ |
|
| 70 | + public function addLoss(string $groupId = '') { |
|
| 71 | 71 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
| 72 | 72 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->lostPoints; |
| 73 | 73 | $this->groupResults[$groupId]['losses']++; |
| 74 | 74 | return $this; |
| 75 | 75 | } |
| 76 | - public function removeLoss(string $groupId = ''){ |
|
| 76 | + public function removeLoss(string $groupId = '') { |
|
| 77 | 77 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
| 78 | 78 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->lostPoints; |
| 79 | 79 | $this->groupResults[$groupId]['losses']--; |
| 80 | 80 | return $this; |
| 81 | 81 | } |
| 82 | - public function addSecond(string $groupId = ''){ |
|
| 82 | + public function addSecond(string $groupId = '') { |
|
| 83 | 83 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
| 84 | 84 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->secondPoints; |
| 85 | 85 | $this->groupResults[$groupId]['second']++; |
| 86 | 86 | return $this; |
| 87 | 87 | } |
| 88 | - public function removeSecond(string $groupId = ''){ |
|
| 88 | + public function removeSecond(string $groupId = '') { |
|
| 89 | 89 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
| 90 | 90 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->secondPoints; |
| 91 | 91 | $this->groupResults[$groupId]['second']--; |
| 92 | 92 | return $this; |
| 93 | 93 | } |
| 94 | - public function addThird(string $groupId = ''){ |
|
| 94 | + public function addThird(string $groupId = '') { |
|
| 95 | 95 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
| 96 | 96 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->thirdPoints; |
| 97 | 97 | $this->groupResults[$groupId]['third']++; |
| 98 | 98 | return $this; |
| 99 | 99 | } |
| 100 | - public function removeThird(string $groupId = ''){ |
|
| 100 | + public function removeThird(string $groupId = '') { |
|
| 101 | 101 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
| 102 | 102 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->thirdPoints; |
| 103 | 103 | $this->groupResults[$groupId]['third']--; |
@@ -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; |
@@ -22,11 +22,11 @@ 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) $teams[] = DUMMY_TEAM; // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY |
|
| 26 | 26 | |
| 27 | 27 | shuffle($teams); // SHUFFLE TEAMS FOR MORE RANDOMNESS |
| 28 | 28 | |
| 29 | - for ($i=0; $i < count($teams)-1; $i++) { |
|
| 29 | + for ($i = 0; $i < count($teams)-1; $i++) { |
|
| 30 | 30 | $bracket = array_merge($bracket, circle_saveBracket($teams, $group)); // SAVE CURRENT ROUND |
| 31 | 31 | |
| 32 | 32 | $teams = circle_rotateBracket($teams); // ROTATE TEAMS IN BRACKET |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | |
| 42 | 42 | $bracket = []; |
| 43 | 43 | |
| 44 | - for ($i=0; $i < count($teams)/2; $i++) { // GO THROUGH HALF OF THE TEAMS |
|
| 44 | + for ($i = 0; $i < count($teams)/2; $i++) { // GO THROUGH HALF OF THE TEAMS |
|
| 45 | 45 | |
| 46 | 46 | $home = $teams[$i]; |
| 47 | 47 | $reverse = array_reverse($teams); |
@@ -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 | |
@@ -68,11 +68,11 @@ discard block |
||
| 68 | 68 | return 'Group '.$this->name; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - public function allowSkip(){ |
|
| 71 | + public function allowSkip() { |
|
| 72 | 72 | $this->allowSkip = true; |
| 73 | 73 | return $this; |
| 74 | 74 | } |
| 75 | - public function disallowSkip(){ |
|
| 75 | + public function disallowSkip() { |
|
| 76 | 76 | $this->allowSkip = false; |
| 77 | 77 | return $this; |
| 78 | 78 | } |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | |
| 87 | 87 | public function addTeam(...$teams) { |
| 88 | 88 | foreach ($teams as $team) { |
| 89 | - if ($team instanceof Team) { |
|
| 89 | + if ($team instanceof Team) { |
|
| 90 | 90 | $this->teams[] = $team; |
| 91 | 91 | $team->groupResults[$this->id] = [ |
| 92 | 92 | 'group' => $this, |
@@ -243,13 +243,13 @@ discard block |
||
| 243 | 243 | if ($a->groupResults[$this->id]["points"] === $b->groupResults[$this->id]["points"]) return ($a->groupResults[$this->id]["score"] > $b->groupResults[$this->id]["score"] ? -1 : 1); |
| 244 | 244 | return ($a->groupResults[$this->id]["points"] > $b->groupResults[$this->id]["points"] ? -1 : 1); |
| 245 | 245 | }); |
| 246 | - break;} |
|
| 246 | + break; } |
|
| 247 | 247 | case SCORE:{ |
| 248 | 248 | usort($this->teams, function($a, $b) { |
| 249 | 249 | if ($a->groupResults[$this->id]["score"] === $b->groupResults[$this->id]["score"]) return 0; |
| 250 | 250 | return ($a->groupResults[$this->id]["score"] > $b->groupResults[$this->id]["score"] ? -1 : 1); |
| 251 | 251 | }); |
| 252 | - break;} |
|
| 252 | + break; } |
|
| 253 | 253 | } |
| 254 | 254 | return $this->getTeams($filters); |
| 255 | 255 | } |
@@ -314,19 +314,19 @@ discard block |
||
| 314 | 314 | switch ($this->type) { |
| 315 | 315 | case R_R:{ |
| 316 | 316 | $this->games = $this->r_rGames(); |
| 317 | - break;} |
|
| 317 | + break; } |
|
| 318 | 318 | case TWO_TWO: |
| 319 | 319 | $teams = $this->teams; |
| 320 | 320 | $discard = []; |
| 321 | 321 | shuffle($teams); |
| 322 | 322 | $count = count($teams); |
| 323 | - while (count($teams) % $this->inGame !== 0) { |
|
| 323 | + while (count($teams)%$this->inGame !== 0) { |
|
| 324 | 324 | $discard[] = array_shift($teams); |
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | while (count($teams) > 0) { |
| 328 | 328 | $tInGame = []; |
| 329 | - for ($i=0; $i < $this->inGame; $i++) { |
|
| 329 | + for ($i = 0; $i < $this->inGame; $i++) { |
|
| 330 | 330 | $tInGame[] = array_shift($teams); |
| 331 | 331 | } |
| 332 | 332 | $this->game($tInGame); |
@@ -365,7 +365,7 @@ discard block |
||
| 365 | 365 | $this->games[] = $g; |
| 366 | 366 | return $g; |
| 367 | 367 | } |
| 368 | - public function addGame(Game ...$games){ |
|
| 368 | + public function addGame(Game ...$games) { |
|
| 369 | 369 | foreach ($games as $game) { |
| 370 | 370 | if ($game instanceof Game) $this->games[] = $game; |
| 371 | 371 | else throw new \Exception('Trying to add game which is not instance of Game object.'); |
@@ -461,7 +461,7 @@ discard block |
||
| 461 | 461 | foreach ($games as $key => $game) { |
| 462 | 462 | $gTeams = $game->getTeamsIds(); |
| 463 | 463 | $suitable = true; |
| 464 | - $requiredTeams = array_filter($teams, function($a){ |
|
| 464 | + $requiredTeams = array_filter($teams, function($a) { |
|
| 465 | 465 | return $a < 4; |
| 466 | 466 | }); |
| 467 | 467 | foreach ($gTeams as $tid) { |
@@ -512,7 +512,7 @@ discard block |
||
| 512 | 512 | foreach ($games as $key => $game) { |
| 513 | 513 | $gTeams = $game->getTeamsIds(); |
| 514 | 514 | $suitable = false; |
| 515 | - $requiredTeams = array_filter($teams, function($a){ |
|
| 515 | + $requiredTeams = array_filter($teams, function($a) { |
|
| 516 | 516 | return $a < 4; |
| 517 | 517 | }); |
| 518 | 518 | foreach ($gTeams as $tid) { |
@@ -557,7 +557,7 @@ discard block |
||
| 557 | 557 | $games = array_merge($games, $games); |
| 558 | 558 | } |
| 559 | 559 | // $this->orderGames(); |
| 560 | - break;} |
|
| 560 | + break; } |
|
| 561 | 561 | case 4:{ |
| 562 | 562 | $teamsB = $teams; |
| 563 | 563 | $lockedTeam1 = array_shift($teamsB); |
@@ -575,7 +575,7 @@ discard block |
||
| 575 | 575 | } |
| 576 | 576 | $games[] = new Game(array_merge([$lockedTeam1], $teamsB), $this); |
| 577 | 577 | // $this->orderGames(); |
| 578 | - break;} |
|
| 578 | + break; } |
|
| 579 | 579 | } |
| 580 | 580 | return $games; |
| 581 | 581 | } |
@@ -601,7 +601,7 @@ discard block |
||
| 601 | 601 | } |
| 602 | 602 | return $this; |
| 603 | 603 | } |
| 604 | - public function isPlayed(){ |
|
| 604 | + public function isPlayed() { |
|
| 605 | 605 | foreach ($this->games as $game) { |
| 606 | 606 | if ((isset($game) || !$this->getSkip()) && !$game->isPlayed()) return false; |
| 607 | 607 | } |
@@ -33,23 +33,36 @@ discard block |
||
| 33 | 33 | foreach ($settings as $key => $value) { |
| 34 | 34 | switch ($key) { |
| 35 | 35 | case 'name': |
| 36 | - if (gettype($value) === 'string') $this->name = $value; |
|
| 37 | - else throw new \Exception('Expected string as group name '.gettype($value).' given'); |
|
| 36 | + if (gettype($value) === 'string') { |
|
| 37 | + $this->name = $value; |
|
| 38 | + } else { |
|
| 39 | + throw new \Exception('Expected string as group name '.gettype($value).' given'); |
|
| 40 | + } |
|
| 38 | 41 | break; |
| 39 | 42 | case 'type': |
| 40 | - if (in_array($value, groupTypes)) $this->type = $value; |
|
| 41 | - else throw new \Exception('Unknown group type: '.$value); |
|
| 43 | + if (in_array($value, groupTypes)) { |
|
| 44 | + $this->type = $value; |
|
| 45 | + } else { |
|
| 46 | + throw new \Exception('Unknown group type: '.$value); |
|
| 47 | + } |
|
| 42 | 48 | break; |
| 43 | 49 | case 'ordering': |
| 44 | - if (in_array($value, orderingTypes)) $this->ordering = $value; |
|
| 45 | - else throw new \Exception('Unknown group ordering: '.$value); |
|
| 50 | + if (in_array($value, orderingTypes)) { |
|
| 51 | + $this->ordering = $value; |
|
| 52 | + } else { |
|
| 53 | + throw new \Exception('Unknown group ordering: '.$value); |
|
| 54 | + } |
|
| 46 | 55 | break; |
| 47 | 56 | case 'inGame': |
| 48 | 57 | if (gettype($value) === 'integer') { |
| 49 | - if ($value === 2 || $value === 3 || $value === 4) $this->inGame = $value; |
|
| 50 | - else throw new \Exception('Expected 2,3 or 4 as inGame '.$value.' given'); |
|
| 58 | + if ($value === 2 || $value === 3 || $value === 4) { |
|
| 59 | + $this->inGame = $value; |
|
| 60 | + } else { |
|
| 61 | + throw new \Exception('Expected 2,3 or 4 as inGame '.$value.' given'); |
|
| 62 | + } |
|
| 63 | + } else { |
|
| 64 | + throw new \Exception('Expected integer as inGame '.gettype($value).' given'); |
|
| 51 | 65 | } |
| 52 | - else throw new \Exception('Expected integer as inGame '.gettype($value).' given'); |
|
| 53 | 66 | break; |
| 54 | 67 | case 'maxSize': |
| 55 | 68 | if (gettype($value) === 'integer') { |
@@ -98,10 +111,11 @@ discard block |
||
| 98 | 111 | 'second' => 0, |
| 99 | 112 | 'third' => 0 |
| 100 | 113 | ]; |
| 101 | - } |
|
| 102 | - elseif (gettype($team) === 'array') { |
|
| 114 | + } elseif (gettype($team) === 'array') { |
|
| 103 | 115 | foreach ($team as $team2) { |
| 104 | - if ($team2 instanceof Team) $this->teams[] = $team2; |
|
| 116 | + if ($team2 instanceof Team) { |
|
| 117 | + $this->teams[] = $team2; |
|
| 118 | + } |
|
| 105 | 119 | $team2->groupResults[$this->id] = [ |
| 106 | 120 | 'group' => $this, |
| 107 | 121 | 'points' => 0, |
@@ -113,16 +127,20 @@ discard block |
||
| 113 | 127 | 'third' => 0 |
| 114 | 128 | ]; |
| 115 | 129 | } |
| 130 | + } else { |
|
| 131 | + throw new \Exception('Trying to add team which is not an instance of Team class'); |
|
| 116 | 132 | } |
| 117 | - else throw new \Exception('Trying to add team which is not an instance of Team class'); |
|
| 118 | 133 | } |
| 119 | 134 | return $this; |
| 120 | 135 | } |
| 121 | 136 | public function getTeams($filters = []) { |
| 122 | 137 | $teams = $this->teams; |
| 123 | 138 | |
| 124 | - if (gettype($filters) !== 'array' && $filters instanceof TeamFilter) $filters = [$filters]; |
|
| 125 | - elseif (gettype($filters) !== 'array') $filters = []; |
|
| 139 | + if (gettype($filters) !== 'array' && $filters instanceof TeamFilter) { |
|
| 140 | + $filters = [$filters]; |
|
| 141 | + } elseif (gettype($filters) !== 'array') { |
|
| 142 | + $filters = []; |
|
| 143 | + } |
|
| 126 | 144 | |
| 127 | 145 | // APPLY FILTERS |
| 128 | 146 | foreach ($filters as $key => $filter) { |
@@ -130,27 +148,31 @@ discard block |
||
| 130 | 148 | switch (strtolower($key)) { |
| 131 | 149 | case 'and': |
| 132 | 150 | foreach ($teams as $tkey => $team) { |
| 133 | - if (!$this->filterAnd($team, $filter)) unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
| 151 | + if (!$this->filterAnd($team, $filter)) { |
|
| 152 | + unset($teams[$tkey]); |
|
| 153 | + } |
|
| 154 | + // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
| 134 | 155 | } |
| 135 | 156 | break; |
| 136 | 157 | case 'or': |
| 137 | 158 | foreach ($teams as $tkey => $team) { |
| 138 | - if (!$this->filterOr($team, $filter)) unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
| 159 | + if (!$this->filterOr($team, $filter)) { |
|
| 160 | + unset($teams[$tkey]); |
|
| 161 | + } |
|
| 162 | + // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
|
| 139 | 163 | } |
| 140 | 164 | break; |
| 141 | 165 | default: |
| 142 | 166 | throw new \Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".'); |
| 143 | 167 | break; |
| 144 | 168 | } |
| 145 | - } |
|
| 146 | - elseif ($filter instanceof TeamFilter) { |
|
| 169 | + } elseif ($filter instanceof TeamFilter) { |
|
| 147 | 170 | foreach ($teams as $tkey => $team) { |
| 148 | 171 | if (!$filter->validate($team, $this->id, 'sum', $this)) { |
| 149 | 172 | unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
| 150 | 173 | } |
| 151 | 174 | } |
| 152 | - } |
|
| 153 | - else { |
|
| 175 | + } else { |
|
| 154 | 176 | throw new \Exception('Filer ['.$key.'] is not an instance of TeamFilter class'); |
| 155 | 177 | } |
| 156 | 178 | } |
@@ -161,20 +183,24 @@ discard block |
||
| 161 | 183 | if (gettype($value) === 'array') { |
| 162 | 184 | switch (strtolower($key)) { |
| 163 | 185 | case 'and': |
| 164 | - if ($this->filterAnd($team, $value)) return false; |
|
| 186 | + if ($this->filterAnd($team, $value)) { |
|
| 187 | + return false; |
|
| 188 | + } |
|
| 165 | 189 | break; |
| 166 | 190 | case 'or': |
| 167 | - if ($this->filterOr($team, $value)) return false; |
|
| 191 | + if ($this->filterOr($team, $value)) { |
|
| 192 | + return false; |
|
| 193 | + } |
|
| 168 | 194 | break; |
| 169 | 195 | default: |
| 170 | 196 | throw new \Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".'); |
| 171 | 197 | break; |
| 172 | 198 | } |
| 173 | - } |
|
| 174 | - elseif ($value instanceof TeamFilter) { |
|
| 175 | - if (!$value->validate($team, $this->id, 'sum', $this)) return false; |
|
| 176 | - } |
|
| 177 | - else { |
|
| 199 | + } elseif ($value instanceof TeamFilter) { |
|
| 200 | + if (!$value->validate($team, $this->id, 'sum', $this)) { |
|
| 201 | + return false; |
|
| 202 | + } |
|
| 203 | + } else { |
|
| 178 | 204 | throw new \Exception('Filer ['.$key.'] is not an instance of TeamFilter class'); |
| 179 | 205 | } |
| 180 | 206 | } |
@@ -185,20 +211,24 @@ discard block |
||
| 185 | 211 | if (gettype($value) === 'array') { |
| 186 | 212 | switch (strtolower($key)) { |
| 187 | 213 | case 'and': |
| 188 | - if ($this->filterAnd($team, $value)) return true; |
|
| 214 | + if ($this->filterAnd($team, $value)) { |
|
| 215 | + return true; |
|
| 216 | + } |
|
| 189 | 217 | break; |
| 190 | 218 | case 'or': |
| 191 | - if ($this->filterOr($team, $value)) return true; |
|
| 219 | + if ($this->filterOr($team, $value)) { |
|
| 220 | + return true; |
|
| 221 | + } |
|
| 192 | 222 | break; |
| 193 | 223 | default: |
| 194 | 224 | throw new \Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".'); |
| 195 | 225 | break; |
| 196 | 226 | } |
| 197 | - } |
|
| 198 | - elseif ($value instanceof TeamFilter) { |
|
| 199 | - if (!$value->validate($team, $this->id, 'sum', $this)) return true; |
|
| 200 | - } |
|
| 201 | - else { |
|
| 227 | + } elseif ($value instanceof TeamFilter) { |
|
| 228 | + if (!$value->validate($team, $this->id, 'sum', $this)) { |
|
| 229 | + return true; |
|
| 230 | + } |
|
| 231 | + } else { |
|
| 202 | 232 | throw new \Exception('Filer ['.$key.'] is not an instance of TeamFilter class'); |
| 203 | 233 | } |
| 204 | 234 | } |
@@ -220,16 +250,22 @@ discard block |
||
| 220 | 250 | return $t; |
| 221 | 251 | } |
| 222 | 252 | public function setType(string $type = R_R) { |
| 223 | - if (in_array($type, groupTypes)) $this->type = $type; |
|
| 224 | - else throw new \Exception('Unknown group type: '.$type); |
|
| 253 | + if (in_array($type, groupTypes)) { |
|
| 254 | + $this->type = $type; |
|
| 255 | + } else { |
|
| 256 | + throw new \Exception('Unknown group type: '.$type); |
|
| 257 | + } |
|
| 225 | 258 | return $this; |
| 226 | 259 | } |
| 227 | 260 | public function getType() { |
| 228 | 261 | return $this->type; |
| 229 | 262 | } |
| 230 | 263 | public function setOrdering(string $ordering = POINTS) { |
| 231 | - if (in_array($ordering, orderingTypes)) $this->ordering = $ordering; |
|
| 232 | - else throw new \Exception('Unknown group ordering: '.$ordering); |
|
| 264 | + if (in_array($ordering, orderingTypes)) { |
|
| 265 | + $this->ordering = $ordering; |
|
| 266 | + } else { |
|
| 267 | + throw new \Exception('Unknown group ordering: '.$ordering); |
|
| 268 | + } |
|
| 233 | 269 | return $this; |
| 234 | 270 | } |
| 235 | 271 | public function getOrdering() { |
@@ -239,14 +275,20 @@ discard block |
||
| 239 | 275 | switch ($this->ordering) { |
| 240 | 276 | case POINTS:{ |
| 241 | 277 | usort($this->teams, function($a, $b) { |
| 242 | - if ($a->groupResults[$this->id]["points"] === $b->groupResults[$this->id]["points"] && $a->groupResults[$this->id]["score"] === $b->groupResults[$this->id]["score"]) return 0; |
|
| 243 | - if ($a->groupResults[$this->id]["points"] === $b->groupResults[$this->id]["points"]) return ($a->groupResults[$this->id]["score"] > $b->groupResults[$this->id]["score"] ? -1 : 1); |
|
| 278 | + if ($a->groupResults[$this->id]["points"] === $b->groupResults[$this->id]["points"] && $a->groupResults[$this->id]["score"] === $b->groupResults[$this->id]["score"]) { |
|
| 279 | + return 0; |
|
| 280 | + } |
|
| 281 | + if ($a->groupResults[$this->id]["points"] === $b->groupResults[$this->id]["points"]) { |
|
| 282 | + return ($a->groupResults[$this->id]["score"] > $b->groupResults[$this->id]["score"] ? -1 : 1); |
|
| 283 | + } |
|
| 244 | 284 | return ($a->groupResults[$this->id]["points"] > $b->groupResults[$this->id]["points"] ? -1 : 1); |
| 245 | 285 | }); |
| 246 | 286 | break;} |
| 247 | 287 | case SCORE:{ |
| 248 | 288 | usort($this->teams, function($a, $b) { |
| 249 | - if ($a->groupResults[$this->id]["score"] === $b->groupResults[$this->id]["score"]) return 0; |
|
| 289 | + if ($a->groupResults[$this->id]["score"] === $b->groupResults[$this->id]["score"]) { |
|
| 290 | + return 0; |
|
| 291 | + } |
|
| 250 | 292 | return ($a->groupResults[$this->id]["score"] > $b->groupResults[$this->id]["score"] ? -1 : 1); |
| 251 | 293 | }); |
| 252 | 294 | break;} |
@@ -255,10 +297,14 @@ discard block |
||
| 255 | 297 | } |
| 256 | 298 | public function setInGame(int $inGame) { |
| 257 | 299 | if (gettype($inGame) === 'integer') { |
| 258 | - if ($inGame === 2 || $inGame === 3 || $inGame === 4) $this->inGame = $inGame; |
|
| 259 | - else throw new \Exception('Expected 2,3 or 4 as inGame '.$inGame.' given'); |
|
| 300 | + if ($inGame === 2 || $inGame === 3 || $inGame === 4) { |
|
| 301 | + $this->inGame = $inGame; |
|
| 302 | + } else { |
|
| 303 | + throw new \Exception('Expected 2,3 or 4 as inGame '.$inGame.' given'); |
|
| 304 | + } |
|
| 305 | + } else { |
|
| 306 | + throw new \Exception('Expected integer as inGame '.gettype($inGame).' given'); |
|
| 260 | 307 | } |
| 261 | - else throw new \Exception('Expected integer as inGame '.gettype($inGame).' given'); |
|
| 262 | 308 | } |
| 263 | 309 | public function getInGame() { |
| 264 | 310 | return $this->inGame; |
@@ -286,16 +332,13 @@ discard block |
||
| 286 | 332 | foreach ($teams as $team) { |
| 287 | 333 | if ($team instanceOf Team) { |
| 288 | 334 | $this->progressed[] = $team->id; |
| 289 | - } |
|
| 290 | - elseif (gettype($team) === 'string' || gettype($team) === 'integer') { |
|
| 335 | + } elseif (gettype($team) === 'string' || gettype($team) === 'integer') { |
|
| 291 | 336 | $this->progressed[] = $team; |
| 292 | - } |
|
| 293 | - elseif (gettype($team) === 'array') { |
|
| 337 | + } elseif (gettype($team) === 'array') { |
|
| 294 | 338 | foreach ($team as $teamInner) { |
| 295 | 339 | if ($teamInner instanceOf Team) { |
| 296 | 340 | $this->progressed[] = $teamInner->id; |
| 297 | - } |
|
| 298 | - elseif (gettype($teamInner) === 'string' || gettype($teamInner) === 'integer') { |
|
| 341 | + } elseif (gettype($teamInner) === 'string' || gettype($teamInner) === 'integer') { |
|
| 299 | 342 | $this->progressed[] = $teamInner; |
| 300 | 343 | } |
| 301 | 344 | } |
@@ -349,12 +392,15 @@ discard block |
||
| 349 | 392 | while ($g > 0) { |
| 350 | 393 | foreach ($games as $key => $group) { |
| 351 | 394 | $this->games[] = array_shift($games[$key]); |
| 352 | - if (count($games[$key]) === 0) unset($games[$key]); |
|
| 395 | + if (count($games[$key]) === 0) { |
|
| 396 | + unset($games[$key]); |
|
| 397 | + } |
|
| 353 | 398 | $g--; |
| 354 | 399 | } |
| 355 | 400 | } |
| 401 | + } else { |
|
| 402 | + $this->games = $this->r_rGames(); |
|
| 356 | 403 | } |
| 357 | - else $this->games = $this->r_rGames(); |
|
| 358 | 404 | break; |
| 359 | 405 | } |
| 360 | 406 | return $this->games; |
@@ -366,8 +412,11 @@ discard block |
||
| 366 | 412 | } |
| 367 | 413 | public function addGame(Game ...$games){ |
| 368 | 414 | foreach ($games as $game) { |
| 369 | - if ($game instanceof Game) $this->games[] = $game; |
|
| 370 | - else throw new \Exception('Trying to add game which is not instance of Game object.'); |
|
| 415 | + if ($game instanceof Game) { |
|
| 416 | + $this->games[] = $game; |
|
| 417 | + } else { |
|
| 418 | + throw new \Exception('Trying to add game which is not instance of Game object.'); |
|
| 419 | + } |
|
| 371 | 420 | } |
| 372 | 421 | return $this; |
| 373 | 422 | } |
@@ -395,21 +444,30 @@ discard block |
||
| 395 | 444 | $teams[$team->id] = 0; |
| 396 | 445 | } |
| 397 | 446 | foreach (end($this->games)->getTeams() as $team) { |
| 398 | - if (!isset($teams[$team->id])) $teams[$team->id] = 4; |
|
| 399 | - else $teams[$team->id] += 4; |
|
| 447 | + if (!isset($teams[$team->id])) { |
|
| 448 | + $teams[$team->id] = 4; |
|
| 449 | + } else { |
|
| 450 | + $teams[$team->id] += 4; |
|
| 451 | + } |
|
| 400 | 452 | } |
| 401 | 453 | $g = prev($this->games); |
| 402 | 454 | if ($g instanceof Game) { |
| 403 | 455 | foreach ($g->getTeams() as $team) { |
| 404 | - if (!isset($teams[$team->id])) $teams[$team->id] = 2; |
|
| 405 | - else $teams[$team->id] += 2; |
|
| 456 | + if (!isset($teams[$team->id])) { |
|
| 457 | + $teams[$team->id] = 2; |
|
| 458 | + } else { |
|
| 459 | + $teams[$team->id] += 2; |
|
| 460 | + } |
|
| 406 | 461 | } |
| 407 | 462 | } |
| 408 | 463 | $g = prev($this->games); |
| 409 | 464 | if ($g instanceof Game) { |
| 410 | 465 | foreach ($g->getTeams() as $team) { |
| 411 | - if (!isset($teams[$team->id])) $teams[$team->id] = 1; |
|
| 412 | - else $teams[$team->id]++; |
|
| 466 | + if (!isset($teams[$team->id])) { |
|
| 467 | + $teams[$team->id] = 1; |
|
| 468 | + } else { |
|
| 469 | + $teams[$team->id]++; |
|
| 470 | + } |
|
| 413 | 471 | } |
| 414 | 472 | } |
| 415 | 473 | |
@@ -431,7 +489,9 @@ discard block |
||
| 431 | 489 | break; |
| 432 | 490 | } |
| 433 | 491 | } |
| 434 | - if ($found) continue; |
|
| 492 | + if ($found) { |
|
| 493 | + continue; |
|
| 494 | + } |
|
| 435 | 495 | |
| 436 | 496 | // CYCLE 2 |
| 437 | 497 | // ! TEAM WHICH PLAYED IN LAST TWO GAMES (NOT 6 or 7) |
@@ -452,7 +512,9 @@ discard block |
||
| 452 | 512 | break; |
| 453 | 513 | } |
| 454 | 514 | } |
| 455 | - if ($found) continue; |
|
| 515 | + if ($found) { |
|
| 516 | + continue; |
|
| 517 | + } |
|
| 456 | 518 | |
| 457 | 519 | // CYCLE 3 |
| 458 | 520 | // ! TEAM WHICH PLAYED IN LAST THREE GAMES (NOT 7) |
@@ -483,7 +545,9 @@ discard block |
||
| 483 | 545 | break; |
| 484 | 546 | } |
| 485 | 547 | } |
| 486 | - if ($found) continue; |
|
| 548 | + if ($found) { |
|
| 549 | + continue; |
|
| 550 | + } |
|
| 487 | 551 | |
| 488 | 552 | // CYCLE 4 |
| 489 | 553 | // ! TEAM WHICH PLAYED IN LAST THREE GAMES (NOT 7) |
@@ -504,7 +568,9 @@ discard block |
||
| 504 | 568 | break; |
| 505 | 569 | } |
| 506 | 570 | } |
| 507 | - if ($found) continue; |
|
| 571 | + if ($found) { |
|
| 572 | + continue; |
|
| 573 | + } |
|
| 508 | 574 | |
| 509 | 575 | // CYCLE 5 |
| 510 | 576 | // TEAMS THAT DIDN'T PLAY IN LAST GAME WILL PLAY THIS GAME (< 4) |
@@ -529,7 +595,9 @@ discard block |
||
| 529 | 595 | break; |
| 530 | 596 | } |
| 531 | 597 | } |
| 532 | - if ($found) continue; |
|
| 598 | + if ($found) { |
|
| 599 | + continue; |
|
| 600 | + } |
|
| 533 | 601 | |
| 534 | 602 | // CYCLE 6 |
| 535 | 603 | // FIRST AVAILABLE GAME |
@@ -540,7 +608,9 @@ discard block |
||
| 540 | 608 | } |
| 541 | 609 | public function r_rGames(array $teams = []) { |
| 542 | 610 | $games = []; |
| 543 | - if (count($teams) === 0) $teams = $this->teams; |
|
| 611 | + if (count($teams) === 0) { |
|
| 612 | + $teams = $this->teams; |
|
| 613 | + } |
|
| 544 | 614 | switch ($this->inGame) { |
| 545 | 615 | case 2: |
| 546 | 616 | $games = circle_genGames2($teams, $this); |
@@ -588,7 +658,9 @@ discard block |
||
| 588 | 658 | $game->setResults($results); |
| 589 | 659 | } |
| 590 | 660 | $return = $this->sortTeams($filters); |
| 591 | - if (!$reset) return $return; |
|
| 661 | + if (!$reset) { |
|
| 662 | + return $return; |
|
| 663 | + } |
|
| 592 | 664 | foreach ($this->getGames() as $game) { |
| 593 | 665 | $game->resetResults(); |
| 594 | 666 | } |
@@ -596,13 +668,17 @@ discard block |
||
| 596 | 668 | } |
| 597 | 669 | public function resetGames() { |
| 598 | 670 | foreach ($this->getGames() as $game) { |
| 599 | - if (isset($game)) $game->resetResults(); |
|
| 671 | + if (isset($game)) { |
|
| 672 | + $game->resetResults(); |
|
| 673 | + } |
|
| 600 | 674 | } |
| 601 | 675 | return $this; |
| 602 | 676 | } |
| 603 | 677 | public function isPlayed(){ |
| 604 | 678 | foreach ($this->games as $game) { |
| 605 | - if ((isset($game) || !$this->getSkip()) && !$game->isPlayed()) return false; |
|
| 679 | + if ((isset($game) || !$this->getSkip()) && !$game->isPlayed()) { |
|
| 680 | + return false; |
|
| 681 | + } |
|
| 606 | 682 | } |
| 607 | 683 | return true; |
| 608 | 684 | } |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | return $this->name; |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | - public function addGroup(Group ...$groups){ |
|
| 28 | + public function addGroup(Group ...$groups) { |
|
| 29 | 29 | foreach ($groups as $group) { |
| 30 | 30 | if ($group instanceof Group) $this->groups[] = $group; |
| 31 | 31 | else throw new \Exception('Trying to add group which is not an instance of Group class.'); |
@@ -37,21 +37,21 @@ discard block |
||
| 37 | 37 | $this->groups[] = $g->setSkip($this->allowSkip); |
| 38 | 38 | return $g; |
| 39 | 39 | } |
| 40 | - public function getGroups(){ |
|
| 40 | + public function getGroups() { |
|
| 41 | 41 | $this->orderGroups(); |
| 42 | 42 | return $this->groups; |
| 43 | 43 | } |
| 44 | 44 | public function orderGroups() { |
| 45 | - usort($this->groups, function($a, $b){ |
|
| 46 | - return $a->order - $b->order; |
|
| 45 | + usort($this->groups, function($a, $b) { |
|
| 46 | + return $a->order-$b->order; |
|
| 47 | 47 | }); |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - public function allowSkip(){ |
|
| 50 | + public function allowSkip() { |
|
| 51 | 51 | $this->allowSkip = true; |
| 52 | 52 | return $this; |
| 53 | 53 | } |
| 54 | - public function disallowSkip(){ |
|
| 54 | + public function disallowSkip() { |
|
| 55 | 55 | $this->allowSkip = false; |
| 56 | 56 | return $this; |
| 57 | 57 | } |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | return $this->allowSkip; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - public function genGames(){ |
|
| 66 | + public function genGames() { |
|
| 67 | 67 | $games = []; |
| 68 | 68 | $g = 0; |
| 69 | 69 | foreach ($this->groups as $group) { |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | public function getGames() { |
| 88 | 88 | return $this->games; |
| 89 | 89 | } |
| 90 | - public function isPlayed(){ |
|
| 90 | + public function isPlayed() { |
|
| 91 | 91 | foreach ($this->groups as $group) { |
| 92 | 92 | if (!$group->isPlayed()) return false; |
| 93 | 93 | } |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | |
| 97 | 97 | public function addTeam(...$teams) { |
| 98 | 98 | foreach ($teams as $team) { |
| 99 | - if ($team instanceof Team) { |
|
| 99 | + if ($team instanceof Team) { |
|
| 100 | 100 | $this->teams[] = $team; |
| 101 | 101 | } |
| 102 | 102 | elseif (gettype($team) === 'array') { |
@@ -157,14 +157,14 @@ discard block |
||
| 157 | 157 | return $this; |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - public function progress(){ |
|
| 160 | + public function progress() { |
|
| 161 | 161 | foreach ($this->groups as $group) { |
| 162 | 162 | $group->progress(); |
| 163 | 163 | } |
| 164 | 164 | return $this; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - public function progressBlank(){ |
|
| 167 | + public function progressBlank() { |
|
| 168 | 168 | if (!$this->isPlayed()) $this->simulate(); |
| 169 | 169 | foreach ($this->groups as $group) { |
| 170 | 170 | $group->progressBlank(); |
@@ -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; |
@@ -45,12 +45,12 @@ |
||
| 45 | 45 | |
| 46 | 46 | private $groups = []; |
| 47 | 47 | |
| 48 | - function __construct(string $what = 'points', string $how = '>', $val = 0, $groups = []){ |
|
| 48 | + function __construct(string $what = 'points', string $how = '>', $val = 0, $groups = []) { |
|
| 49 | 49 | if (in_array(strtolower($what), ['points', 'score', 'wins', 'draws', 'losses', 'second', 'third', 'team', 'notprogressed', 'progressed'])) $this->what = strtolower($what); |
| 50 | 50 | if (in_array($how, ['>', '<', '>=', '<=', '=', '!='])) $this->how = $how; |
| 51 | 51 | if ((gettype($val) === 'integer' && strtolower($what) !== 'team') || ($val instanceof Team && strtolower($what) === 'team')) $this->val = $val; |
| 52 | 52 | foreach ($groups as $group) { |
| 53 | - if ($group instanceof Group) $this->groups[] = $group->id; |
|
| 53 | + if ($group instanceof Group) $this->groups[] = $group->id; |
|
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | 56 | public function __toString() { |
@@ -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 | |