@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | $this->name = $name; |
20 | 20 | } |
21 | 21 | |
22 | - public function addRound(Round ...$rounds){ |
|
22 | + public function addRound(Round ...$rounds) { |
|
23 | 23 | foreach ($rounds as $round) { |
24 | 24 | if ($round instanceof Round) $this->rounds[] = $round; |
25 | 25 | else throw new Exception('Trying to add round which is not an instance of Round class.'); |
@@ -31,15 +31,15 @@ discard block |
||
31 | 31 | $this->rounds[] = $r->setSkip($this->allowSkip); |
32 | 32 | return $r; |
33 | 33 | } |
34 | - public function getRounds(){ |
|
34 | + public function getRounds() { |
|
35 | 35 | return $this->rounds; |
36 | 36 | } |
37 | 37 | |
38 | - public function allowSkip(){ |
|
38 | + public function allowSkip() { |
|
39 | 39 | $this->allowSkip = true; |
40 | 40 | return $this; |
41 | 41 | } |
42 | - public function disallowSkip(){ |
|
42 | + public function disallowSkip() { |
|
43 | 43 | $this->allowSkip = false; |
44 | 44 | return $this; |
45 | 45 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | |
54 | 54 | public function addTeam(...$teams) { |
55 | 55 | foreach ($teams as $team) { |
56 | - if ($team instanceof Team) { |
|
56 | + if ($team instanceof Team) { |
|
57 | 57 | $this->teams[] = $team; |
58 | 58 | } |
59 | 59 | elseif (gettype($team) === 'array') { |
@@ -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 |
@@ -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, |
@@ -43,12 +43,12 @@ |
||
43 | 43 | |
44 | 44 | private $groups = []; |
45 | 45 | |
46 | - function __construct(string $what = 'points', string $how = '>', $val = 0, $groups = []){ |
|
46 | + function __construct(string $what = 'points', string $how = '>', $val = 0, $groups = []) { |
|
47 | 47 | if (in_array(strtolower($what), ['points', 'score', 'wins', 'draws', 'losses', 'second', 'third', 'team', 'notprogressed', 'progressed'])) $this->what = strtolower($what); |
48 | 48 | if (in_array($how, ['>', '<', '>=', '<=', '=', '!='])) $this->how = $how; |
49 | 49 | if ((gettype($val) === 'integer' && strtolower($what) !== 'team') || ($val instanceof Team && strtolower($what) === 'team')) $this->val = $val; |
50 | 50 | foreach ($groups as $group) { |
51 | - if ($group instanceof Group) $this->groups[] = $group->id; |
|
51 | + if ($group instanceof Group) $this->groups[] = $group->id; |
|
52 | 52 | } |
53 | 53 | } |
54 | 54 | function __toString() { |
@@ -76,10 +76,10 @@ discard block |
||
76 | 76 | if (count($error) > 0) throw new Exception('Trying to add teams ('.count($error).') that are not instance of Team class'.PHP_EOL.print_r($error, true)); |
77 | 77 | return $this; |
78 | 78 | } |
79 | - public function getTeams(){ |
|
79 | + public function getTeams() { |
|
80 | 80 | return $this->teams; |
81 | 81 | } |
82 | - public function getTeamsIds(){ |
|
82 | + public function getTeamsIds() { |
|
83 | 83 | $ids = []; |
84 | 84 | foreach ($this->teams as $team) { |
85 | 85 | $ids[] = $team->id; |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | $team->addLoss($this->group->id); |
127 | 127 | $this->results[$team->id] += ['points' => $this->group->lostPoints, 'type' => 'loss']; |
128 | 128 | } |
129 | - break;} |
|
129 | + break; } |
|
130 | 130 | case 3:{ |
131 | 131 | switch ($i) { |
132 | 132 | case 1: |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | $this->results[$team->id] += ['points' => $this->group->lostPoints, 'type' => 'loss']; |
146 | 146 | break; |
147 | 147 | } |
148 | - break;} |
|
148 | + break; } |
|
149 | 149 | case 4:{ |
150 | 150 | switch ($i) { |
151 | 151 | case 1: |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | $this->results[$team->id] += ['points' => $this->group->lostPoints, 'type' => 'loss']; |
170 | 170 | break; |
171 | 171 | } |
172 | - break;} |
|
172 | + break; } |
|
173 | 173 | } |
174 | 174 | $team->groupResults[$this->group->id]['score'] += $score; |
175 | 175 | $i++; |
@@ -66,11 +66,11 @@ discard block |
||
66 | 66 | return 'Group '.$this->name; |
67 | 67 | } |
68 | 68 | |
69 | - public function allowSkip(){ |
|
69 | + public function allowSkip() { |
|
70 | 70 | $this->allowSkip = true; |
71 | 71 | return $this; |
72 | 72 | } |
73 | - public function disallowSkip(){ |
|
73 | + public function disallowSkip() { |
|
74 | 74 | $this->allowSkip = false; |
75 | 75 | return $this; |
76 | 76 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | |
85 | 85 | public function addTeam(...$teams) { |
86 | 86 | foreach ($teams as $team) { |
87 | - if ($team instanceof Team) { |
|
87 | + if ($team instanceof Team) { |
|
88 | 88 | $this->teams[] = $team; |
89 | 89 | $team->groupResults[$this->id] = [ |
90 | 90 | 'group' => $this, |
@@ -242,13 +242,13 @@ discard block |
||
242 | 242 | if ($a->groupResults[$this->id]["points"] === $b->groupResults[$this->id]["points"]) return ($a->groupResults[$this->id]["score"] > $b->groupResults[$this->id]["score"] ? -1 : 1); |
243 | 243 | return ($a->groupResults[$this->id]["points"] > $b->groupResults[$this->id]["points"] ? -1 : 1); |
244 | 244 | }); |
245 | - break;} |
|
245 | + break; } |
|
246 | 246 | case SCORE:{ |
247 | 247 | usort($this->teams, function($a, $b) { |
248 | 248 | if ($a->groupResults[$this->id]["score"] === $b->groupResults[$this->id]["score"]) return 0; |
249 | 249 | return ($a->groupResults[$this->id]["score"] > $b->groupResults[$this->id]["score"] ? -1 : 1); |
250 | 250 | }); |
251 | - break;} |
|
251 | + break; } |
|
252 | 252 | } |
253 | 253 | return $this->getTeams($filters); |
254 | 254 | } |
@@ -313,19 +313,19 @@ discard block |
||
313 | 313 | switch ($this->type) { |
314 | 314 | case R_R:{ |
315 | 315 | $this->games = $this->r_rGames(); |
316 | - break;} |
|
316 | + break; } |
|
317 | 317 | case TWO_TWO: |
318 | 318 | $teams = $this->teams; |
319 | 319 | $discard = []; |
320 | 320 | shuffle($teams); |
321 | 321 | $count = count($teams); |
322 | - while (count($teams) % $this->inGame !== 0) { |
|
322 | + while (count($teams)%$this->inGame !== 0) { |
|
323 | 323 | $discard[] = array_shift($teams); |
324 | 324 | } |
325 | 325 | |
326 | 326 | while (count($teams) > 0) { |
327 | 327 | $tInGame = []; |
328 | - for ($i=0; $i < $this->inGame; $i++) { |
|
328 | + for ($i = 0; $i < $this->inGame; $i++) { |
|
329 | 329 | $tInGame[] = array_shift($teams); |
330 | 330 | } |
331 | 331 | $this->game($tInGame); |
@@ -364,7 +364,7 @@ discard block |
||
364 | 364 | $this->games[] = $g; |
365 | 365 | return $g; |
366 | 366 | } |
367 | - public function addGame(Game ...$games){ |
|
367 | + public function addGame(Game ...$games) { |
|
368 | 368 | foreach ($game as $game) { |
369 | 369 | if ($game instanceof Game) $this->games[] = $game; |
370 | 370 | else throw new Exception('Trying to add game which is not instance of Game object.'); |
@@ -460,7 +460,7 @@ discard block |
||
460 | 460 | foreach ($games as $key => $game) { |
461 | 461 | $gTeams = $game->getTeamsIds(); |
462 | 462 | $suitable = true; |
463 | - $requiredTeams = array_filter($teams, function($a){ |
|
463 | + $requiredTeams = array_filter($teams, function($a) { |
|
464 | 464 | return $a < 4; |
465 | 465 | }); |
466 | 466 | foreach ($gTeams as $tid) { |
@@ -511,7 +511,7 @@ discard block |
||
511 | 511 | foreach ($games as $key => $game) { |
512 | 512 | $gTeams = $game->getTeamsIds(); |
513 | 513 | $suitable = false; |
514 | - $requiredTeams = array_filter($teams, function($a){ |
|
514 | + $requiredTeams = array_filter($teams, function($a) { |
|
515 | 515 | return $a < 4; |
516 | 516 | }); |
517 | 517 | foreach ($gTeams as $tid) { |
@@ -556,7 +556,7 @@ discard block |
||
556 | 556 | $games = array_merge($games, $games); |
557 | 557 | } |
558 | 558 | // $this->orderGames(); |
559 | - break;} |
|
559 | + break; } |
|
560 | 560 | case 4:{ |
561 | 561 | $teamsB = $teams; |
562 | 562 | $lockedTeam1 = array_shift($teamsB); |
@@ -574,7 +574,7 @@ discard block |
||
574 | 574 | } |
575 | 575 | $games[] = new Game(array_merge([$lockedTeam1], $teamsB), $this); |
576 | 576 | // $this->orderGames(); |
577 | - break;} |
|
577 | + break; } |
|
578 | 578 | } |
579 | 579 | return $games; |
580 | 580 | } |
@@ -601,7 +601,7 @@ discard block |
||
601 | 601 | } |
602 | 602 | return $this; |
603 | 603 | } |
604 | - public function isPlayed(){ |
|
604 | + public function isPlayed() { |
|
605 | 605 | foreach ($this->games as $game) { |
606 | 606 | if ((isset($game) || !$this->getSkip()) && !$game->isPlayed()) return false; |
607 | 607 | } |
@@ -43,7 +43,7 @@ |
||
43 | 43 | return $this; |
44 | 44 | } |
45 | 45 | |
46 | - public function progressBlank(){ |
|
46 | + public function progressBlank() { |
|
47 | 47 | $teams = $this->from->isPlayed() ? $this->from->sortTeams($this->filters) : $this->from->simulate($this->filters); |
48 | 48 | if (count($this->filters) === 0 || $this->len !== null || $this->start !== 0) $next = array_splice($teams, $this->start, ($this->len == null ? count($teams) : $this->len)); |
49 | 49 | else $next = $teams; |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | return $this->name; |
24 | 24 | } |
25 | 25 | |
26 | - public function addGroup(Group ...$groups){ |
|
26 | + public function addGroup(Group ...$groups) { |
|
27 | 27 | foreach ($groups as $group) { |
28 | 28 | if ($group instanceof Group) $this->groups[] = $group; |
29 | 29 | else throw new Exception('Trying to add group which is not an instance of Group class.'); |
@@ -35,21 +35,21 @@ discard block |
||
35 | 35 | $this->groups[] = $g->setSkip($this->allowSkip); |
36 | 36 | return $g; |
37 | 37 | } |
38 | - public function getGroups(){ |
|
38 | + public function getGroups() { |
|
39 | 39 | $this->orderGroups(); |
40 | 40 | return $this->groups; |
41 | 41 | } |
42 | 42 | public function orderGroups() { |
43 | - usort($this->groups, function($a, $b){ |
|
44 | - return $a->order - $b->order; |
|
43 | + usort($this->groups, function($a, $b) { |
|
44 | + return $a->order-$b->order; |
|
45 | 45 | }); |
46 | 46 | } |
47 | 47 | |
48 | - public function allowSkip(){ |
|
48 | + public function allowSkip() { |
|
49 | 49 | $this->allowSkip = true; |
50 | 50 | return $this; |
51 | 51 | } |
52 | - public function disallowSkip(){ |
|
52 | + public function disallowSkip() { |
|
53 | 53 | $this->allowSkip = false; |
54 | 54 | return $this; |
55 | 55 | } |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | return $this->allowSkip; |
62 | 62 | } |
63 | 63 | |
64 | - public function genGames(){ |
|
64 | + public function genGames() { |
|
65 | 65 | $games = []; |
66 | 66 | $ex = []; |
67 | 67 | $g = 0; |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | public function getGames() { |
87 | 87 | return $this->games; |
88 | 88 | } |
89 | - public function isPlayed(){ |
|
89 | + public function isPlayed() { |
|
90 | 90 | foreach ($this->groups as $group) { |
91 | 91 | if (!$group->isPlayed()) return false; |
92 | 92 | } |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | |
96 | 96 | public function addTeam(...$teams) { |
97 | 97 | foreach ($teams as $team) { |
98 | - if ($team instanceof Team) { |
|
98 | + if ($team instanceof Team) { |
|
99 | 99 | $this->teams[] = $team; |
100 | 100 | } |
101 | 101 | elseif (gettype($team) === 'array') { |
@@ -156,14 +156,14 @@ discard block |
||
156 | 156 | return $this; |
157 | 157 | } |
158 | 158 | |
159 | - public function progress(){ |
|
159 | + public function progress() { |
|
160 | 160 | foreach ($this->groups as $group) { |
161 | 161 | $group->progress(); |
162 | 162 | } |
163 | 163 | return $this; |
164 | 164 | } |
165 | 165 | |
166 | - public function progressBlank(){ |
|
166 | + public function progressBlank() { |
|
167 | 167 | if (!$this->isPlayed()) $this->simulate(); |
168 | 168 | foreach ($this->groups as $group) { |
169 | 169 | $group->progressBlank(); |