@@ -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, |
@@ -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 | } |
@@ -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'); |
@@ -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 |
@@ -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,14 +64,14 @@ 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 | return $this->validateTeam($team); |
62 | - } |
|
63 | - elseif ($this->what == 'notprogressed') { |
|
72 | + } elseif ($this->what == 'notprogressed') { |
|
64 | 73 | return !$this->validateProgressed($team, $from); |
65 | - } |
|
66 | - elseif ($this->what == 'progressed') { |
|
74 | + } elseif ($this->what == 'progressed') { |
|
67 | 75 | return $this->validateProgressed($team, $from); |
68 | 76 | } |
69 | 77 | return $this->validateCalc($team, $groupsId, $operation, $from); |
@@ -72,30 +80,45 @@ discard block |
||
72 | 80 | private function validateTeam(Team $team) { |
73 | 81 | switch ($this->how) { |
74 | 82 | case '=': |
75 | - if ($this->val === $team) return true; |
|
83 | + if ($this->val === $team) { |
|
84 | + return true; |
|
85 | + } |
|
76 | 86 | break; |
77 | 87 | case '!=': |
78 | - if ($this->val !== $team) return true; |
|
88 | + if ($this->val !== $team) { |
|
89 | + return true; |
|
90 | + } |
|
79 | 91 | break; |
80 | 92 | } |
81 | 93 | return false; |
82 | 94 | } |
83 | 95 | private function validateProgressed(Team $team, Group $from) { |
84 | - if ($from === null) throw new \Exception('Group $from was not defined.'); |
|
96 | + if ($from === null) { |
|
97 | + throw new \Exception('Group $from was not defined.'); |
|
98 | + } |
|
85 | 99 | return $from->isProgressed($team); |
86 | 100 | } |
87 | 101 | private function validateCalc(Team $team, $groupsId, string $operation = 'sum', Group $from = null) { |
88 | - 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.'); |
|
102 | + if (gettype($groupsId) === 'array' && !in_array(strtolower($operation), ['sum', 'avg', 'max', 'min'])) { |
|
103 | + throw new \Exception('Unknown operation of '.$operation.'. Only "sum", "avg", "min", "max" possible.'); |
|
104 | + } |
|
89 | 105 | $comp = 0; |
90 | 106 | if (gettype($groupsId) === 'array' && count($groupsId) > 0) { |
91 | 107 | $sum = 0; |
92 | 108 | $max = null; |
93 | 109 | $min = null; |
94 | 110 | foreach ($groupsId as $id) { |
95 | - if (!isset($team->groupResults[$id])) continue; // IF TEAM DIDN'T PLAY IN THAT GROUP -> SKIP |
|
111 | + if (!isset($team->groupResults[$id])) { |
|
112 | + continue; |
|
113 | + } |
|
114 | + // IF TEAM DIDN'T PLAY IN THAT GROUP -> SKIP |
|
96 | 115 | $sum += $team->groupResults[$id][$this->what]; |
97 | - if ($team->groupResults[$id][$this->what] > $max || $max === null) $max = $team->groupResults[$id][$this->what]; |
|
98 | - if ($team->groupResults[$id][$this->what] < $min || $min === null) $min = $team->groupResults[$id][$this->what]; |
|
116 | + if ($team->groupResults[$id][$this->what] > $max || $max === null) { |
|
117 | + $max = $team->groupResults[$id][$this->what]; |
|
118 | + } |
|
119 | + if ($team->groupResults[$id][$this->what] < $min || $min === null) { |
|
120 | + $min = $team->groupResults[$id][$this->what]; |
|
121 | + } |
|
99 | 122 | } |
100 | 123 | switch (strtolower($operation)) { |
101 | 124 | case 'sum': |
@@ -111,9 +134,11 @@ discard block |
||
111 | 134 | $comp = $min; |
112 | 135 | break; |
113 | 136 | } |
137 | + } elseif (gettype($groupsId) === 'string' && isset($team->groupResults[$groupsId])) { |
|
138 | + $comp = $team->groupResults[$groupsId][$this->what]; |
|
139 | + } else { |
|
140 | + throw new \Exception("Couldn't find group of id ".print_r($groupsId, true)); |
|
114 | 141 | } |
115 | - elseif (gettype($groupsId) === 'string' && isset($team->groupResults[$groupsId])) $comp = $team->groupResults[$groupsId][$this->what]; |
|
116 | - else throw new \Exception("Couldn't find group of id ".print_r($groupsId, true)); |
|
117 | 142 | |
118 | 143 | switch ($this->how) { |
119 | 144 | case '>': return ($comp > $this->val); |
@@ -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 | } |
@@ -27,18 +27,26 @@ 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 | return $this; |
34 | 36 | } |
35 | 37 | |
36 | 38 | public function progress(bool $blank = false) { |
37 | - if ($blank) $teams = $this->from->isPlayed() ? $this->from->sortTeams($this->filters) : $this->from->simulate($this->filters); |
|
38 | - else $teams = $this->from->sortTeams($this->filters); |
|
39 | + if ($blank) { |
|
40 | + $teams = $this->from->isPlayed() ? $this->from->sortTeams($this->filters) : $this->from->simulate($this->filters); |
|
41 | + } else { |
|
42 | + $teams = $this->from->sortTeams($this->filters); |
|
43 | + } |
|
39 | 44 | |
40 | - if (count($this->filters) === 0 || $this->len !== null || $this->start !== 0) $next = array_splice($teams, $this->start, ($this->len === null ? count($teams) : $this->len)); |
|
41 | - else $next = $teams; |
|
45 | + if (count($this->filters) === 0 || $this->len !== null || $this->start !== 0) { |
|
46 | + $next = array_splice($teams, $this->start, ($this->len === null ? count($teams) : $this->len)); |
|
47 | + } else { |
|
48 | + $next = $teams; |
|
49 | + } |
|
42 | 50 | |
43 | 51 | $i = 1; |
44 | 52 | |
@@ -46,12 +54,15 @@ discard block |
||
46 | 54 | if ($blank) { |
47 | 55 | $this->to->addTeam(new BlankTeam($this.' - '.$i, $team)); |
48 | 56 | $i++; |
57 | + } else { |
|
58 | + $team->sumPoints += $this->from->progressPoints; |
|
49 | 59 | } |
50 | - else $team->sumPoints += $this->from->progressPoints; |
|
51 | 60 | } |
52 | 61 | |
53 | 62 | $this->from->addProgressed($next); |
54 | - if (!$blank) $this->to->addTeam($next); |
|
63 | + if (!$blank) { |
|
64 | + $this->to->addTeam($next); |
|
65 | + } |
|
55 | 66 | return $this; |
56 | 67 | } |
57 | 68 |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | |
70 | 70 | // CYCLE 6 |
71 | 71 | // FIRST AVAILABLE GAME |
72 | - $this->moveCalculatedGames(array_shift($games),$teams); |
|
72 | + $this->moveCalculatedGames(array_shift($games), $teams); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | return $this->games; |
@@ -79,8 +79,8 @@ discard block |
||
79 | 79 | private function cycle1(array &$games, array &$teams) { |
80 | 80 | $found = false; |
81 | 81 | foreach ($games as $key => $game) { |
82 | - if ($this->orderCheckTeamsVal($game, $teams, [4,5,6,7])) { |
|
83 | - $this->moveCalculatedGames($game,$teams); |
|
82 | + if ($this->orderCheckTeamsVal($game, $teams, [4, 5, 6, 7])) { |
|
83 | + $this->moveCalculatedGames($game, $teams); |
|
84 | 84 | unset($games[$key]); |
85 | 85 | $found = true; |
86 | 86 | break; |
@@ -92,8 +92,8 @@ discard block |
||
92 | 92 | private function cycle2(array &$games, array &$teams) { |
93 | 93 | $found = false; |
94 | 94 | foreach ($games as $key => $game) { |
95 | - if ($this->orderCheckTeamsVal($game, $teams, [6,7])) { |
|
96 | - $this->moveCalculatedGames($game,$teams); |
|
95 | + if ($this->orderCheckTeamsVal($game, $teams, [6, 7])) { |
|
96 | + $this->moveCalculatedGames($game, $teams); |
|
97 | 97 | unset($games[$key]); |
98 | 98 | $found = true; |
99 | 99 | break; |
@@ -106,8 +106,8 @@ discard block |
||
106 | 106 | private function cycle3(array &$games, array &$teams) { |
107 | 107 | $found = false; |
108 | 108 | foreach ($games as $key => $game) { |
109 | - if ($this->orderCheckTeamsVal($game, $teams, [7], [1,2,3])) { |
|
110 | - $this->moveCalculatedGames($game,$teams); |
|
109 | + if ($this->orderCheckTeamsVal($game, $teams, [7], [1, 2, 3])) { |
|
110 | + $this->moveCalculatedGames($game, $teams); |
|
111 | 111 | unset($games[$key]); |
112 | 112 | $found = true; |
113 | 113 | break; |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | $found = false; |
121 | 121 | foreach ($games as $key => $game) { |
122 | 122 | if ($this->orderCheckTeamsVal($game, $teams, [7])) { |
123 | - $this->moveCalculatedGames($game,$teams); |
|
123 | + $this->moveCalculatedGames($game, $teams); |
|
124 | 124 | unset($games[$key]); |
125 | 125 | $found = true; |
126 | 126 | break; |
@@ -132,8 +132,8 @@ discard block |
||
132 | 132 | private function cycle5(array &$games, array &$teams) { |
133 | 133 | $found = false; |
134 | 134 | foreach ($games as $key => $game) { |
135 | - if ($this->orderCheckTeamsVal($game, $teams, [], [1,2,3])) { |
|
136 | - $this->moveCalculatedGames($game,$teams); |
|
135 | + if ($this->orderCheckTeamsVal($game, $teams, [], [1, 2, 3])) { |
|
136 | + $this->moveCalculatedGames($game, $teams); |
|
137 | 137 | unset($games[$key]); |
138 | 138 | $found = true; |
139 | 139 | break; |
@@ -36,7 +36,9 @@ discard block |
||
36 | 36 | |
37 | 37 | $games = $this->group->getGames(); |
38 | 38 | |
39 | - if (count($games) <= 4) return $games; |
|
39 | + if (count($games) <= 4) { |
|
40 | + return $games; |
|
41 | + } |
|
40 | 42 | |
41 | 43 | $this->games = []; |
42 | 44 | |
@@ -48,24 +50,34 @@ discard block |
||
48 | 50 | while (count($games) > 0) { |
49 | 51 | // CYCLE 1 |
50 | 52 | // TEAM WHICH DIDN'T PLAY IN LAST GAME (< 4) |
51 | - if ($this->cycle1($games, $teams)) continue; |
|
53 | + if ($this->cycle1($games, $teams)) { |
|
54 | + continue; |
|
55 | + } |
|
52 | 56 | |
53 | 57 | // CYCLE 2 |
54 | 58 | // NOT TEAM WHICH PLAYED IN LAST TWO GAMES (NOT 6 or 7) |
55 | - if ($this->cycle2($games, $teams)) continue; |
|
59 | + if ($this->cycle2($games, $teams)) { |
|
60 | + continue; |
|
61 | + } |
|
56 | 62 | |
57 | 63 | // CYCLE 3 |
58 | 64 | // NOT TEAM WHICH PLAYED IN LAST THREE GAMES (NOT 7) |
59 | 65 | // TEAMS THAT DIDN'T PLAY IN LAST GAME WILL PLAY THIS GAME (< 4) |
60 | - if ($this->cycle3($games, $teams)) continue; |
|
66 | + if ($this->cycle3($games, $teams)) { |
|
67 | + continue; |
|
68 | + } |
|
61 | 69 | |
62 | 70 | // CYCLE 4 |
63 | 71 | // NOT TEAM WHICH PLAYED IN LAST THREE GAMES (NOT 7) |
64 | - if ($this->cycle4($games, $teams)) continue; |
|
72 | + if ($this->cycle4($games, $teams)) { |
|
73 | + continue; |
|
74 | + } |
|
65 | 75 | |
66 | 76 | // CYCLE 5 |
67 | 77 | // TEAMS THAT DIDN'T PLAY IN LAST GAME WILL PLAY THIS GAME (< 4) |
68 | - if ($this->cycle5($games, $teams)) continue; |
|
78 | + if ($this->cycle5($games, $teams)) { |
|
79 | + continue; |
|
80 | + } |
|
69 | 81 | |
70 | 82 | // CYCLE 6 |
71 | 83 | // FIRST AVAILABLE GAME |
@@ -174,11 +186,17 @@ discard block |
||
174 | 186 | $requiredTeams = array_filter($teams, function($a) use ($required) { return in_array($a, $required); }); |
175 | 187 | |
176 | 188 | foreach ($game->getTeamsIds() as $tid) { |
177 | - if (in_array($teams[$tid], $checkVals)) return false; |
|
178 | - if (isset($requiredTeams[$tid])) unset($requiredTeams[$tid]); |
|
189 | + if (in_array($teams[$tid], $checkVals)) { |
|
190 | + return false; |
|
191 | + } |
|
192 | + if (isset($requiredTeams[$tid])) { |
|
193 | + unset($requiredTeams[$tid]); |
|
194 | + } |
|
179 | 195 | } |
180 | 196 | |
181 | - if (count($requiredTeams) > 0) return false; |
|
197 | + if (count($requiredTeams) > 0) { |
|
198 | + return false; |
|
199 | + } |
|
182 | 200 | |
183 | 201 | return true; |
184 | 202 |
@@ -18,11 +18,11 @@ discard block |
||
18 | 18 | $this->group = $group; |
19 | 19 | } |
20 | 20 | |
21 | - public function allowSkip(){ |
|
21 | + public function allowSkip() { |
|
22 | 22 | $this->allowSkip = true; |
23 | 23 | return $this; |
24 | 24 | } |
25 | - public function disallowSkip(){ |
|
25 | + public function disallowSkip() { |
|
26 | 26 | $this->allowSkip = false; |
27 | 27 | return $this; |
28 | 28 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | } |
46 | 46 | |
47 | 47 | public function setInGame(int $inGame) { |
48 | - if ($inGame < 2 || $inGame > 4) throw new \Exception('Expected 2,3 or 4 as inGame '.$inGame.' given'); |
|
48 | + if ($inGame < 2 || $inGame > 4) throw new \Exception('Expected 2,3 or 4 as inGame '.$inGame.' given'); |
|
49 | 49 | $this->inGame = $inGame; |
50 | 50 | return $this; |
51 | 51 | } |
@@ -66,17 +66,17 @@ discard block |
||
66 | 66 | switch ($this->type) { |
67 | 67 | case \R_R:{ |
68 | 68 | $this->group->addGame($this->r_rGames()); |
69 | - break;} |
|
69 | + break; } |
|
70 | 70 | case \TWO_TWO: |
71 | 71 | $teams = $this->group->getTeams(); |
72 | 72 | $discard = []; |
73 | 73 | shuffle($teams); |
74 | 74 | $count = count($teams); |
75 | - while (count($teams) % $this->inGame !== 0) { $discard[] = array_shift($teams); } |
|
75 | + while (count($teams)%$this->inGame !== 0) { $discard[] = array_shift($teams); } |
|
76 | 76 | |
77 | 77 | while (count($teams) > 0) { |
78 | 78 | $tInGame = []; |
79 | - for ($i=0; $i < $this->inGame; $i++) { $tInGame[] = array_shift($teams); } |
|
79 | + for ($i = 0; $i < $this->inGame; $i++) { $tInGame[] = array_shift($teams); } |
|
80 | 80 | $this->group->game($tInGame); |
81 | 81 | } |
82 | 82 | |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | } |
123 | 123 | $games = array_merge($games, $gamesTemp); |
124 | 124 | } |
125 | - break;} |
|
125 | + break; } |
|
126 | 126 | case 4:{ |
127 | 127 | $teamsB = $teams; |
128 | 128 | $lockedTeam1 = array_shift($teamsB); |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | $lockedTeam1 = array_shift($teamsB); |
140 | 140 | } |
141 | 141 | $games[] = new \TournamentGenerator\Game(array_merge([$lockedTeam1], $teamsB), $this->group); |
142 | - break;} |
|
142 | + break; } |
|
143 | 143 | } |
144 | 144 | return $games; |
145 | 145 | } |
@@ -154,11 +154,11 @@ discard block |
||
154 | 154 | public static function circle_genGames2(array $teams = [], \tournamentGenerator\Group $group) { |
155 | 155 | $bracket = []; // ARRAY OF GAMES |
156 | 156 | |
157 | - if (count($teams) % 2 != 0) $teams[] = \DUMMY_TEAM; // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY |
|
157 | + if (count($teams)%2 != 0) $teams[] = \DUMMY_TEAM; // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY |
|
158 | 158 | |
159 | 159 | shuffle($teams); // SHUFFLE TEAMS FOR MORE RANDOMNESS |
160 | 160 | |
161 | - for ($i=0; $i < count($teams)-1; $i++) { |
|
161 | + for ($i = 0; $i < count($teams)-1; $i++) { |
|
162 | 162 | $bracket = array_merge($bracket, Generator::circle_saveBracket($teams, $group)); // SAVE CURRENT ROUND |
163 | 163 | |
164 | 164 | $teams = Generator::circle_rotateBracket($teams); // ROTATE TEAMS IN BRACKET |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | |
173 | 173 | $bracket = []; |
174 | 174 | |
175 | - for ($i=0; $i < count($teams)/2; $i++) { // GO THROUGH HALF OF THE TEAMS |
|
175 | + for ($i = 0; $i < count($teams)/2; $i++) { // GO THROUGH HALF OF THE TEAMS |
|
176 | 176 | |
177 | 177 | $home = $teams[$i]; |
178 | 178 | $reverse = array_reverse($teams); |
@@ -36,8 +36,11 @@ discard block |
||
36 | 36 | |
37 | 37 | |
38 | 38 | public function setType(/** @scrutinizer ignore-all */ string $type = \R_R) { |
39 | - if (in_array($type, \groupTypes)) $this->type = $type; |
|
40 | - else throw new \Exception('Unknown group type: '.$type); |
|
39 | + if (in_array($type, \groupTypes)) { |
|
40 | + $this->type = $type; |
|
41 | + } else { |
|
42 | + throw new \Exception('Unknown group type: '.$type); |
|
43 | + } |
|
41 | 44 | return $this; |
42 | 45 | } |
43 | 46 | public function getType() { |
@@ -45,7 +48,9 @@ discard block |
||
45 | 48 | } |
46 | 49 | |
47 | 50 | public function setInGame(int $inGame) { |
48 | - if ($inGame < 2 || $inGame > 4) throw new \Exception('Expected 2,3 or 4 as inGame '.$inGame.' given'); |
|
51 | + if ($inGame < 2 || $inGame > 4) { |
|
52 | + throw new \Exception('Expected 2,3 or 4 as inGame '.$inGame.' given'); |
|
53 | + } |
|
49 | 54 | $this->inGame = $inGame; |
50 | 55 | return $this; |
51 | 56 | } |
@@ -54,7 +59,9 @@ discard block |
||
54 | 59 | } |
55 | 60 | |
56 | 61 | public function setMaxSize(int $maxSize) { |
57 | - if ($maxSize < 2) throw new \Exception('Max group size has to be at least 2, '.$maxSize.' given'); |
|
62 | + if ($maxSize < 2) { |
|
63 | + throw new \Exception('Max group size has to be at least 2, '.$maxSize.' given'); |
|
64 | + } |
|
58 | 65 | $this->maxSize = $maxSize; |
59 | 66 | return $this; |
60 | 67 | } |
@@ -80,7 +87,9 @@ discard block |
||
80 | 87 | $this->group->game($tInGame); |
81 | 88 | } |
82 | 89 | |
83 | - if (count($discard) > 0 && !$this->allowSkip) throw new \Exception('Couldn\'t make games with all teams. Expected k*'.$this->inGame.' teams '.$count.' teams given - discarting '.count($discard).' teams ('.implode(', ', $discard).') in group '.$this->group.' - allow skip '.($this->allowSkip ? 'True' : 'False')); |
|
90 | + if (count($discard) > 0 && !$this->allowSkip) { |
|
91 | + throw new \Exception('Couldn\'t make games with all teams. Expected k*'.$this->inGame.' teams '.$count.' teams given - discarting '.count($discard).' teams ('.implode(', ', $discard).') in group '.$this->group.' - allow skip '.($this->allowSkip ? 'True' : 'False')); |
|
92 | + } |
|
84 | 93 | break; |
85 | 94 | case \COND_SPLIT: |
86 | 95 | $games = []; |
@@ -95,19 +104,24 @@ discard block |
||
95 | 104 | while ($g > 0) { |
96 | 105 | foreach ($games as $key => $group) { |
97 | 106 | $this->group->addGame(array_shift($games[$key])); |
98 | - if (count($games[$key]) === 0) unset($games[$key]); |
|
107 | + if (count($games[$key]) === 0) { |
|
108 | + unset($games[$key]); |
|
109 | + } |
|
99 | 110 | $g--; |
100 | 111 | } |
101 | 112 | } |
113 | + } else { |
|
114 | + $this->group->addGame($this->r_rGames()); |
|
102 | 115 | } |
103 | - else $this->group->addGame($this->r_rGames()); |
|
104 | 116 | break; |
105 | 117 | } |
106 | 118 | return $this->group->getGames(); |
107 | 119 | } |
108 | 120 | public function r_rGames(array $teams = []) { |
109 | 121 | $games = []; |
110 | - if (count($teams) === 0) $teams = $this->group->getTeams(); |
|
122 | + if (count($teams) === 0) { |
|
123 | + $teams = $this->group->getTeams(); |
|
124 | + } |
|
111 | 125 | switch ($this->inGame) { |
112 | 126 | case 2: |
113 | 127 | $games = Generator::circle_genGames2($teams, $this->group); |
@@ -154,7 +168,10 @@ discard block |
||
154 | 168 | public static function circle_genGames2(array $teams = [], \tournamentGenerator\Group $group) { |
155 | 169 | $bracket = []; // ARRAY OF GAMES |
156 | 170 | |
157 | - if (count($teams) % 2 != 0) $teams[] = \DUMMY_TEAM; // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY |
|
171 | + if (count($teams) % 2 != 0) { |
|
172 | + $teams[] = \DUMMY_TEAM; |
|
173 | + } |
|
174 | + // IF NOT EVEN NUMBER OF TEAMS, ADD DUMMY |
|
158 | 175 | |
159 | 176 | shuffle($teams); // SHUFFLE TEAMS FOR MORE RANDOMNESS |
160 | 177 | |
@@ -178,7 +195,10 @@ discard block |
||
178 | 195 | $reverse = array_reverse($teams); |
179 | 196 | $away = $reverse[$i]; |
180 | 197 | |
181 | - if (($home == \DUMMY_TEAM || $away == \DUMMY_TEAM)) continue; // SKIP WHEN DUMMY_TEAM IS PRESENT |
|
198 | + if (($home == \DUMMY_TEAM || $away == \DUMMY_TEAM)) { |
|
199 | + continue; |
|
200 | + } |
|
201 | + // SKIP WHEN DUMMY_TEAM IS PRESENT |
|
182 | 202 | |
183 | 203 | $bracket[] = new \TournamentGenerator\Game([$home, $away], $group); |
184 | 204 |