Conditions | 4 |
Paths | 5 |
Total Lines | 75 |
Code Lines | 46 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
11 | public function generate() { |
||
12 | $this->allowSkip(); |
||
13 | |||
14 | $countTeams = count($this->getTeams()); |
||
15 | |||
16 | if ($countTeams < 3) throw new \Exception('Double elimination is possible for minimum of 3 teams - '.$countTeams.' teams given.'); |
||
17 | |||
18 | |||
19 | // CALCULATE BYES |
||
20 | $nextPow = 0; |
||
21 | $byes = $this->calcByes($countTeams, $nextPow); |
||
22 | |||
23 | $startRound = $this->round('Start round'); |
||
24 | |||
25 | $roundsNum = log($nextPow, 2)*2; |
||
26 | |||
27 | $startGroups = ($countTeams+$byes)/2; |
||
28 | |||
29 | $previousGroups = []; |
||
30 | $previousLosingGroups = []; |
||
31 | $groupIds = []; |
||
32 | $allGroups = []; |
||
33 | |||
34 | for ($i=1; $i <= $startGroups; $i++) { |
||
35 | $g = $startRound->group([ |
||
36 | 'name' => 'Start group - '.$i, |
||
37 | 'inGame' => 2, |
||
38 | 'type' => \TWO_TWO, |
||
39 | ]); |
||
40 | $allGroups[] = $g; |
||
41 | $groupIds[] = $g->id; |
||
42 | $previousGroups[] = $g; |
||
43 | } |
||
44 | |||
45 | // SPLIT TEAMS EVENLY |
||
46 | $this->splitTeams(); |
||
47 | |||
48 | for ($r=2; $r <= $roundsNum-1; $r++) { |
||
49 | $groups = []; |
||
50 | $losingGroups = []; |
||
51 | $round = $this->round('Round '.$r); |
||
52 | |||
53 | // GENERATE GROUPS AND PROGRESSIONS |
||
54 | |||
55 | // GENERATING LOSING AND WINNING SIDE |
||
56 | $lastLosingGroup = $this->generateLosingSide($r, $byes, $countTeams, $round, $allGroups, $groups, $previousLosingGroups, $previousGroups, $losingGroups); |
||
57 | $this->generateWinSide($r, $byes, $countTeams, $round, $allGroups, $groups, $lastWinningGroup, $previousGroups); |
||
58 | |||
59 | $previousGroups = $groups; |
||
60 | $previousLosingGroups = $losingGroups; |
||
61 | } |
||
62 | |||
63 | // LAST ROUND |
||
64 | $round = $this->round('Round '.$roundsNum.' - Finale'); |
||
65 | $groupFinal = $round->group([ |
||
66 | 'name' => 'Round '.$r.' - finale', |
||
67 | 'inGame' => 2, |
||
68 | 'type' => \TWO_TWO, |
||
69 | 'order' => 1, |
||
70 | ]); |
||
71 | $allGroups[] = $groupFinal; |
||
72 | $lastLosingGroup->progression($groupFinal, 0, 1); |
||
73 | $lastWinningGroup->progression($groupFinal, 0, 1); |
||
74 | |||
75 | // REPEAT GROUP IF LOSING TEAM WON |
||
76 | $group = $round->group([ |
||
77 | 'name' => 'Round '.$r.' - finale (2)', |
||
78 | 'inGame' => 2, |
||
79 | 'type' => \TWO_TWO, |
||
80 | 'order' => 1, |
||
81 | ]); |
||
82 | $twoLoss = new \TournamentGenerator\TeamFilter('losses', '=', 1, $allGroups); |
||
83 | $groupFinal->progression($group, 0, 2)->addFilter($twoLoss); |
||
84 | |||
85 | return $this; |
||
86 | |||
178 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.