Conditions | 11 |
Paths | 7 |
Total Lines | 59 |
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:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
1 | <?php |
||
116 | private function generateLosingSide(int &$r, int &$byes, int &$countTeams, \TournamentGenerator\Round &$round, array &$allGroups, array &$groups, array &$previousLosingGroups = [], array &$previousGroups = [], array &$losingGroups = []) { |
||
117 | $losingGroupTeamsCount = count($previousLosingGroups)+count($previousGroups); |
||
118 | $order = 2; |
||
119 | if (\TournamentGenerator\isPowerOf2($losingGroupTeamsCount)) { // IF THE NUMBER OF TEAMS IS A POWER OF 2, GENERATE GROUPS WITHOUT BYES |
||
120 | for ($g=1; $g <= $losingGroupTeamsCount/2; $g++) { |
||
121 | $group = $round->group([ |
||
122 | 'name' => 'Round '.$r.' - loss '.$g, |
||
123 | 'inGame' => 2, |
||
124 | 'type' => \TWO_TWO, |
||
125 | 'order' => $order, |
||
126 | ]); |
||
127 | $allGroups[] = $group; |
||
128 | $order += 2; |
||
129 | $losingGroups[] = $group; |
||
130 | $lastLosingGroup = $group; // KEEP THE LAST GROUP FOR FINALE |
||
131 | if ($r === 2) { // FIRST LOSING ROUND |
||
132 | $previousGroups[2*($g-1)]->progression($group, 1, 1); // PROGRESS FROM STARTING GROUP |
||
133 | $previousGroups[(2*($g-1))+1]->progression($group, 1, 1); // PROGREESS FROM STARTING GROUP |
||
134 | } |
||
135 | elseif ($losingGroupTeamsCount >= 2) { |
||
136 | $previousLosingGroups[$g-1]->progression($group, 0, 1); // PROGRESS FROM LOSING GROUP BEFORE |
||
137 | if (isset(array_reverse($previousGroups)[$g-1])) array_reverse($previousGroups)[$g-1]->progression($group, 1, 1); // PROGREESS FROM WINNING GROUP BEFORE |
||
138 | else $previousLosingGroups[$g]->progression($group, 0, 1); // PROGRESS OTHER TEAM FROM LOSING GROUP BEEFORE |
||
139 | } |
||
140 | } |
||
141 | } |
||
142 | else { // IF THE NUMBER OF TEAMS IS NOT A POWER OF 2, GENERATE GROUPS WITH BYES |
||
143 | // LOOK FOR THE CLOSEST LOWER POWER OF 2 |
||
144 | $losingByes = $losingGroupTeamsCount-bindec(str_pad(1, strlen(decbin($losingGroupTeamsCount)), 0, STR_PAD_RIGHT)); |
||
145 | $n = (floor(count($previousLosingGroups)/2)+$losingByes); |
||
146 | $byesGroupsNums = []; |
||
147 | $byesProgressed = 0; |
||
148 | for ($i=0; $i < $losingByes; $i++) { |
||
149 | $byesGroupsNums[] = $n-($i*2); |
||
150 | } |
||
151 | $lastGroup = 0; |
||
152 | for ($g=1; $g <= ((count($previousLosingGroups)/2)+$losingByes); $g++) { |
||
153 | $group = $round->group([ |
||
154 | 'name' => 'Round '.$r.' - loss '.$g, |
||
155 | 'inGame' => 2, |
||
156 | 'type' => \TWO_TWO, |
||
157 | 'order' => $order, |
||
158 | ]); |
||
159 | $allGroups[] = $group; |
||
160 | $order += 2; |
||
161 | $losingGroups[] = $group; |
||
162 | $lastLosingGroup = $group; // KEEP THE LAST GROUP FOR FINALE |
||
163 | if (in_array($g, $byesGroupsNums) && isset($previousGroups[$byesProgressed])) { // EMPTY GROUP FROM BYE |
||
164 | $previousGroups[$byesProgressed]->progression($group, 1, 1); // PROGRESS FROM WINNING GROUP BEFORE |
||
165 | $byesProgressed++; |
||
166 | } |
||
167 | else { |
||
168 | $previousLosingGroups[$lastGroup]->progression($group, 0, 1); // PROGRESS FROM LOSING GROUP BEFORE |
||
169 | if (isset($previousLosingGroups[$lastGroup + 1])) $previousLosingGroups[$lastGroup + 1]->progression($group, 0, 1); // PROGREESS FROM LOSING GROUP BEFORE |
||
170 | $lastGroup += 2; |
||
171 | } |
||
172 | } |
||
173 | } |
||
174 | return $lastLosingGroup; |
||
1 ignored issue
–
show
|
|||
175 | } |
||
178 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.