@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | $this->name = $name; |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | - public function addRound(Round ...$rounds){ |
|
| 22 | + public function addRound(Round ...$rounds) { |
|
| 23 | 23 | foreach ($rounds as $round) { |
| 24 | 24 | if ($round instanceof Round) $this->rounds[] = $round; |
| 25 | 25 | else throw new Exception('Trying to add round which is not an instance of Round class.'); |
@@ -31,15 +31,15 @@ discard block |
||
| 31 | 31 | $this->rounds[] = $r->setSkip($this->allowSkip); |
| 32 | 32 | return $r; |
| 33 | 33 | } |
| 34 | - public function getRounds(){ |
|
| 34 | + public function getRounds() { |
|
| 35 | 35 | return $this->rounds; |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - public function allowSkip(){ |
|
| 38 | + public function allowSkip() { |
|
| 39 | 39 | $this->allowSkip = true; |
| 40 | 40 | return $this; |
| 41 | 41 | } |
| 42 | - public function disallowSkip(){ |
|
| 42 | + public function disallowSkip() { |
|
| 43 | 43 | $this->allowSkip = false; |
| 44 | 44 | return $this; |
| 45 | 45 | } |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | |
| 54 | 54 | public function addTeam(...$teams) { |
| 55 | 55 | foreach ($teams as $team) { |
| 56 | - if ($team instanceof Team) { |
|
| 56 | + if ($team instanceof Team) { |
|
| 57 | 57 | $this->teams[] = $team; |
| 58 | 58 | } |
| 59 | 59 | elseif (gettype($team) === 'array') { |
@@ -21,8 +21,11 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | public function addRound(Round ...$rounds){ |
| 23 | 23 | foreach ($rounds as $round) { |
| 24 | - if ($round instanceof Round) $this->rounds[] = $round; |
|
| 25 | - else throw new Exception('Trying to add round which is not an instance of Round class.'); |
|
| 24 | + if ($round instanceof Round) { |
|
| 25 | + $this->rounds[] = $round; |
|
| 26 | + } else { |
|
| 27 | + throw new Exception('Trying to add round which is not an instance of Round class.'); |
|
| 28 | + } |
|
| 26 | 29 | } |
| 27 | 30 | return $this; |
| 28 | 31 | } |
@@ -55,13 +58,15 @@ discard block |
||
| 55 | 58 | foreach ($teams as $team) { |
| 56 | 59 | if ($team instanceof Team) { |
| 57 | 60 | $this->teams[] = $team; |
| 58 | - } |
|
| 59 | - elseif (gettype($team) === 'array') { |
|
| 61 | + } elseif (gettype($team) === 'array') { |
|
| 60 | 62 | foreach ($team as $team2) { |
| 61 | - if ($team2 instanceof Team) $this->teams[] = $team2; |
|
| 63 | + if ($team2 instanceof Team) { |
|
| 64 | + $this->teams[] = $team2; |
|
| 65 | + } |
|
| 62 | 66 | } |
| 67 | + } else { |
|
| 68 | + throw new Exception('Trying to add team which is not an instance of Team class'); |
|
| 63 | 69 | } |
| 64 | - else throw new Exception('Trying to add team which is not an instance of Team class'); |
|
| 65 | 70 | } |
| 66 | 71 | return $this; |
| 67 | 72 | } |
@@ -71,7 +76,9 @@ discard block |
||
| 71 | 76 | return $t; |
| 72 | 77 | } |
| 73 | 78 | public function getTeams() { |
| 74 | - if (count($this->teams) > 0) return $this->teams; |
|
| 79 | + if (count($this->teams) > 0) { |
|
| 80 | + return $this->teams; |
|
| 81 | + } |
|
| 75 | 82 | $teams = []; |
| 76 | 83 | foreach ($this->groups as $group) { |
| 77 | 84 | $teams = array_merge($teams, $group->getTeams()); |
@@ -90,7 +97,9 @@ discard block |
||
| 90 | 97 | |
| 91 | 98 | public function splitTeams(...$rounds) { |
| 92 | 99 | |
| 93 | - if (count($rounds) === 0) $rounds = $this->getRounds(); |
|
| 100 | + if (count($rounds) === 0) { |
|
| 101 | + $rounds = $this->getRounds(); |
|
| 102 | + } |
|
| 94 | 103 | |
| 95 | 104 | $teams = $this->getTeams(); |
| 96 | 105 | shuffle($teams); |
@@ -110,7 +119,9 @@ discard block |
||
| 110 | 119 | |
| 111 | 120 | public function genGamesSimulate() { |
| 112 | 121 | $games = []; |
| 113 | - if (count($this->rounds) <= 0) throw new Exception('There are no rounds to simulate games from.'); |
|
| 122 | + if (count($this->rounds) <= 0) { |
|
| 123 | + throw new Exception('There are no rounds to simulate games from.'); |
|
| 124 | + } |
|
| 114 | 125 | foreach ($this->rounds as $round) { |
| 115 | 126 | $games = array_merge($games, $round->genGames()); |
| 116 | 127 | $round->simulate()->progressBlank()->resetGames(); |
@@ -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 |
@@ -10,7 +10,9 @@ |
||
| 10 | 10 | |
| 11 | 11 | public function generate() { |
| 12 | 12 | |
| 13 | - if (count($this->getTeams()) === 0) throw new Exception('Couldn\'t generate 2R2G tournament because there are no teams in the tournament.'); |
|
| 13 | + if (count($this->getTeams()) === 0) { |
|
| 14 | + throw new Exception('Couldn\'t generate 2R2G tournament because there are no teams in the tournament.'); |
|
| 15 | + } |
|
| 14 | 16 | |
| 15 | 17 | |
| 16 | 18 | $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, |
@@ -13,7 +13,9 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | $countTeams = count($this->getTeams()); |
| 15 | 15 | |
| 16 | - if ($countTeams < 3) throw new Exception('Double elimination is possible for minimum of 3 teams - '.$countTeams.' teams given.'); |
|
| 16 | + if ($countTeams < 3) { |
|
| 17 | + throw new Exception('Double elimination is possible for minimum of 3 teams - '.$countTeams.' teams given.'); |
|
| 18 | + } |
|
| 17 | 19 | |
| 18 | 20 | |
| 19 | 21 | // CALCULATE BYES |
@@ -77,15 +79,19 @@ discard block |
||
| 77 | 79 | if ($r === 2) { // FIRST LOSING ROUND |
| 78 | 80 | $previousGroups[2*($g-1)]->progression($group, 1, 1); // PROGRESS FROM STARTING GROUP |
| 79 | 81 | $previousGroups[(2*($g-1))+1]->progression($group, 1, 1); // PROGREESS FROM STARTING GROUP |
| 80 | - } |
|
| 81 | - elseif ($losingGroupTeamsCount >= 2) { |
|
| 82 | + } elseif ($losingGroupTeamsCount >= 2) { |
|
| 82 | 83 | $previousLosingGroups[$g-1]->progression($group, 0, 1); // PROGRESS FROM LOSING GROUP BEFORE |
| 83 | - if (isset(array_reverse($previousGroups)[$g-1])) array_reverse($previousGroups)[$g-1]->progression($group, 1, 1); // PROGREESS FROM WINNING GROUP BEFORE |
|
| 84 | - else $previousLosingGroups[$g]->progression($group, 0, 1); // PROGRESS OTHER TEAM FROM LOSING GROUP BEEFORE |
|
| 84 | + if (isset(array_reverse($previousGroups)[$g-1])) { |
|
| 85 | + array_reverse($previousGroups)[$g-1]->progression($group, 1, 1); |
|
| 86 | + } |
|
| 87 | + // PROGREESS FROM WINNING GROUP BEFORE |
|
| 88 | + else { |
|
| 89 | + $previousLosingGroups[$g]->progression($group, 0, 1); |
|
| 90 | + } |
|
| 91 | + // PROGRESS OTHER TEAM FROM LOSING GROUP BEEFORE |
|
| 85 | 92 | } |
| 86 | 93 | } |
| 87 | - } |
|
| 88 | - else { // IF THE NUMBER OF TEAMS IS NOT A POWER OF 2, GENERATE GROUPS WITH BYES |
|
| 94 | + } else { // IF THE NUMBER OF TEAMS IS NOT A POWER OF 2, GENERATE GROUPS WITH BYES |
|
| 89 | 95 | // LOOK FOR THE CLOSEST LOWER POWER OF 2 |
| 90 | 96 | $losingByes = $losingGroupTeamsCount-bindec(str_pad(1, strlen(decbin($losingGroupTeamsCount)), 0, STR_PAD_RIGHT)); |
| 91 | 97 | $n = (floor(count($previousLosingGroups)/2)+$losingByes); |
@@ -109,10 +115,12 @@ discard block |
||
| 109 | 115 | if (in_array($g, $byesGroupsNums) && isset($previousGroups[$byesProgressed])) { // EMPTY GROUP FROM BYE |
| 110 | 116 | $previousGroups[$byesProgressed]->progression($group, 1, 1); // PROGRESS FROM WINNING GROUP BEFORE |
| 111 | 117 | $byesProgressed++; |
| 112 | - } |
|
| 113 | - else { |
|
| 118 | + } else { |
|
| 114 | 119 | $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 |
|
| 120 | + if (isset($previousLosingGroups[$lastGroup + 1])) { |
|
| 121 | + $previousLosingGroups[$lastGroup + 1]->progression($group, 0, 1); |
|
| 122 | + } |
|
| 123 | + // PROGREESS FROM LOSING GROUP BEFORE |
|
| 116 | 124 | $lastGroup += 2; |
| 117 | 125 | } |
| 118 | 126 | } |
@@ -43,12 +43,12 @@ |
||
| 43 | 43 | |
| 44 | 44 | private $groups = []; |
| 45 | 45 | |
| 46 | - function __construct(string $what = 'points', string $how = '>', $val = 0, $groups = []){ |
|
| 46 | + function __construct(string $what = 'points', string $how = '>', $val = 0, $groups = []) { |
|
| 47 | 47 | if (in_array(strtolower($what), ['points', 'score', 'wins', 'draws', 'losses', 'second', 'third', 'team', 'notprogressed', 'progressed'])) $this->what = strtolower($what); |
| 48 | 48 | if (in_array($how, ['>', '<', '>=', '<=', '=', '!='])) $this->how = $how; |
| 49 | 49 | if ((gettype($val) === 'integer' && strtolower($what) !== 'team') || ($val instanceof Team && strtolower($what) === 'team')) $this->val = $val; |
| 50 | 50 | foreach ($groups as $group) { |
| 51 | - if ($group instanceof Group) $this->groups[] = $group->id; |
|
| 51 | + if ($group instanceof Group) $this->groups[] = $group->id; |
|
| 52 | 52 | } |
| 53 | 53 | } |
| 54 | 54 | function __toString() { |
@@ -44,11 +44,19 @@ discard block |
||
| 44 | 44 | private $groups = []; |
| 45 | 45 | |
| 46 | 46 | function __construct(string $what = 'points', string $how = '>', $val = 0, $groups = []){ |
| 47 | - if (in_array(strtolower($what), ['points', 'score', 'wins', 'draws', 'losses', 'second', 'third', 'team', 'notprogressed', 'progressed'])) $this->what = strtolower($what); |
|
| 48 | - if (in_array($how, ['>', '<', '>=', '<=', '=', '!='])) $this->how = $how; |
|
| 49 | - if ((gettype($val) === 'integer' && strtolower($what) !== 'team') || ($val instanceof Team && strtolower($what) === 'team')) $this->val = $val; |
|
| 47 | + if (in_array(strtolower($what), ['points', 'score', 'wins', 'draws', 'losses', 'second', 'third', 'team', 'notprogressed', 'progressed'])) { |
|
| 48 | + $this->what = strtolower($what); |
|
| 49 | + } |
|
| 50 | + if (in_array($how, ['>', '<', '>=', '<=', '=', '!='])) { |
|
| 51 | + $this->how = $how; |
|
| 52 | + } |
|
| 53 | + if ((gettype($val) === 'integer' && strtolower($what) !== 'team') || ($val instanceof Team && strtolower($what) === 'team')) { |
|
| 54 | + $this->val = $val; |
|
| 55 | + } |
|
| 50 | 56 | foreach ($groups as $group) { |
| 51 | - if ($group instanceof Group) $this->groups[] = $group->id; |
|
| 57 | + if ($group instanceof Group) { |
|
| 58 | + $this->groups[] = $group->id; |
|
| 59 | + } |
|
| 52 | 60 | } |
| 53 | 61 | } |
| 54 | 62 | function __toString() { |
@@ -56,35 +64,48 @@ discard block |
||
| 56 | 64 | } |
| 57 | 65 | |
| 58 | 66 | public function validate(Team $team, $groupsId, string $operation = 'sum', Group $from = null) { |
| 59 | - if (count($this->groups) > 0) $groupsId = array_unique(array_merge($this->groups, (gettype($groupsId) === 'array' ? $groupsId : [$groupsId])), SORT_REGULAR); |
|
| 67 | + if (count($this->groups) > 0) { |
|
| 68 | + $groupsId = array_unique(array_merge($this->groups, (gettype($groupsId) === 'array' ? $groupsId : [$groupsId])), SORT_REGULAR); |
|
| 69 | + } |
|
| 60 | 70 | if ($this->what == 'team') { |
| 61 | 71 | switch ($this->how) { |
| 62 | 72 | case '=': |
| 63 | - if ($this->val === $team) return true; |
|
| 73 | + if ($this->val === $team) { |
|
| 74 | + return true; |
|
| 75 | + } |
|
| 64 | 76 | break; |
| 65 | 77 | case '!=': |
| 66 | - if ($this->val !== $team) return true; |
|
| 78 | + if ($this->val !== $team) { |
|
| 79 | + return true; |
|
| 80 | + } |
|
| 67 | 81 | break; |
| 68 | 82 | } |
| 69 | 83 | return false; |
| 70 | - } |
|
| 71 | - elseif ($this->what == 'notprogressed') { |
|
| 84 | + } elseif ($this->what == 'notprogressed') { |
|
| 72 | 85 | return !$from->progressed($team); |
| 73 | - } |
|
| 74 | - elseif ($this->what == 'progressed') { |
|
| 86 | + } elseif ($this->what == 'progressed') { |
|
| 75 | 87 | return $from->progressed($team); |
| 76 | 88 | } |
| 77 | - if (gettype($groupsId) === 'array' && !in_array(strtolower($operation), ['sum', 'avg', 'max', 'min'])) throw new Exception('Unknown operation of '.$sum.'. Only "sum", "avg", "min", "max" possible.'); |
|
| 89 | + if (gettype($groupsId) === 'array' && !in_array(strtolower($operation), ['sum', 'avg', 'max', 'min'])) { |
|
| 90 | + throw new Exception('Unknown operation of '.$sum.'. Only "sum", "avg", "min", "max" possible.'); |
|
| 91 | + } |
|
| 78 | 92 | $comp = 0; |
| 79 | 93 | if (gettype($groupsId) === 'array' && count($groupsId) > 0) { |
| 80 | 94 | $sum = 0; |
| 81 | 95 | $max = null; |
| 82 | 96 | $min = null; |
| 83 | 97 | foreach ($groupsId as $id) { |
| 84 | - if (!isset($team->groupResults[$id])) continue; // IF TEAM DIDN'T PLAY IN THAT GROUP -> SKIP |
|
| 98 | + if (!isset($team->groupResults[$id])) { |
|
| 99 | + continue; |
|
| 100 | + } |
|
| 101 | + // IF TEAM DIDN'T PLAY IN THAT GROUP -> SKIP |
|
| 85 | 102 | $sum += $team->groupResults[$id][$this->what]; |
| 86 | - if ($team->groupResults[$id][$this->what] > $max || $max === null) $max = $team->groupResults[$id][$this->what]; |
|
| 87 | - if ($team->groupResults[$id][$this->what] < $min || $min === null) $min = $team->groupResults[$id][$this->what]; |
|
| 103 | + if ($team->groupResults[$id][$this->what] > $max || $max === null) { |
|
| 104 | + $max = $team->groupResults[$id][$this->what]; |
|
| 105 | + } |
|
| 106 | + if ($team->groupResults[$id][$this->what] < $min || $min === null) { |
|
| 107 | + $min = $team->groupResults[$id][$this->what]; |
|
| 108 | + } |
|
| 88 | 109 | } |
| 89 | 110 | switch (strtolower($operation)) { |
| 90 | 111 | case 'sum': |
@@ -100,11 +121,9 @@ discard block |
||
| 100 | 121 | $comp = $min; |
| 101 | 122 | break; |
| 102 | 123 | } |
| 103 | - } |
|
| 104 | - elseif (gettype($groupsId) === 'string' && isset($team->groupResults[$groupsId])) { |
|
| 124 | + } elseif (gettype($groupsId) === 'string' && isset($team->groupResults[$groupsId])) { |
|
| 105 | 125 | $comp = $team->groupResults[$groupsId][$this->what]; |
| 106 | - } |
|
| 107 | - else { |
|
| 126 | + } else { |
|
| 108 | 127 | throw new Exception("Couldn't find group of id ".print_r($groupsId, true)); |
| 109 | 128 | } |
| 110 | 129 | |
@@ -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); |
@@ -76,10 +76,10 @@ discard block |
||
| 76 | 76 | 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)); |
| 77 | 77 | return $this; |
| 78 | 78 | } |
| 79 | - public function getTeams(){ |
|
| 79 | + public function getTeams() { |
|
| 80 | 80 | return $this->teams; |
| 81 | 81 | } |
| 82 | - public function getTeamsIds(){ |
|
| 82 | + public function getTeamsIds() { |
|
| 83 | 83 | $ids = []; |
| 84 | 84 | foreach ($this->teams as $team) { |
| 85 | 85 | $ids[] = $team->id; |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | $team->addLoss($this->group->id); |
| 127 | 127 | $this->results[$team->id] += ['points' => $this->group->lostPoints, 'type' => 'loss']; |
| 128 | 128 | } |
| 129 | - break;} |
|
| 129 | + break; } |
|
| 130 | 130 | case 3:{ |
| 131 | 131 | switch ($i) { |
| 132 | 132 | case 1: |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | $this->results[$team->id] += ['points' => $this->group->lostPoints, 'type' => 'loss']; |
| 146 | 146 | break; |
| 147 | 147 | } |
| 148 | - break;} |
|
| 148 | + break; } |
|
| 149 | 149 | case 4:{ |
| 150 | 150 | switch ($i) { |
| 151 | 151 | case 1: |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | $this->results[$team->id] += ['points' => $this->group->lostPoints, 'type' => 'loss']; |
| 170 | 170 | break; |
| 171 | 171 | } |
| 172 | - break;} |
|
| 172 | + break; } |
|
| 173 | 173 | } |
| 174 | 174 | $team->groupResults[$this->group->id]['score'] += $score; |
| 175 | 175 | $i++; |
@@ -25,9 +25,10 @@ discard block |
||
| 25 | 25 | if (!$team instanceof Team) { |
| 26 | 26 | $error[] = $team; |
| 27 | 27 | unset($teams[$key]); |
| 28 | - } |
|
| 29 | - else { |
|
| 30 | - if (!isset($team->games[$group->id])) $team->games[$group->id] = []; |
|
| 28 | + } else { |
|
| 29 | + if (!isset($team->games[$group->id])) { |
|
| 30 | + $team->games[$group->id] = []; |
|
| 31 | + } |
|
| 31 | 32 | $team->games[$group->id][] = $this; |
| 32 | 33 | $tids[] = $team->id; |
| 33 | 34 | } |
@@ -36,12 +37,16 @@ discard block |
||
| 36 | 37 | foreach ($this->teams as $team) { |
| 37 | 38 | foreach ($tids as $id) { |
| 38 | 39 | if ($team->id !== $id) { |
| 39 | - if (!isset($team->gamesWith[$group->id][$id])) $team->gamesWith[$group->id][$id] = 0; |
|
| 40 | + if (!isset($team->gamesWith[$group->id][$id])) { |
|
| 41 | + $team->gamesWith[$group->id][$id] = 0; |
|
| 42 | + } |
|
| 40 | 43 | $team->gamesWith[$group->id][$id]++; |
| 41 | 44 | } |
| 42 | 45 | } |
| 43 | 46 | } |
| 44 | - 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)); |
|
| 47 | + if (count($error) > 0) { |
|
| 48 | + throw new Exception('Trying to add teams ('.count($error).') that are not instance of Team class'.PHP_EOL.print_r($error, true)); |
|
| 49 | + } |
|
| 45 | 50 | } |
| 46 | 51 | |
| 47 | 52 | public function addTeam(...$teams) { |
@@ -49,9 +54,13 @@ discard block |
||
| 49 | 54 | foreach ($this->teams as $team) { |
| 50 | 55 | foreach ($teams as $team2) { |
| 51 | 56 | if ($team2 instanceof Team) { |
| 52 | - if (!isset($team->gamesWith[$this->group->id][$team2->id])) $team->gamesWith[$this->group->id][$team2->id] = 0; |
|
| 57 | + if (!isset($team->gamesWith[$this->group->id][$team2->id])) { |
|
| 58 | + $team->gamesWith[$this->group->id][$team2->id] = 0; |
|
| 59 | + } |
|
| 53 | 60 | $team->gamesWith[$this->group->id][$team2->id]++; |
| 54 | - if (!isset($team2->gamesWith[$this->group->id][$team->id])) $team2->gamesWith[$this->group->id][$team->id] = 0; |
|
| 61 | + if (!isset($team2->gamesWith[$this->group->id][$team->id])) { |
|
| 62 | + $team2->gamesWith[$this->group->id][$team->id] = 0; |
|
| 63 | + } |
|
| 55 | 64 | $team2->gamesWith[$this->group->id][$team->id]++; |
| 56 | 65 | } |
| 57 | 66 | } |
@@ -59,21 +68,26 @@ discard block |
||
| 59 | 68 | foreach ($teams as $key => $team) { |
| 60 | 69 | if ($team instanceof Team) { |
| 61 | 70 | $this->teams[] = $team; |
| 62 | - if (!isset($team->games[$this->group->id])) $team->games[$this->group->id] = []; |
|
| 71 | + if (!isset($team->games[$this->group->id])) { |
|
| 72 | + $team->games[$this->group->id] = []; |
|
| 73 | + } |
|
| 63 | 74 | $team->games[$this->group->id][] = $this; |
| 64 | 75 | foreach ($teams as $key2 => $team2) { |
| 65 | 76 | if ($team2 instanceof Team) { |
| 66 | - if (!isset($team->gamesWith[$this->group->id][$team2->id])) $team->gamesWith[$this->group->id][$team2->id] = 0; |
|
| 77 | + if (!isset($team->gamesWith[$this->group->id][$team2->id])) { |
|
| 78 | + $team->gamesWith[$this->group->id][$team2->id] = 0; |
|
| 79 | + } |
|
| 67 | 80 | $team->gamesWith[$this->group->id][$team2->id]++; |
| 68 | 81 | } |
| 69 | 82 | } |
| 70 | - } |
|
| 71 | - else { |
|
| 83 | + } else { |
|
| 72 | 84 | $error[] = $team; |
| 73 | 85 | unset($teams[$key]); |
| 74 | 86 | } |
| 75 | 87 | } |
| 76 | - 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)); |
|
| 88 | + if (count($error) > 0) { |
|
| 89 | + throw new Exception('Trying to add teams ('.count($error).') that are not instance of Team class'.PHP_EOL.print_r($error, true)); |
|
| 90 | + } |
|
| 77 | 91 | return $this; |
| 78 | 92 | } |
| 79 | 93 | public function getTeams(){ |
@@ -88,7 +102,9 @@ discard block |
||
| 88 | 102 | } |
| 89 | 103 | public function getTeam(string $id) { |
| 90 | 104 | foreach ($this->teams as $team) { |
| 91 | - if ($team->id === $id) return $team; |
|
| 105 | + if ($team->id === $id) { |
|
| 106 | + return $team; |
|
| 107 | + } |
|
| 92 | 108 | } |
| 93 | 109 | return false; |
| 94 | 110 | } |
@@ -99,12 +115,16 @@ discard block |
||
| 99 | 115 | * ) |
| 100 | 116 | */ |
| 101 | 117 | public function setResults(array $results = []) { |
| 102 | - if (count($this->results) === 0) $this->resetResults(); |
|
| 118 | + if (count($this->results) === 0) { |
|
| 119 | + $this->resetResults(); |
|
| 120 | + } |
|
| 103 | 121 | arsort($results); |
| 104 | 122 | $i = 1; |
| 105 | 123 | foreach ($results as $id => $score) { |
| 106 | 124 | $team = $this->getTeam($id); |
| 107 | - if ($team === false) throw new Exception('Couldn\'t find team with id of "'.$id.'"'); |
|
| 125 | + if ($team === false) { |
|
| 126 | + throw new Exception('Couldn\'t find team with id of "'.$id.'"'); |
|
| 127 | + } |
|
| 108 | 128 | $this->results[$team->id] = ['score' => $score]; |
| 109 | 129 | $prev = prev($results); |
| 110 | 130 | next($results); |
@@ -115,13 +135,11 @@ discard block |
||
| 115 | 135 | $this->drawIds[] = $team->id; |
| 116 | 136 | $team->addDraw($this->group->id); |
| 117 | 137 | $this->results[$team->id] += ['points' => $this->group->drawPoints, 'type' => 'draw']; |
| 118 | - } |
|
| 119 | - elseif ($i === 1) { |
|
| 138 | + } elseif ($i === 1) { |
|
| 120 | 139 | $this->winId = $team->id; |
| 121 | 140 | $team->addWin($this->group->id); |
| 122 | 141 | $this->results[$team->id] += ['points' => $this->group->winPoints, 'type' => 'win']; |
| 123 | - } |
|
| 124 | - else { |
|
| 142 | + } else { |
|
| 125 | 143 | $this->lossId = $team->id; |
| 126 | 144 | $team->addLoss($this->group->id); |
| 127 | 145 | $this->results[$team->id] += ['points' => $this->group->lostPoints, 'type' => 'loss']; |
@@ -218,7 +236,9 @@ discard block |
||
| 218 | 236 | } |
| 219 | 237 | |
| 220 | 238 | public function isPlayed() { |
| 221 | - if (count($this->results) > 0) return true; |
|
| 239 | + if (count($this->results) > 0) { |
|
| 240 | + return true; |
|
| 241 | + } |
|
| 222 | 242 | return false; |
| 223 | 243 | } |
| 224 | 244 | } |
@@ -66,11 +66,11 @@ discard block |
||
| 66 | 66 | return 'Group '.$this->name; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - public function allowSkip(){ |
|
| 69 | + public function allowSkip() { |
|
| 70 | 70 | $this->allowSkip = true; |
| 71 | 71 | return $this; |
| 72 | 72 | } |
| 73 | - public function disallowSkip(){ |
|
| 73 | + public function disallowSkip() { |
|
| 74 | 74 | $this->allowSkip = false; |
| 75 | 75 | return $this; |
| 76 | 76 | } |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | |
| 85 | 85 | public function addTeam(...$teams) { |
| 86 | 86 | foreach ($teams as $team) { |
| 87 | - if ($team instanceof Team) { |
|
| 87 | + if ($team instanceof Team) { |
|
| 88 | 88 | $this->teams[] = $team; |
| 89 | 89 | $team->groupResults[$this->id] = [ |
| 90 | 90 | 'group' => $this, |
@@ -242,13 +242,13 @@ discard block |
||
| 242 | 242 | if ($a->groupResults[$this->id]["points"] === $b->groupResults[$this->id]["points"]) return ($a->groupResults[$this->id]["score"] > $b->groupResults[$this->id]["score"] ? -1 : 1); |
| 243 | 243 | return ($a->groupResults[$this->id]["points"] > $b->groupResults[$this->id]["points"] ? -1 : 1); |
| 244 | 244 | }); |
| 245 | - break;} |
|
| 245 | + break; } |
|
| 246 | 246 | case SCORE:{ |
| 247 | 247 | usort($this->teams, function($a, $b) { |
| 248 | 248 | if ($a->groupResults[$this->id]["score"] === $b->groupResults[$this->id]["score"]) return 0; |
| 249 | 249 | return ($a->groupResults[$this->id]["score"] > $b->groupResults[$this->id]["score"] ? -1 : 1); |
| 250 | 250 | }); |
| 251 | - break;} |
|
| 251 | + break; } |
|
| 252 | 252 | } |
| 253 | 253 | return $this->getTeams($filters); |
| 254 | 254 | } |
@@ -313,19 +313,19 @@ discard block |
||
| 313 | 313 | switch ($this->type) { |
| 314 | 314 | case R_R:{ |
| 315 | 315 | $this->games = $this->r_rGames(); |
| 316 | - break;} |
|
| 316 | + break; } |
|
| 317 | 317 | case TWO_TWO: |
| 318 | 318 | $teams = $this->teams; |
| 319 | 319 | $discard = []; |
| 320 | 320 | shuffle($teams); |
| 321 | 321 | $count = count($teams); |
| 322 | - while (count($teams) % $this->inGame !== 0) { |
|
| 322 | + while (count($teams)%$this->inGame !== 0) { |
|
| 323 | 323 | $discard[] = array_shift($teams); |
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | while (count($teams) > 0) { |
| 327 | 327 | $tInGame = []; |
| 328 | - for ($i=0; $i < $this->inGame; $i++) { |
|
| 328 | + for ($i = 0; $i < $this->inGame; $i++) { |
|
| 329 | 329 | $tInGame[] = array_shift($teams); |
| 330 | 330 | } |
| 331 | 331 | $this->game($tInGame); |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | $this->games[] = $g; |
| 365 | 365 | return $g; |
| 366 | 366 | } |
| 367 | - public function addGame(Game ...$games){ |
|
| 367 | + public function addGame(Game ...$games) { |
|
| 368 | 368 | foreach ($game as $game) { |
| 369 | 369 | if ($game instanceof Game) $this->games[] = $game; |
| 370 | 370 | else throw new Exception('Trying to add game which is not instance of Game object.'); |
@@ -460,7 +460,7 @@ discard block |
||
| 460 | 460 | foreach ($games as $key => $game) { |
| 461 | 461 | $gTeams = $game->getTeamsIds(); |
| 462 | 462 | $suitable = true; |
| 463 | - $requiredTeams = array_filter($teams, function($a){ |
|
| 463 | + $requiredTeams = array_filter($teams, function($a) { |
|
| 464 | 464 | return $a < 4; |
| 465 | 465 | }); |
| 466 | 466 | foreach ($gTeams as $tid) { |
@@ -511,7 +511,7 @@ discard block |
||
| 511 | 511 | foreach ($games as $key => $game) { |
| 512 | 512 | $gTeams = $game->getTeamsIds(); |
| 513 | 513 | $suitable = false; |
| 514 | - $requiredTeams = array_filter($teams, function($a){ |
|
| 514 | + $requiredTeams = array_filter($teams, function($a) { |
|
| 515 | 515 | return $a < 4; |
| 516 | 516 | }); |
| 517 | 517 | foreach ($gTeams as $tid) { |
@@ -556,7 +556,7 @@ discard block |
||
| 556 | 556 | $games = array_merge($games, $games); |
| 557 | 557 | } |
| 558 | 558 | // $this->orderGames(); |
| 559 | - break;} |
|
| 559 | + break; } |
|
| 560 | 560 | case 4:{ |
| 561 | 561 | $teamsB = $teams; |
| 562 | 562 | $lockedTeam1 = array_shift($teamsB); |
@@ -574,7 +574,7 @@ discard block |
||
| 574 | 574 | } |
| 575 | 575 | $games[] = new Game(array_merge([$lockedTeam1], $teamsB), $this); |
| 576 | 576 | // $this->orderGames(); |
| 577 | - break;} |
|
| 577 | + break; } |
|
| 578 | 578 | } |
| 579 | 579 | return $games; |
| 580 | 580 | } |
@@ -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 | } |
@@ -31,23 +31,36 @@ discard block |
||
| 31 | 31 | foreach ($settings as $key => $value) { |
| 32 | 32 | switch ($key) { |
| 33 | 33 | case 'name': |
| 34 | - if (gettype($value) === 'string') $this->name = $value; |
|
| 35 | - else throw new Exception('Expected string as group name '.gettype($value).' given'); |
|
| 34 | + if (gettype($value) === 'string') { |
|
| 35 | + $this->name = $value; |
|
| 36 | + } else { |
|
| 37 | + throw new Exception('Expected string as group name '.gettype($value).' given'); |
|
| 38 | + } |
|
| 36 | 39 | break; |
| 37 | 40 | case 'type': |
| 38 | - if (in_array($value, groupTypes)) $this->type = $value; |
|
| 39 | - else throw new Exception('Unknown group type: '.$value); |
|
| 41 | + if (in_array($value, groupTypes)) { |
|
| 42 | + $this->type = $value; |
|
| 43 | + } else { |
|
| 44 | + throw new Exception('Unknown group type: '.$value); |
|
| 45 | + } |
|
| 40 | 46 | break; |
| 41 | 47 | case 'ordering': |
| 42 | - if (in_array($value, orderingTypes)) $this->ordering = $value; |
|
| 43 | - else throw new Exception('Unknown group ordering: '.$value); |
|
| 48 | + if (in_array($value, orderingTypes)) { |
|
| 49 | + $this->ordering = $value; |
|
| 50 | + } else { |
|
| 51 | + throw new Exception('Unknown group ordering: '.$value); |
|
| 52 | + } |
|
| 44 | 53 | break; |
| 45 | 54 | case 'inGame': |
| 46 | 55 | if (gettype($value) === 'integer') { |
| 47 | - if ($value === 2 || $value === 3 || $value === 4) $this->inGame = $value; |
|
| 48 | - else throw new Exception('Expected 2,3 or 4 as inGame '.$value.' given'); |
|
| 56 | + if ($value === 2 || $value === 3 || $value === 4) { |
|
| 57 | + $this->inGame = $value; |
|
| 58 | + } else { |
|
| 59 | + throw new Exception('Expected 2,3 or 4 as inGame '.$value.' given'); |
|
| 60 | + } |
|
| 61 | + } else { |
|
| 62 | + throw new Exception('Expected integer as inGame '.gettype($value).' given'); |
|
| 49 | 63 | } |
| 50 | - else throw new Exception('Expected integer as inGame '.gettype($value).' given'); |
|
| 51 | 64 | break; |
| 52 | 65 | case 'maxSize': |
| 53 | 66 | if (gettype($value) === 'integer') { |
@@ -96,10 +109,11 @@ discard block |
||
| 96 | 109 | 'second' => 0, |
| 97 | 110 | 'third' => 0 |
| 98 | 111 | ]; |
| 99 | - } |
|
| 100 | - elseif (gettype($team) === 'array') { |
|
| 112 | + } elseif (gettype($team) === 'array') { |
|
| 101 | 113 | foreach ($team as $team2) { |
| 102 | - if ($team2 instanceof Team) $this->teams[] = $team2; |
|
| 114 | + if ($team2 instanceof Team) { |
|
| 115 | + $this->teams[] = $team2; |
|
| 116 | + } |
|
| 103 | 117 | $team2->groupResults[$this->id] = [ |
| 104 | 118 | 'group' => $this, |
| 105 | 119 | 'points' => 0, |
@@ -111,16 +125,20 @@ discard block |
||
| 111 | 125 | 'third' => 0 |
| 112 | 126 | ]; |
| 113 | 127 | } |
| 128 | + } else { |
|
| 129 | + throw new Exception('Trying to add team which is not an instance of Team class'); |
|
| 114 | 130 | } |
| 115 | - else throw new Exception('Trying to add team which is not an instance of Team class'); |
|
| 116 | 131 | } |
| 117 | 132 | return $this; |
| 118 | 133 | } |
| 119 | 134 | public function getTeams($filters = []) { |
| 120 | 135 | $teams = $this->teams; |
| 121 | 136 | |
| 122 | - if (gettype($filters) !== 'array' && $filters instanceof TeamFilter) $filters = [$filters]; |
|
| 123 | - elseif (gettype($filters) !== 'array') $filters = []; |
|
| 137 | + if (gettype($filters) !== 'array' && $filters instanceof TeamFilter) { |
|
| 138 | + $filters = [$filters]; |
|
| 139 | + } elseif (gettype($filters) !== 'array') { |
|
| 140 | + $filters = []; |
|
| 141 | + } |
|
| 124 | 142 | |
| 125 | 143 | // APPLY FILTERS |
| 126 | 144 | foreach ($filters as $key => $filter) { |
@@ -140,15 +158,13 @@ discard block |
||
| 140 | 158 | throw new Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".'); |
| 141 | 159 | break; |
| 142 | 160 | } |
| 143 | - } |
|
| 144 | - elseif ($filter instanceof TeamFilter) { |
|
| 161 | + } elseif ($filter instanceof TeamFilter) { |
|
| 145 | 162 | foreach ($teams as $tkey => $team) { |
| 146 | 163 | if (!$filter->validate($team, $this->id, 'sum', $this)) { |
| 147 | 164 | unset($teams[$tkey]); // IF FILTER IS NOT VALIDATED REMOVE TEAM FROM RETURN ARRAY |
| 148 | 165 | } |
| 149 | 166 | } |
| 150 | - } |
|
| 151 | - else { |
|
| 167 | + } else { |
|
| 152 | 168 | throw new Exception('Filer ['.$key.'] is not an instance of TeamFilter class'); |
| 153 | 169 | return []; |
| 154 | 170 | } |
@@ -160,20 +176,24 @@ discard block |
||
| 160 | 176 | if (gettype($value) === 'array') { |
| 161 | 177 | switch (strtolower($key)) { |
| 162 | 178 | case 'and': |
| 163 | - if ($this->filterAnd($team, $value)) return false; |
|
| 179 | + if ($this->filterAnd($team, $value)) { |
|
| 180 | + return false; |
|
| 181 | + } |
|
| 164 | 182 | break; |
| 165 | 183 | case 'or': |
| 166 | - if ($this->filterOr($team, $value)) return false; |
|
| 184 | + if ($this->filterOr($team, $value)) { |
|
| 185 | + return false; |
|
| 186 | + } |
|
| 167 | 187 | break; |
| 168 | 188 | default: |
| 169 | 189 | throw new Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".'); |
| 170 | 190 | break; |
| 171 | 191 | } |
| 172 | - } |
|
| 173 | - elseif ($value instanceof TeamFilter) { |
|
| 174 | - if (!$filter->validate($team, $this->id, 'sum', $this)) return false; |
|
| 175 | - } |
|
| 176 | - else { |
|
| 192 | + } elseif ($value instanceof TeamFilter) { |
|
| 193 | + if (!$filter->validate($team, $this->id, 'sum', $this)) { |
|
| 194 | + return false; |
|
| 195 | + } |
|
| 196 | + } else { |
|
| 177 | 197 | throw new Exception('Filer ['.$key.'] is not an instance of TeamFilter class'); |
| 178 | 198 | } |
| 179 | 199 | } |
@@ -184,20 +204,24 @@ discard block |
||
| 184 | 204 | if (gettype($value) === 'array') { |
| 185 | 205 | switch (strtolower($key)) { |
| 186 | 206 | case 'and': |
| 187 | - if ($this->filterAnd($team, $value)) return true; |
|
| 207 | + if ($this->filterAnd($team, $value)) { |
|
| 208 | + return true; |
|
| 209 | + } |
|
| 188 | 210 | break; |
| 189 | 211 | case 'or': |
| 190 | - if ($this->filterOr($team, $value)) return true; |
|
| 212 | + if ($this->filterOr($team, $value)) { |
|
| 213 | + return true; |
|
| 214 | + } |
|
| 191 | 215 | break; |
| 192 | 216 | default: |
| 193 | 217 | throw new Exception('Unknown opperand type "'.$key.'". Expected "and" or "or".'); |
| 194 | 218 | break; |
| 195 | 219 | } |
| 196 | - } |
|
| 197 | - elseif ($value instanceof TeamFilter) { |
|
| 198 | - if (!$filter->validate($team, $this->id, 'sum', $this)) return true; |
|
| 199 | - } |
|
| 200 | - else { |
|
| 220 | + } elseif ($value instanceof TeamFilter) { |
|
| 221 | + if (!$filter->validate($team, $this->id, 'sum', $this)) { |
|
| 222 | + return true; |
|
| 223 | + } |
|
| 224 | + } else { |
|
| 201 | 225 | throw new Exception('Filer ['.$key.'] is not an instance of TeamFilter class'); |
| 202 | 226 | } |
| 203 | 227 | } |
@@ -219,16 +243,22 @@ discard block |
||
| 219 | 243 | return $t; |
| 220 | 244 | } |
| 221 | 245 | public function setType(string $type = R_R) { |
| 222 | - if (in_array($type, groupTypes)) $this->type = $type; |
|
| 223 | - else throw new Exception('Unknown group type: '.$type); |
|
| 246 | + if (in_array($type, groupTypes)) { |
|
| 247 | + $this->type = $type; |
|
| 248 | + } else { |
|
| 249 | + throw new Exception('Unknown group type: '.$type); |
|
| 250 | + } |
|
| 224 | 251 | return $this; |
| 225 | 252 | } |
| 226 | 253 | public function getType() { |
| 227 | 254 | return $this->type; |
| 228 | 255 | } |
| 229 | 256 | public function setOrdering(string $ordering = POINTS) { |
| 230 | - if (in_array($ordering, orderingTypes)) $this->ordering = $ordering; |
|
| 231 | - else throw new Exception('Unknown group ordering: '.$ordering); |
|
| 257 | + if (in_array($ordering, orderingTypes)) { |
|
| 258 | + $this->ordering = $ordering; |
|
| 259 | + } else { |
|
| 260 | + throw new Exception('Unknown group ordering: '.$ordering); |
|
| 261 | + } |
|
| 232 | 262 | return $this; |
| 233 | 263 | } |
| 234 | 264 | public function getOrdering() { |
@@ -238,14 +268,20 @@ discard block |
||
| 238 | 268 | switch ($this->ordering) { |
| 239 | 269 | case POINTS:{ |
| 240 | 270 | usort($this->teams, function($a, $b) { |
| 241 | - if ($a->groupResults[$this->id]["points"] === $b->groupResults[$this->id]["points"] && $a->groupResults[$this->id]["score"] === $b->groupResults[$this->id]["score"]) return 0; |
|
| 242 | - if ($a->groupResults[$this->id]["points"] === $b->groupResults[$this->id]["points"]) return ($a->groupResults[$this->id]["score"] > $b->groupResults[$this->id]["score"] ? -1 : 1); |
|
| 271 | + if ($a->groupResults[$this->id]["points"] === $b->groupResults[$this->id]["points"] && $a->groupResults[$this->id]["score"] === $b->groupResults[$this->id]["score"]) { |
|
| 272 | + return 0; |
|
| 273 | + } |
|
| 274 | + if ($a->groupResults[$this->id]["points"] === $b->groupResults[$this->id]["points"]) { |
|
| 275 | + return ($a->groupResults[$this->id]["score"] > $b->groupResults[$this->id]["score"] ? -1 : 1); |
|
| 276 | + } |
|
| 243 | 277 | return ($a->groupResults[$this->id]["points"] > $b->groupResults[$this->id]["points"] ? -1 : 1); |
| 244 | 278 | }); |
| 245 | 279 | break;} |
| 246 | 280 | case SCORE:{ |
| 247 | 281 | usort($this->teams, function($a, $b) { |
| 248 | - if ($a->groupResults[$this->id]["score"] === $b->groupResults[$this->id]["score"]) return 0; |
|
| 282 | + if ($a->groupResults[$this->id]["score"] === $b->groupResults[$this->id]["score"]) { |
|
| 283 | + return 0; |
|
| 284 | + } |
|
| 249 | 285 | return ($a->groupResults[$this->id]["score"] > $b->groupResults[$this->id]["score"] ? -1 : 1); |
| 250 | 286 | }); |
| 251 | 287 | break;} |
@@ -254,17 +290,24 @@ discard block |
||
| 254 | 290 | } |
| 255 | 291 | public function setInGame(int $inGame) { |
| 256 | 292 | if (gettype($inGame) === 'integer') { |
| 257 | - if ($inGame === 2 || $inGame === 3 || $inGame === 4) $this->inGame = $inGame; |
|
| 258 | - else throw new Exception('Expected 2,3 or 4 as inGame '.$inGame.' given'); |
|
| 293 | + if ($inGame === 2 || $inGame === 3 || $inGame === 4) { |
|
| 294 | + $this->inGame = $inGame; |
|
| 295 | + } else { |
|
| 296 | + throw new Exception('Expected 2,3 or 4 as inGame '.$inGame.' given'); |
|
| 297 | + } |
|
| 298 | + } else { |
|
| 299 | + throw new Exception('Expected integer as inGame '.gettype($inGame).' given'); |
|
| 259 | 300 | } |
| 260 | - else throw new Exception('Expected integer as inGame '.gettype($inGame).' given'); |
|
| 261 | 301 | } |
| 262 | 302 | public function getInGame() { |
| 263 | 303 | return $this->inGame; |
| 264 | 304 | } |
| 265 | 305 | public function addProgression(Progression $progression) { |
| 266 | - if ($progression instanceof Progression) $this->progressions[] = $progression; |
|
| 267 | - else throw new Exception('Trying to add progression which is not an instance of Progression class'); |
|
| 306 | + if ($progression instanceof Progression) { |
|
| 307 | + $this->progressions[] = $progression; |
|
| 308 | + } else { |
|
| 309 | + throw new Exception('Trying to add progression which is not an instance of Progression class'); |
|
| 310 | + } |
|
| 268 | 311 | return $this; |
| 269 | 312 | } |
| 270 | 313 | public function progression(Group $to, int $start = 0, int $len = null) { |
@@ -286,16 +329,13 @@ discard block |
||
| 286 | 329 | foreach ($teams as $team) { |
| 287 | 330 | if ($team instanceOf Team) { |
| 288 | 331 | $this->progressed[] = $team->id; |
| 289 | - } |
|
| 290 | - elseif (gettype($team) === 'string' || gettype($team) === 'integer') { |
|
| 332 | + } elseif (gettype($team) === 'string' || gettype($team) === 'integer') { |
|
| 291 | 333 | $this->progressed[] = $team; |
| 292 | - } |
|
| 293 | - elseif (gettype($team) === 'array') { |
|
| 334 | + } elseif (gettype($team) === 'array') { |
|
| 294 | 335 | foreach ($team as $teamInner) { |
| 295 | 336 | if ($teamInner instanceOf Team) { |
| 296 | 337 | $this->progressed[] = $teamInner->id; |
| 297 | - } |
|
| 298 | - elseif (gettype($teamInner) === 'string' || gettype($teamInner) === 'integer') { |
|
| 338 | + } elseif (gettype($teamInner) === 'string' || gettype($teamInner) === 'integer') { |
|
| 299 | 339 | $this->progressed[] = $teamInner; |
| 300 | 340 | } |
| 301 | 341 | } |
@@ -349,12 +389,15 @@ discard block |
||
| 349 | 389 | while ($g > 0) { |
| 350 | 390 | foreach ($games as $key => $group) { |
| 351 | 391 | $this->games[] = array_shift($games[$key]); |
| 352 | - if (count($games[$key]) === 0) unset($games[$key]); |
|
| 392 | + if (count($games[$key]) === 0) { |
|
| 393 | + unset($games[$key]); |
|
| 394 | + } |
|
| 353 | 395 | $g--; |
| 354 | 396 | } |
| 355 | 397 | } |
| 398 | + } else { |
|
| 399 | + $this->games = $this->r_rGames(); |
|
| 356 | 400 | } |
| 357 | - else $this->games = $this->r_rGames(); |
|
| 358 | 401 | break; |
| 359 | 402 | } |
| 360 | 403 | return $this->games; |
@@ -366,8 +409,11 @@ discard block |
||
| 366 | 409 | } |
| 367 | 410 | public function addGame(Game ...$games){ |
| 368 | 411 | foreach ($game 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.'); |
|
| 412 | + if ($game instanceof Game) { |
|
| 413 | + $this->games[] = $game; |
|
| 414 | + } else { |
|
| 415 | + throw new Exception('Trying to add game which is not instance of Game object.'); |
|
| 416 | + } |
|
| 371 | 417 | } |
| 372 | 418 | return $this; |
| 373 | 419 | } |
@@ -395,21 +441,30 @@ discard block |
||
| 395 | 441 | $teams[$team->id] = 0; |
| 396 | 442 | } |
| 397 | 443 | foreach (end($this->games)->getTeams() as $team) { |
| 398 | - if (!isset($teams[$team->id])) $teams[$team->id] = 4; |
|
| 399 | - else $teams[$team->id] += 4; |
|
| 444 | + if (!isset($teams[$team->id])) { |
|
| 445 | + $teams[$team->id] = 4; |
|
| 446 | + } else { |
|
| 447 | + $teams[$team->id] += 4; |
|
| 448 | + } |
|
| 400 | 449 | } |
| 401 | 450 | $g = prev($this->games); |
| 402 | 451 | if ($g instanceof Game) { |
| 403 | 452 | foreach ($g->getTeams() as $team) { |
| 404 | - if (!isset($teams[$team->id])) $teams[$team->id] = 2; |
|
| 405 | - else $teams[$team->id] += 2; |
|
| 453 | + if (!isset($teams[$team->id])) { |
|
| 454 | + $teams[$team->id] = 2; |
|
| 455 | + } else { |
|
| 456 | + $teams[$team->id] += 2; |
|
| 457 | + } |
|
| 406 | 458 | } |
| 407 | 459 | } |
| 408 | 460 | $g = prev($this->games); |
| 409 | 461 | if ($g instanceof Game) { |
| 410 | 462 | foreach ($g->getTeams() as $team) { |
| 411 | - if (!isset($teams[$team->id])) $teams[$team->id] = 1; |
|
| 412 | - else $teams[$team->id]++; |
|
| 463 | + if (!isset($teams[$team->id])) { |
|
| 464 | + $teams[$team->id] = 1; |
|
| 465 | + } else { |
|
| 466 | + $teams[$team->id]++; |
|
| 467 | + } |
|
| 413 | 468 | } |
| 414 | 469 | } |
| 415 | 470 | |
@@ -431,7 +486,9 @@ discard block |
||
| 431 | 486 | break; |
| 432 | 487 | } |
| 433 | 488 | } |
| 434 | - if ($found) continue; |
|
| 489 | + if ($found) { |
|
| 490 | + continue; |
|
| 491 | + } |
|
| 435 | 492 | |
| 436 | 493 | // CYCLE 2 |
| 437 | 494 | // ! TEAM WHICH PLAYED IN LAST TWO GAMES (NOT 6 or 7) |
@@ -452,7 +509,9 @@ discard block |
||
| 452 | 509 | break; |
| 453 | 510 | } |
| 454 | 511 | } |
| 455 | - if ($found) continue; |
|
| 512 | + if ($found) { |
|
| 513 | + continue; |
|
| 514 | + } |
|
| 456 | 515 | |
| 457 | 516 | // CYCLE 3 |
| 458 | 517 | // ! TEAM WHICH PLAYED IN LAST THREE GAMES (NOT 7) |
@@ -483,7 +542,9 @@ discard block |
||
| 483 | 542 | break; |
| 484 | 543 | } |
| 485 | 544 | } |
| 486 | - if ($found) continue; |
|
| 545 | + if ($found) { |
|
| 546 | + continue; |
|
| 547 | + } |
|
| 487 | 548 | |
| 488 | 549 | // CYCLE 4 |
| 489 | 550 | // ! TEAM WHICH PLAYED IN LAST THREE GAMES (NOT 7) |
@@ -504,7 +565,9 @@ discard block |
||
| 504 | 565 | break; |
| 505 | 566 | } |
| 506 | 567 | } |
| 507 | - if ($found) continue; |
|
| 568 | + if ($found) { |
|
| 569 | + continue; |
|
| 570 | + } |
|
| 508 | 571 | |
| 509 | 572 | // CYCLE 5 |
| 510 | 573 | // TEAMS THAT DIDN'T PLAY IN LAST GAME WILL PLAY THIS GAME (< 4) |
@@ -529,7 +592,9 @@ discard block |
||
| 529 | 592 | break; |
| 530 | 593 | } |
| 531 | 594 | } |
| 532 | - if ($found) continue; |
|
| 595 | + if ($found) { |
|
| 596 | + continue; |
|
| 597 | + } |
|
| 533 | 598 | |
| 534 | 599 | // CYCLE 6 |
| 535 | 600 | // FIRST AVAILABLE GAME |
@@ -540,7 +605,9 @@ discard block |
||
| 540 | 605 | } |
| 541 | 606 | public function r_rGames(array $teams = []) { |
| 542 | 607 | $games = []; |
| 543 | - if (count($teams) === 0) $teams = $this->teams; |
|
| 608 | + if (count($teams) === 0) { |
|
| 609 | + $teams = $this->teams; |
|
| 610 | + } |
|
| 544 | 611 | switch ($this->inGame) { |
| 545 | 612 | case 2: |
| 546 | 613 | $games = circle_genGames2($teams, $this); |
@@ -589,7 +656,9 @@ discard block |
||
| 589 | 656 | $game->setResults($results); |
| 590 | 657 | } |
| 591 | 658 | $return = $this->sortTeams($filters); |
| 592 | - if (!$reset) return $return; |
|
| 659 | + if (!$reset) { |
|
| 660 | + return $return; |
|
| 661 | + } |
|
| 593 | 662 | foreach ($this->getGames() as $game) { |
| 594 | 663 | $game->resetResults(); |
| 595 | 664 | } |
@@ -597,13 +666,17 @@ discard block |
||
| 597 | 666 | } |
| 598 | 667 | public function resetGames() { |
| 599 | 668 | foreach ($this->getGames() as $game) { |
| 600 | - if (isset($game)) $game->resetResults(); |
|
| 669 | + if (isset($game)) { |
|
| 670 | + $game->resetResults(); |
|
| 671 | + } |
|
| 601 | 672 | } |
| 602 | 673 | return $this; |
| 603 | 674 | } |
| 604 | 675 | public function isPlayed(){ |
| 605 | 676 | foreach ($this->games as $game) { |
| 606 | - if ((isset($game) || !$this->getSkip()) && !$game->isPlayed()) return false; |
|
| 677 | + if ((isset($game) || !$this->getSkip()) && !$game->isPlayed()) { |
|
| 678 | + return false; |
|
| 679 | + } |
|
| 607 | 680 | } |
| 608 | 681 | return true; |
| 609 | 682 | } |
@@ -43,7 +43,7 @@ |
||
| 43 | 43 | return $this; |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - public function progressBlank(){ |
|
| 46 | + public function progressBlank() { |
|
| 47 | 47 | $teams = $this->from->isPlayed() ? $this->from->sortTeams($this->filters) : $this->from->simulate($this->filters); |
| 48 | 48 | if (count($this->filters) === 0 || $this->len !== null || $this->start !== 0) $next = array_splice($teams, $this->start, ($this->len == null ? count($teams) : $this->len)); |
| 49 | 49 | else $next = $teams; |
@@ -27,7 +27,9 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | public function addFilter(...$filters) { |
| 29 | 29 | foreach ($filters as $filter) { |
| 30 | - if (!$filter instanceof TeamFilter) throw new Exception('Trying to add filter which is not an instance of TeamFilter.'); |
|
| 30 | + if (!$filter instanceof TeamFilter) { |
|
| 31 | + throw new Exception('Trying to add filter which is not an instance of TeamFilter.'); |
|
| 32 | + } |
|
| 31 | 33 | $this->filters[] = $filter; |
| 32 | 34 | } |
| 33 | 35 | $this->filter[] = $filter; |
@@ -36,8 +38,11 @@ discard block |
||
| 36 | 38 | |
| 37 | 39 | public function progress() { |
| 38 | 40 | $teams = $this->from->sortTeams($this->filters); |
| 39 | - if (count($this->filters) === 0 || $this->len !== null || $this->start !== 0) $next = array_splice($teams, $this->start, ($this->len == null ? count($teams) : $this->len)); |
|
| 40 | - else $next = $teams; |
|
| 41 | + if (count($this->filters) === 0 || $this->len !== null || $this->start !== 0) { |
|
| 42 | + $next = array_splice($teams, $this->start, ($this->len == null ? count($teams) : $this->len)); |
|
| 43 | + } else { |
|
| 44 | + $next = $teams; |
|
| 45 | + } |
|
| 41 | 46 | $this->from->addProgressed($next); |
| 42 | 47 | $this->to->addTeam($next); |
| 43 | 48 | return $this; |
@@ -45,8 +50,11 @@ discard block |
||
| 45 | 50 | |
| 46 | 51 | public function progressBlank(){ |
| 47 | 52 | $teams = $this->from->isPlayed() ? $this->from->sortTeams($this->filters) : $this->from->simulate($this->filters); |
| 48 | - if (count($this->filters) === 0 || $this->len !== null || $this->start !== 0) $next = array_splice($teams, $this->start, ($this->len == null ? count($teams) : $this->len)); |
|
| 49 | - else $next = $teams; |
|
| 53 | + if (count($this->filters) === 0 || $this->len !== null || $this->start !== 0) { |
|
| 54 | + $next = array_splice($teams, $this->start, ($this->len == null ? count($teams) : $this->len)); |
|
| 55 | + } else { |
|
| 56 | + $next = $teams; |
|
| 57 | + } |
|
| 50 | 58 | $this->from->addProgressed($next); |
| 51 | 59 | $i = 1; |
| 52 | 60 | foreach ($next as $team) { |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | return $this->name; |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | - public function addGroup(Group ...$groups){ |
|
| 26 | + public function addGroup(Group ...$groups) { |
|
| 27 | 27 | foreach ($groups as $group) { |
| 28 | 28 | if ($group instanceof Group) $this->groups[] = $group; |
| 29 | 29 | else throw new Exception('Trying to add group which is not an instance of Group class.'); |
@@ -35,21 +35,21 @@ discard block |
||
| 35 | 35 | $this->groups[] = $g->setSkip($this->allowSkip); |
| 36 | 36 | return $g; |
| 37 | 37 | } |
| 38 | - public function getGroups(){ |
|
| 38 | + public function getGroups() { |
|
| 39 | 39 | $this->orderGroups(); |
| 40 | 40 | return $this->groups; |
| 41 | 41 | } |
| 42 | 42 | public function orderGroups() { |
| 43 | - usort($this->groups, function($a, $b){ |
|
| 44 | - return $a->order - $b->order; |
|
| 43 | + usort($this->groups, function($a, $b) { |
|
| 44 | + return $a->order-$b->order; |
|
| 45 | 45 | }); |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - public function allowSkip(){ |
|
| 48 | + public function allowSkip() { |
|
| 49 | 49 | $this->allowSkip = true; |
| 50 | 50 | return $this; |
| 51 | 51 | } |
| 52 | - public function disallowSkip(){ |
|
| 52 | + public function disallowSkip() { |
|
| 53 | 53 | $this->allowSkip = false; |
| 54 | 54 | return $this; |
| 55 | 55 | } |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | return $this->allowSkip; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - public function genGames(){ |
|
| 64 | + public function genGames() { |
|
| 65 | 65 | $games = []; |
| 66 | 66 | $ex = []; |
| 67 | 67 | $g = 0; |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | public function getGames() { |
| 87 | 87 | return $this->games; |
| 88 | 88 | } |
| 89 | - public function isPlayed(){ |
|
| 89 | + public function isPlayed() { |
|
| 90 | 90 | foreach ($this->groups as $group) { |
| 91 | 91 | if (!$group->isPlayed()) return false; |
| 92 | 92 | } |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | |
| 96 | 96 | public function addTeam(...$teams) { |
| 97 | 97 | foreach ($teams as $team) { |
| 98 | - if ($team instanceof Team) { |
|
| 98 | + if ($team instanceof Team) { |
|
| 99 | 99 | $this->teams[] = $team; |
| 100 | 100 | } |
| 101 | 101 | elseif (gettype($team) === 'array') { |
@@ -156,14 +156,14 @@ discard block |
||
| 156 | 156 | return $this; |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - public function progress(){ |
|
| 159 | + public function progress() { |
|
| 160 | 160 | foreach ($this->groups as $group) { |
| 161 | 161 | $group->progress(); |
| 162 | 162 | } |
| 163 | 163 | return $this; |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - public function progressBlank(){ |
|
| 166 | + public function progressBlank() { |
|
| 167 | 167 | if (!$this->isPlayed()) $this->simulate(); |
| 168 | 168 | foreach ($this->groups as $group) { |
| 169 | 169 | $group->progressBlank(); |
@@ -25,8 +25,11 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | public function addGroup(Group ...$groups){ |
| 27 | 27 | foreach ($groups as $group) { |
| 28 | - if ($group instanceof Group) $this->groups[] = $group; |
|
| 29 | - else throw new Exception('Trying to add group which is not an instance of Group class.'); |
|
| 28 | + if ($group instanceof Group) { |
|
| 29 | + $this->groups[] = $group; |
|
| 30 | + } else { |
|
| 31 | + throw new Exception('Trying to add group which is not an instance of Group class.'); |
|
| 32 | + } |
|
| 30 | 33 | } |
| 31 | 34 | return $this; |
| 32 | 35 | } |
@@ -77,7 +80,9 @@ discard block |
||
| 77 | 80 | while ($g > 0) { |
| 78 | 81 | foreach ($games as $key => $group) { |
| 79 | 82 | $this->games[] = array_shift($games[$key]); |
| 80 | - if (count($games[$key]) === 0) unset($games[$key]); |
|
| 83 | + if (count($games[$key]) === 0) { |
|
| 84 | + unset($games[$key]); |
|
| 85 | + } |
|
| 81 | 86 | $g--; |
| 82 | 87 | } |
| 83 | 88 | } |
@@ -88,7 +93,9 @@ discard block |
||
| 88 | 93 | } |
| 89 | 94 | public function isPlayed(){ |
| 90 | 95 | foreach ($this->groups as $group) { |
| 91 | - if (!$group->isPlayed()) return false; |
|
| 96 | + if (!$group->isPlayed()) { |
|
| 97 | + return false; |
|
| 98 | + } |
|
| 92 | 99 | } |
| 93 | 100 | return true; |
| 94 | 101 | } |
@@ -97,10 +104,11 @@ discard block |
||
| 97 | 104 | foreach ($teams as $team) { |
| 98 | 105 | if ($team instanceof Team) { |
| 99 | 106 | $this->teams[] = $team; |
| 100 | - } |
|
| 101 | - elseif (gettype($team) === 'array') { |
|
| 107 | + } elseif (gettype($team) === 'array') { |
|
| 102 | 108 | foreach ($team as $team2) { |
| 103 | - if ($team2 instanceof Team) $this->teams[] = $team2; |
|
| 109 | + if ($team2 instanceof Team) { |
|
| 110 | + $this->teams[] = $team2; |
|
| 111 | + } |
|
| 104 | 112 | $team2->groupResults[$this->id] = [ |
| 105 | 113 | 'group' => $this, |
| 106 | 114 | 'points' => 0, |
@@ -112,8 +120,9 @@ discard block |
||
| 112 | 120 | 'third' => 0 |
| 113 | 121 | ]; |
| 114 | 122 | } |
| 123 | + } else { |
|
| 124 | + throw new Exception('Trying to add team which is not an instance of Team class'); |
|
| 115 | 125 | } |
| 116 | - else throw new Exception('Trying to add team which is not an instance of Team class'); |
|
| 117 | 126 | } |
| 118 | 127 | return $this; |
| 119 | 128 | } |
@@ -123,7 +132,9 @@ discard block |
||
| 123 | 132 | return $t; |
| 124 | 133 | } |
| 125 | 134 | public function getTeams() { |
| 126 | - if (count($this->teams) > 0) return $this->teams; |
|
| 135 | + if (count($this->teams) > 0) { |
|
| 136 | + return $this->teams; |
|
| 137 | + } |
|
| 127 | 138 | $teams = []; |
| 128 | 139 | foreach ($this->groups as $group) { |
| 129 | 140 | $teams = array_merge($teams, $group->getTeams()); |
@@ -134,7 +145,9 @@ discard block |
||
| 134 | 145 | |
| 135 | 146 | public function splitTeams(...$groups) { |
| 136 | 147 | |
| 137 | - if (count($groups) === 0) $groups = $this->getGroups(); |
|
| 148 | + if (count($groups) === 0) { |
|
| 149 | + $groups = $this->getGroups(); |
|
| 150 | + } |
|
| 138 | 151 | |
| 139 | 152 | foreach ($groups as $key => $value) { |
| 140 | 153 | if (gettype($value) === 'array') { |
@@ -149,7 +162,9 @@ discard block |
||
| 149 | 162 | while (count($teams) > 0) { |
| 150 | 163 | foreach ($groups as $group) { |
| 151 | 164 | if ($group instanceof Group) { |
| 152 | - if (count($teams) > 0) $group->addTeam(array_shift($teams)); |
|
| 165 | + if (count($teams) > 0) { |
|
| 166 | + $group->addTeam(array_shift($teams)); |
|
| 167 | + } |
|
| 153 | 168 | } |
| 154 | 169 | } |
| 155 | 170 | } |
@@ -164,7 +179,9 @@ discard block |
||
| 164 | 179 | } |
| 165 | 180 | |
| 166 | 181 | public function progressBlank(){ |
| 167 | - if (!$this->isPlayed()) $this->simulate(); |
|
| 182 | + if (!$this->isPlayed()) { |
|
| 183 | + $this->simulate(); |
|
| 184 | + } |
|
| 168 | 185 | foreach ($this->groups as $group) { |
| 169 | 186 | $group->progressBlank(); |
| 170 | 187 | } |
@@ -173,7 +190,9 @@ discard block |
||
| 173 | 190 | |
| 174 | 191 | public function simulate() { |
| 175 | 192 | foreach ($this->groups as $group) { |
| 176 | - if ($group->isPlayed()) continue; |
|
| 193 | + if ($group->isPlayed()) { |
|
| 194 | + continue; |
|
| 195 | + } |
|
| 177 | 196 | $group->simulate([], false); |
| 178 | 197 | } |
| 179 | 198 | return $this; |