Conditions | 11 |
Paths | 4 |
Total Lines | 20 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 static function sortGroup(array &$teams, \TournamentGenerator\Group $group, string $ordering = POINTS) { |
||
12 | if (!in_array($ordering, orderingTypes)) throw new \Exception('Unknown ordering type `'.$ordering.'`'); |
||
13 | |||
14 | switch ($ordering) { |
||
15 | case \POINTS:{ |
||
16 | uasort($teams, function($a, $b) use ($group) { |
||
17 | if ($a->groupResults[$group->id]["points"] === $b->groupResults[$group->id]["points"] && $a->groupResults[$group->id]["score"] === $b->groupResults[$group->id]["score"]) return 0; |
||
18 | if ($a->groupResults[$group->id]["points"] === $b->groupResults[$group->id]["points"]) return ($a->groupResults[$group->id]["score"] > $b->groupResults[$group->id]["score"] ? -1 : 1); |
||
19 | return ($a->groupResults[$group->id]["points"] > $b->groupResults[$group->id]["points"] ? -1 : 1); |
||
20 | }); |
||
21 | break;} |
||
22 | case \SCORE:{ |
||
23 | uasort($teams, function($a, $b) use ($group) { |
||
24 | if ($a->groupResults[$group->id]["score"] === $b->groupResults[$group->id]["score"]) return 0; |
||
25 | return ($a->groupResults[$group->id]["score"] > $b->groupResults[$group->id]["score"] ? -1 : 1); |
||
26 | }); |
||
27 | break;} |
||
28 | } |
||
29 | |||
30 | return $teams; |
||
31 | } |
||
57 |