@@ -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); |
@@ -66,11 +66,11 @@ |
||
66 | 66 | 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)); |
67 | 67 | return $this; |
68 | 68 | } |
69 | - public function getTeams(){ |
|
69 | + public function getTeams() { |
|
70 | 70 | return $this->teams; |
71 | 71 | } |
72 | - public function getTeamsIds(){ |
|
73 | - return array_map(function($a){ return $a->id; }, $this->teams); |
|
72 | + public function getTeamsIds() { |
|
73 | + return array_map(function($a) { return $a->id; }, $this->teams); |
|
74 | 74 | } |
75 | 75 | public function getTeam(string $id) { |
76 | 76 | foreach ($this->teams as $team) { |
@@ -33,11 +33,15 @@ discard block |
||
33 | 33 | $this->teams = $teams; |
34 | 34 | foreach ($this->teams as $team) { |
35 | 35 | foreach ($this->teams as $team2) { |
36 | - if ($team === $team2) continue; |
|
36 | + if ($team === $team2) { |
|
37 | + continue; |
|
38 | + } |
|
37 | 39 | $team->addGameWith($team2, $group); |
38 | 40 | } |
39 | 41 | } |
40 | - 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)); |
|
42 | + if (count($error) > 0) { |
|
43 | + throw new \Exception('Trying to add teams ('.count($error).') that are not instance of Team class'.PHP_EOL.print_r($error, true)); |
|
44 | + } |
|
41 | 45 | } |
42 | 46 | |
43 | 47 | public function getGroup() { |
@@ -56,14 +60,18 @@ discard block |
||
56 | 60 | $team->addGame($this); |
57 | 61 | |
58 | 62 | foreach ($this->teams as $team2) { |
59 | - if ($team === $team2) continue; |
|
63 | + if ($team === $team2) { |
|
64 | + continue; |
|
65 | + } |
|
60 | 66 | if ($team instanceof Team) { |
61 | 67 | $team->addGameWith($team2, $this->group); |
62 | 68 | $team2->addGameWith($team, $this->group); |
63 | 69 | } |
64 | 70 | } |
65 | 71 | } |
66 | - 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)); |
|
72 | + if (count($error) > 0) { |
|
73 | + throw new \Exception('Trying to add teams ('.count($error).') that are not instance of Team class'.PHP_EOL.print_r($error, true)); |
|
74 | + } |
|
67 | 75 | return $this; |
68 | 76 | } |
69 | 77 | public function getTeams(){ |
@@ -74,7 +82,9 @@ discard block |
||
74 | 82 | } |
75 | 83 | public function getTeam(string $id) { |
76 | 84 | foreach ($this->teams as $team) { |
77 | - if ($team->id === $id) return $team; |
|
85 | + if ($team->id === $id) { |
|
86 | + return $team; |
|
87 | + } |
|
78 | 88 | } |
79 | 89 | return false; |
80 | 90 | } |
@@ -85,13 +95,17 @@ discard block |
||
85 | 95 | * ) |
86 | 96 | */ |
87 | 97 | public function setResults(array $results = []) { |
88 | - if (count($this->results) === 0) $this->resetResults(); |
|
98 | + if (count($this->results) === 0) { |
|
99 | + $this->resetResults(); |
|
100 | + } |
|
89 | 101 | arsort($results); |
90 | 102 | $inGame = /** @scrutinizer ignore-call */ $this->group->getInGame(); |
91 | 103 | $i = 1; |
92 | 104 | foreach ($results as $id => $score) { |
93 | 105 | $team = $this->getTeam($id); |
94 | - if ($team === false) throw new \Exception('Couldn\'t find team with id of "'.$id.'"'); |
|
106 | + if ($team === false) { |
|
107 | + throw new \Exception('Couldn\'t find team with id of "'.$id.'"'); |
|
108 | + } |
|
95 | 109 | $this->results[$team->id] = ['score' => $score]; |
96 | 110 | $team->sumScore += $score; |
97 | 111 | $prev = prev($results); |
@@ -118,13 +132,11 @@ discard block |
||
118 | 132 | $this->drawIds[] = $team->id; |
119 | 133 | $team->addDraw($this->group->id); |
120 | 134 | $this->results[$team->id] += ['points' => $this->group->drawPoints, 'type' => 'draw']; |
121 | - } |
|
122 | - elseif ($i === 1) { |
|
135 | + } elseif ($i === 1) { |
|
123 | 136 | $this->winId = $team->id; |
124 | 137 | $team->addWin($this->group->id); |
125 | 138 | $this->results[$team->id] += ['points' => $this->group->winPoints, 'type' => 'win']; |
126 | - } |
|
127 | - else { |
|
139 | + } else { |
|
128 | 140 | $this->lossId = $team->id; |
129 | 141 | $team->addLoss($this->group->id); |
130 | 142 | $this->results[$team->id] += ['points' => $this->group->lostPoints, 'type' => 'loss']; |
@@ -220,7 +232,9 @@ discard block |
||
220 | 232 | } |
221 | 233 | |
222 | 234 | public function isPlayed() { |
223 | - if (count($this->results) > 0) return true; |
|
235 | + if (count($this->results) > 0) { |
|
236 | + return true; |
|
237 | + } |
|
224 | 238 | return false; |
225 | 239 | } |
226 | 240 | } |
@@ -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 |
@@ -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() { |
@@ -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 | public function __toString() { |
@@ -56,37 +64,54 @@ 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') { |
|
72 | - if ($from === null) throw new \Exception('Group $from was not defined.'); |
|
84 | + } elseif ($this->what == 'notprogressed') { |
|
85 | + if ($from === null) { |
|
86 | + throw new \Exception('Group $from was not defined.'); |
|
87 | + } |
|
73 | 88 | return !$from->isProgressed($team); |
74 | - } |
|
75 | - elseif ($this->what == 'progressed') { |
|
76 | - if ($from === null) throw new \Exception('Group $from was not defined.'); |
|
89 | + } elseif ($this->what == 'progressed') { |
|
90 | + if ($from === null) { |
|
91 | + throw new \Exception('Group $from was not defined.'); |
|
92 | + } |
|
77 | 93 | return $from->isProgressed($team); |
78 | 94 | } |
79 | - 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.'); |
|
95 | + if (gettype($groupsId) === 'array' && !in_array(strtolower($operation), ['sum', 'avg', 'max', 'min'])) { |
|
96 | + throw new \Exception('Unknown operation of '.$operation.'. Only "sum", "avg", "min", "max" possible.'); |
|
97 | + } |
|
80 | 98 | $comp = 0; |
81 | 99 | if (gettype($groupsId) === 'array' && count($groupsId) > 0) { |
82 | 100 | $sum = 0; |
83 | 101 | $max = null; |
84 | 102 | $min = null; |
85 | 103 | foreach ($groupsId as $id) { |
86 | - if (!isset($team->groupResults[$id])) continue; // IF TEAM DIDN'T PLAY IN THAT GROUP -> SKIP |
|
104 | + if (!isset($team->groupResults[$id])) { |
|
105 | + continue; |
|
106 | + } |
|
107 | + // IF TEAM DIDN'T PLAY IN THAT GROUP -> SKIP |
|
87 | 108 | $sum += $team->groupResults[$id][$this->what]; |
88 | - if ($team->groupResults[$id][$this->what] > $max || $max === null) $max = $team->groupResults[$id][$this->what]; |
|
89 | - if ($team->groupResults[$id][$this->what] < $min || $min === null) $min = $team->groupResults[$id][$this->what]; |
|
109 | + if ($team->groupResults[$id][$this->what] > $max || $max === null) { |
|
110 | + $max = $team->groupResults[$id][$this->what]; |
|
111 | + } |
|
112 | + if ($team->groupResults[$id][$this->what] < $min || $min === null) { |
|
113 | + $min = $team->groupResults[$id][$this->what]; |
|
114 | + } |
|
90 | 115 | } |
91 | 116 | switch (strtolower($operation)) { |
92 | 117 | case 'sum': |
@@ -102,11 +127,9 @@ discard block |
||
102 | 127 | $comp = $min; |
103 | 128 | break; |
104 | 129 | } |
105 | - } |
|
106 | - elseif (gettype($groupsId) === 'string' && isset($team->groupResults[$groupsId])) { |
|
130 | + } elseif (gettype($groupsId) === 'string' && isset($team->groupResults[$groupsId])) { |
|
107 | 131 | $comp = $team->groupResults[$groupsId][$this->what]; |
108 | - } |
|
109 | - else { |
|
132 | + } else { |
|
110 | 133 | throw new \Exception("Couldn't find group of id ".print_r($groupsId, true)); |
111 | 134 | } |
112 | 135 |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | |
23 | 23 | private $allowSkip = false; |
24 | 24 | |
25 | - function __construct(string $name = ''){ |
|
25 | + function __construct(string $name = '') { |
|
26 | 26 | $this->name = $name; |
27 | 27 | } |
28 | 28 | public function __toString() { |
@@ -57,16 +57,16 @@ discard block |
||
57 | 57 | public function getCategoryWait() { |
58 | 58 | return $this->expectedCategoryWait; |
59 | 59 | } |
60 | - public function getTournamentTime(){ |
|
60 | + public function getTournamentTime() { |
|
61 | 61 | $games = count($this->getGames()); |
62 | 62 | return $games*$this->expectedPlay+$games*$this->expectedGameWait+count($this->getRounds())*$this->expectedRoundWait+count($this->getCategories())*$this->expectedCategoryWait; |
63 | 63 | } |
64 | 64 | |
65 | - public function allowSkip(){ |
|
65 | + public function allowSkip() { |
|
66 | 66 | $this->allowSkip = true; |
67 | 67 | return $this; |
68 | 68 | } |
69 | - public function disallowSkip(){ |
|
69 | + public function disallowSkip() { |
|
70 | 70 | $this->allowSkip = false; |
71 | 71 | return $this; |
72 | 72 | } |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | return $this->allowSkip; |
79 | 79 | } |
80 | 80 | |
81 | - public function addCategory(Category ...$categories){ |
|
81 | + public function addCategory(Category ...$categories) { |
|
82 | 82 | foreach ($categories as $category) { |
83 | 83 | if ($category instanceof Category) $this->categories[] = $category; |
84 | 84 | else throw new \Exception('Trying to add category which is not an instance of the Category class.'); |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | |
120 | 120 | public function addTeam(...$teams) { |
121 | 121 | foreach ($teams as $team) { |
122 | - if ($team instanceof Team) { |
|
122 | + if ($team instanceof Team) { |
|
123 | 123 | $this->teams[] = $team; |
124 | 124 | } |
125 | 125 | elseif (gettype($team) === 'array') { |
@@ -78,8 +78,11 @@ discard block |
||
78 | 78 | |
79 | 79 | public function addCategory(Category ...$categories){ |
80 | 80 | foreach ($categories as $category) { |
81 | - if ($category instanceof Category) $this->categories[] = $category; |
|
82 | - else throw new \Exception('Trying to add category which is not an instance of the Category class.'); |
|
81 | + if ($category instanceof Category) { |
|
82 | + $this->categories[] = $category; |
|
83 | + } else { |
|
84 | + throw new \Exception('Trying to add category which is not an instance of the Category class.'); |
|
85 | + } |
|
83 | 86 | } |
84 | 87 | return $this; |
85 | 88 | } |
@@ -94,8 +97,11 @@ discard block |
||
94 | 97 | |
95 | 98 | public function addRound(Round ...$rounds) { |
96 | 99 | foreach ($rounds as $round) { |
97 | - if ($round instanceof Round) $this->rounds[] = $round; |
|
98 | - else throw new \Exception('Trying to add round which is not an instance of the Round class.'); |
|
100 | + if ($round instanceof Round) { |
|
101 | + $this->rounds[] = $round; |
|
102 | + } else { |
|
103 | + throw new \Exception('Trying to add round which is not an instance of the Round class.'); |
|
104 | + } |
|
99 | 105 | } |
100 | 106 | return $this; |
101 | 107 | } |
@@ -119,13 +125,15 @@ discard block |
||
119 | 125 | foreach ($teams as $team) { |
120 | 126 | if ($team instanceof Team) { |
121 | 127 | $this->teams[] = $team; |
122 | - } |
|
123 | - elseif (gettype($team) === 'array') { |
|
128 | + } elseif (gettype($team) === 'array') { |
|
124 | 129 | foreach ($team as $team2) { |
125 | - if ($team2 instanceof Team) $this->teams[] = $team2; |
|
130 | + if ($team2 instanceof Team) { |
|
131 | + $this->teams[] = $team2; |
|
132 | + } |
|
126 | 133 | } |
134 | + } else { |
|
135 | + throw new \Exception('Trying to add team which is not an instance of Team class'); |
|
127 | 136 | } |
128 | - else throw new \Exception('Trying to add team which is not an instance of Team class'); |
|
129 | 137 | } |
130 | 138 | return $this; |
131 | 139 | } |
@@ -170,18 +178,24 @@ discard block |
||
170 | 178 | |
171 | 179 | public function splitTeams(...$wheres) { |
172 | 180 | |
173 | - if (count($wheres) === 0) $wheres = array_merge($this->getRounds(), $this->getCategories()); |
|
181 | + if (count($wheres) === 0) { |
|
182 | + $wheres = array_merge($this->getRounds(), $this->getCategories()); |
|
183 | + } |
|
174 | 184 | |
175 | 185 | foreach ($wheres as $key => $value) { |
176 | 186 | if (gettype($value) === 'array') { |
177 | 187 | unset($wheres[$key]); |
178 | 188 | foreach ($value as $key2 => $value2) { |
179 | - if (!$value2 instanceof Round && !$value2 instanceof Category) throw new \Exception('Trying to split teams to another object, that is not instance of Category or Round.'); |
|
189 | + if (!$value2 instanceof Round && !$value2 instanceof Category) { |
|
190 | + throw new \Exception('Trying to split teams to another object, that is not instance of Category or Round.'); |
|
191 | + } |
|
180 | 192 | } |
181 | 193 | $wheres = array_merge($wheres, $value); |
182 | 194 | continue; |
183 | 195 | } |
184 | - if (!$value instanceof Round && !$value instanceof Category) throw new \Exception('Trying to split teams to another object, that is not instance of Category or Round.'); |
|
196 | + if (!$value instanceof Round && !$value instanceof Category) { |
|
197 | + throw new \Exception('Trying to split teams to another object, that is not instance of Category or Round.'); |
|
198 | + } |
|
185 | 199 | } |
186 | 200 | |
187 | 201 | $teams = $this->getTeams(); |
@@ -189,7 +203,9 @@ discard block |
||
189 | 203 | |
190 | 204 | while (count($teams) > 0) { |
191 | 205 | foreach ($wheres as $where) { |
192 | - if (count($teams) > 0) $where->addTeam(array_shift($teams)); |
|
206 | + if (count($teams) > 0) { |
|
207 | + $where->addTeam(array_shift($teams)); |
|
208 | + } |
|
193 | 209 | } |
194 | 210 | } |
195 | 211 | foreach ($wheres as $where) { |
@@ -204,8 +220,7 @@ discard block |
||
204 | 220 | foreach ($this->categories as $category) { |
205 | 221 | $games = array_merge($games, $category->genGamesSimulate()); |
206 | 222 | } |
207 | - } |
|
208 | - elseif (count($this->rounds) > 0) { |
|
223 | + } elseif (count($this->rounds) > 0) { |
|
209 | 224 | foreach ($this->rounds as $round) { |
210 | 225 | $games = array_merge($games, $round->genGames()); |
211 | 226 | $round->simulate()->progress(true); |
@@ -213,9 +228,12 @@ discard block |
||
213 | 228 | foreach ($this->rounds as $round) { |
214 | 229 | $round->resetGames(); |
215 | 230 | } |
231 | + } else { |
|
232 | + throw new \Exception('There are no rounds or categories to simulate games from.'); |
|
233 | + } |
|
234 | + if ($returnTime) { |
|
235 | + return $this->getTournamentTime(); |
|
216 | 236 | } |
217 | - else throw new \Exception('There are no rounds or categories to simulate games from.'); |
|
218 | - if ($returnTime) return $this->getTournamentTime(); |
|
219 | 237 | return $games; |
220 | 238 | } |
221 | 239 | public function genGamesSimulateReal(bool $returnTime = false) { |
@@ -224,16 +242,18 @@ discard block |
||
224 | 242 | foreach ($this->categories as $category) { |
225 | 243 | $games = array_merge($games, $category->genGamesSimulate()); |
226 | 244 | } |
227 | - } |
|
228 | - elseif (count($this->rounds) > 0) { |
|
245 | + } elseif (count($this->rounds) > 0) { |
|
229 | 246 | foreach ($this->rounds as $round) { |
230 | 247 | $games = array_merge($games, $round->genGames()); |
231 | 248 | $round->simulate(); |
232 | 249 | $round->progress(); |
233 | 250 | } |
251 | + } else { |
|
252 | + throw new \Exception('There are no rounds or categories to simulate games from.'); |
|
253 | + } |
|
254 | + if ($returnTime) { |
|
255 | + return $this->getTournamentTime(); |
|
234 | 256 | } |
235 | - else throw new \Exception('There are no rounds or categories to simulate games from.'); |
|
236 | - if ($returnTime) return $this->getTournamentTime(); |
|
237 | 257 | return $games; |
238 | 258 | } |
239 | 259 |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | $this->name = $name; |
22 | 22 | } |
23 | 23 | |
24 | - public function addRound(Round ...$rounds){ |
|
24 | + public function addRound(Round ...$rounds) { |
|
25 | 25 | foreach ($rounds as $round) { |
26 | 26 | if ($round instanceof Round) $this->rounds[] = $round; |
27 | 27 | else throw new \Exception('Trying to add round which is not an instance of Round class.'); |
@@ -33,15 +33,15 @@ discard block |
||
33 | 33 | $this->rounds[] = $r->setSkip($this->allowSkip); |
34 | 34 | return $r; |
35 | 35 | } |
36 | - public function getRounds(){ |
|
36 | + public function getRounds() { |
|
37 | 37 | return $this->rounds; |
38 | 38 | } |
39 | 39 | |
40 | - public function allowSkip(){ |
|
40 | + public function allowSkip() { |
|
41 | 41 | $this->allowSkip = true; |
42 | 42 | return $this; |
43 | 43 | } |
44 | - public function disallowSkip(){ |
|
44 | + public function disallowSkip() { |
|
45 | 45 | $this->allowSkip = false; |
46 | 46 | return $this; |
47 | 47 | } |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | |
56 | 56 | public function addTeam(...$teams) { |
57 | 57 | foreach ($teams as $team) { |
58 | - if ($team instanceof Team) { |
|
58 | + if ($team instanceof Team) { |
|
59 | 59 | $this->teams[] = $team; |
60 | 60 | } |
61 | 61 | 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->rounds as $round) { |
77 | 84 | $teams = array_merge($teams, $round->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()->progress(true)->resetGames(); |
@@ -16,20 +16,20 @@ |
||
16 | 16 | public $sumScore = 0; |
17 | 17 | |
18 | 18 | /** |
19 | - * ARRAY WITH GROUPS AND IT'S RESULTS |
|
20 | - * array ( |
|
21 | - * * groupId => array ( |
|
22 | - * * * "group" => Group, # GROUP OBJECT |
|
23 | - * * * "points" => int 0, # NUMBER OF POINTS AQUIRED |
|
24 | - * * * "score" => int 0, # SUM OF SCORE AQUIRED |
|
25 | - * * * "wins" => int 0, # NUMBER OF WINS |
|
26 | - * * * "draws" => int 0, # NUMBER OF DRAWS |
|
27 | - * * * "losses" => int 0, # NUMBER OF LOSSES |
|
28 | - * * * "second" => int 0, # NUMBER OF TIMES BEING SECOND (ONLY FOR INGAME OPTION OF 3 OR 4) |
|
29 | - * * * "third" => int 0 # NUMBER OF TIMES BEING THIRD (ONLY FOR INGAME OPTION OF 4) |
|
30 | - * * ) |
|
31 | - *) |
|
32 | - */ |
|
19 | + * ARRAY WITH GROUPS AND IT'S RESULTS |
|
20 | + * array ( |
|
21 | + * * groupId => array ( |
|
22 | + * * * "group" => Group, # GROUP OBJECT |
|
23 | + * * * "points" => int 0, # NUMBER OF POINTS AQUIRED |
|
24 | + * * * "score" => int 0, # SUM OF SCORE AQUIRED |
|
25 | + * * * "wins" => int 0, # NUMBER OF WINS |
|
26 | + * * * "draws" => int 0, # NUMBER OF DRAWS |
|
27 | + * * * "losses" => int 0, # NUMBER OF LOSSES |
|
28 | + * * * "second" => int 0, # NUMBER OF TIMES BEING SECOND (ONLY FOR INGAME OPTION OF 3 OR 4) |
|
29 | + * * * "third" => int 0 # NUMBER OF TIMES BEING THIRD (ONLY FOR INGAME OPTION OF 4) |
|
30 | + * * ) |
|
31 | + *) |
|
32 | + */ |
|
33 | 33 | public $groupResults = []; |
34 | 34 | |
35 | 35 | function __construct(string $name = 'team', $id = null) { |
@@ -59,70 +59,70 @@ |
||
59 | 59 | return $this; |
60 | 60 | } |
61 | 61 | |
62 | - public function addWin(string $groupId = ''){ |
|
62 | + public function addWin(string $groupId = '') { |
|
63 | 63 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
64 | 64 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->winPoints; |
65 | 65 | $this->sumPoints += $this->groupResults[$groupId]['group']->winPoints; |
66 | 66 | $this->groupResults[$groupId]['wins']++; |
67 | 67 | return $this; |
68 | 68 | } |
69 | - public function removeWin(string $groupId = ''){ |
|
69 | + public function removeWin(string $groupId = '') { |
|
70 | 70 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
71 | 71 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->winPoints; |
72 | 72 | $this->sumPoints -= $this->groupResults[$groupId]['group']->winPoints; |
73 | 73 | $this->groupResults[$groupId]['wins']--; |
74 | 74 | return $this; |
75 | 75 | } |
76 | - public function addDraw(string $groupId = ''){ |
|
76 | + public function addDraw(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']->drawPoints; |
79 | 79 | $this->sumPoints += $this->groupResults[$groupId]['group']->drawPoints; |
80 | 80 | $this->groupResults[$groupId]['draws']++; |
81 | 81 | return $this; |
82 | 82 | } |
83 | - public function removeDraw(string $groupId = ''){ |
|
83 | + public function removeDraw(string $groupId = '') { |
|
84 | 84 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
85 | 85 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->drawPointsPoints; |
86 | 86 | $this->sumPoints -= $this->groupResults[$groupId]['group']->drawPoints; |
87 | 87 | $this->groupResults[$groupId]['draws']--; |
88 | 88 | return $this; |
89 | 89 | } |
90 | - public function addLoss(string $groupId = ''){ |
|
90 | + public function addLoss(string $groupId = '') { |
|
91 | 91 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
92 | 92 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->lostPoints; |
93 | 93 | $this->sumPoints += $this->groupResults[$groupId]['group']->lostPoints; |
94 | 94 | $this->groupResults[$groupId]['losses']++; |
95 | 95 | return $this; |
96 | 96 | } |
97 | - public function removeLoss(string $groupId = ''){ |
|
97 | + public function removeLoss(string $groupId = '') { |
|
98 | 98 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
99 | 99 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->lostPoints; |
100 | 100 | $this->sumPoints -= $this->groupResults[$groupId]['group']->lostPoints; |
101 | 101 | $this->groupResults[$groupId]['losses']--; |
102 | 102 | return $this; |
103 | 103 | } |
104 | - public function addSecond(string $groupId = ''){ |
|
104 | + public function addSecond(string $groupId = '') { |
|
105 | 105 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
106 | 106 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->secondPoints; |
107 | 107 | $this->sumPoints += $this->groupResults[$groupId]['group']->secondPoints; |
108 | 108 | $this->groupResults[$groupId]['second']++; |
109 | 109 | return $this; |
110 | 110 | } |
111 | - public function removeSecond(string $groupId = ''){ |
|
111 | + public function removeSecond(string $groupId = '') { |
|
112 | 112 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
113 | 113 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->secondPoints; |
114 | 114 | $this->sumPoints -= $this->groupResults[$groupId]['group']->secondPoints; |
115 | 115 | $this->groupResults[$groupId]['second']--; |
116 | 116 | return $this; |
117 | 117 | } |
118 | - public function addThird(string $groupId = ''){ |
|
118 | + public function addThird(string $groupId = '') { |
|
119 | 119 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
120 | 120 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->thirdPoints; |
121 | 121 | $this->sumPoints += $this->groupResults[$groupId]['group']->thirdPoints; |
122 | 122 | $this->groupResults[$groupId]['third']++; |
123 | 123 | return $this; |
124 | 124 | } |
125 | - public function removeThird(string $groupId = ''){ |
|
125 | + public function removeThird(string $groupId = '') { |
|
126 | 126 | if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
127 | 127 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->thirdPoints; |
128 | 128 | $this->sumPoints -= $this->groupResults[$groupId]['group']->thirdPoints; |
@@ -44,104 +44,138 @@ |
||
44 | 44 | } |
45 | 45 | |
46 | 46 | public function addGameWith(Team $team, Group $group) { |
47 | - if (!isset($this->gamesWith[$group->id][$team->id])) $this->gamesWith[$group->id][$team->id] = 0; |
|
47 | + if (!isset($this->gamesWith[$group->id][$team->id])) { |
|
48 | + $this->gamesWith[$group->id][$team->id] = 0; |
|
49 | + } |
|
48 | 50 | $this->gamesWith[$group->id][$team->id]++; |
49 | 51 | return $this; |
50 | 52 | } |
51 | 53 | public function addGroup(Group $group) { |
52 | - if (!isset($this->games[$group->id])) $this->games[$group->id] = []; |
|
54 | + if (!isset($this->games[$group->id])) { |
|
55 | + $this->games[$group->id] = []; |
|
56 | + } |
|
53 | 57 | return $this; |
54 | 58 | } |
55 | 59 | public function addGame(Game $game) { |
56 | 60 | $group = $game->getGroup(); |
57 | - if (!isset($this->games[$group->id])) $this->games[$group->id] = []; |
|
61 | + if (!isset($this->games[$group->id])) { |
|
62 | + $this->games[$group->id] = []; |
|
63 | + } |
|
58 | 64 | $this->games[$group->id][] = $game; |
59 | 65 | return $this; |
60 | 66 | } |
61 | 67 | |
62 | 68 | public function addWin(string $groupId = ''){ |
63 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
69 | + if (!isset($this->groupResults[$groupId])) { |
|
70 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
71 | + } |
|
64 | 72 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->winPoints; |
65 | 73 | $this->sumPoints += $this->groupResults[$groupId]['group']->winPoints; |
66 | 74 | $this->groupResults[$groupId]['wins']++; |
67 | 75 | return $this; |
68 | 76 | } |
69 | 77 | public function removeWin(string $groupId = ''){ |
70 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
78 | + if (!isset($this->groupResults[$groupId])) { |
|
79 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
80 | + } |
|
71 | 81 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->winPoints; |
72 | 82 | $this->sumPoints -= $this->groupResults[$groupId]['group']->winPoints; |
73 | 83 | $this->groupResults[$groupId]['wins']--; |
74 | 84 | return $this; |
75 | 85 | } |
76 | 86 | public function addDraw(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']->drawPoints; |
79 | 91 | $this->sumPoints += $this->groupResults[$groupId]['group']->drawPoints; |
80 | 92 | $this->groupResults[$groupId]['draws']++; |
81 | 93 | return $this; |
82 | 94 | } |
83 | 95 | public function removeDraw(string $groupId = ''){ |
84 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
96 | + if (!isset($this->groupResults[$groupId])) { |
|
97 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
98 | + } |
|
85 | 99 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->drawPointsPoints; |
86 | 100 | $this->sumPoints -= $this->groupResults[$groupId]['group']->drawPoints; |
87 | 101 | $this->groupResults[$groupId]['draws']--; |
88 | 102 | return $this; |
89 | 103 | } |
90 | 104 | public function addLoss(string $groupId = ''){ |
91 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
105 | + if (!isset($this->groupResults[$groupId])) { |
|
106 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
107 | + } |
|
92 | 108 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->lostPoints; |
93 | 109 | $this->sumPoints += $this->groupResults[$groupId]['group']->lostPoints; |
94 | 110 | $this->groupResults[$groupId]['losses']++; |
95 | 111 | return $this; |
96 | 112 | } |
97 | 113 | public function removeLoss(string $groupId = ''){ |
98 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
114 | + if (!isset($this->groupResults[$groupId])) { |
|
115 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
116 | + } |
|
99 | 117 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->lostPoints; |
100 | 118 | $this->sumPoints -= $this->groupResults[$groupId]['group']->lostPoints; |
101 | 119 | $this->groupResults[$groupId]['losses']--; |
102 | 120 | return $this; |
103 | 121 | } |
104 | 122 | public function addSecond(string $groupId = ''){ |
105 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
123 | + if (!isset($this->groupResults[$groupId])) { |
|
124 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
125 | + } |
|
106 | 126 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->secondPoints; |
107 | 127 | $this->sumPoints += $this->groupResults[$groupId]['group']->secondPoints; |
108 | 128 | $this->groupResults[$groupId]['second']++; |
109 | 129 | return $this; |
110 | 130 | } |
111 | 131 | public function removeSecond(string $groupId = ''){ |
112 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
132 | + if (!isset($this->groupResults[$groupId])) { |
|
133 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
134 | + } |
|
113 | 135 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->secondPoints; |
114 | 136 | $this->sumPoints -= $this->groupResults[$groupId]['group']->secondPoints; |
115 | 137 | $this->groupResults[$groupId]['second']--; |
116 | 138 | return $this; |
117 | 139 | } |
118 | 140 | public function addThird(string $groupId = ''){ |
119 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
141 | + if (!isset($this->groupResults[$groupId])) { |
|
142 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
143 | + } |
|
120 | 144 | $this->groupResults[$groupId]['points'] += $this->groupResults[$groupId]['group']->thirdPoints; |
121 | 145 | $this->sumPoints += $this->groupResults[$groupId]['group']->thirdPoints; |
122 | 146 | $this->groupResults[$groupId]['third']++; |
123 | 147 | return $this; |
124 | 148 | } |
125 | 149 | public function removeThird(string $groupId = ''){ |
126 | - if (!isset($this->groupResults[$groupId])) throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
150 | + if (!isset($this->groupResults[$groupId])) { |
|
151 | + throw new \Exception('Group '.$groupId.' is not set for this team ('.$this->name.')'); |
|
152 | + } |
|
127 | 153 | $this->groupResults[$groupId]['points'] -= $this->groupResults[$groupId]['group']->thirdPoints; |
128 | 154 | $this->sumPoints -= $this->groupResults[$groupId]['group']->thirdPoints; |
129 | 155 | $this->groupResults[$groupId]['third']--; |
130 | 156 | return $this; |
131 | 157 | } |
132 | 158 | public function sumPoints(array $groupIds = []) { |
133 | - if (count($groupIds) === 0) return $this->sumPoints; |
|
159 | + if (count($groupIds) === 0) { |
|
160 | + return $this->sumPoints; |
|
161 | + } |
|
134 | 162 | $sum = 0; |
135 | 163 | foreach ($groupIds as $gid) { |
136 | - if (isset($this->groupResults[$gid])) $sum += $this->groupResults[$gid]['points']; |
|
164 | + if (isset($this->groupResults[$gid])) { |
|
165 | + $sum += $this->groupResults[$gid]['points']; |
|
166 | + } |
|
137 | 167 | } |
138 | 168 | return $sum; |
139 | 169 | } |
140 | 170 | public function sumScore(array $groupIds = []) { |
141 | - if (count($groupIds) === 0) return $this->sumScore; |
|
171 | + if (count($groupIds) === 0) { |
|
172 | + return $this->sumScore; |
|
173 | + } |
|
142 | 174 | $sum = 0; |
143 | 175 | foreach ($groupIds as $gid) { |
144 | - if (isset($this->groupResults[$gid])) $sum += $this->groupResults[$gid]['score']; |
|
176 | + if (isset($this->groupResults[$gid])) { |
|
177 | + $sum += $this->groupResults[$gid]['score']; |
|
178 | + } |
|
145 | 179 | } |
146 | 180 | return $sum; |
147 | 181 | } |