Conditions | 11 |
Paths | 4 |
Total Lines | 22 |
Code Lines | 15 |
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 |
||
32 | public static function sortRound(array &$teams, \TournamentGenerator\Round $round, string $ordering = POINTS) { |
||
33 | if (!in_array($ordering, orderingTypes)) throw new \Exception('Unknown ordering type `'.$ordering.'`'); |
||
34 | |||
35 | $groupsIds = $round->getGroupsIds(); |
||
36 | |||
37 | switch ($ordering) { |
||
38 | case \POINTS:{ |
||
39 | uasort($teams, function($a, $b) use ($groupsIds) { |
||
40 | if ($a->sumPoints($groupsIds) === $b->sumPoints($groupsIds) && $a->sumScore($groupsIds) === $b->sumScore($groupsIds)) return 0; |
||
41 | if ($a->sumPoints($groupsIds) === $b->sumPoints($groupsIds)) return ($a->sumScore($groupsIds) > $b->sumScore($groupsIds) ? -1 : 1); |
||
42 | return ($a->sumPoints($groupsIds) > $b->sumPoints($groupsIds) ? -1 : 1); |
||
43 | }); |
||
44 | break;} |
||
45 | case \SCORE:{ |
||
46 | uasort($teams, function($a, $b) use ($groupsIds) { |
||
47 | if ($a->sumScore($groupsIds) === $b->sumScore($groupsIds)) return 0; |
||
48 | return ($a->sumScore($groupsIds) > $b->sumScore($groupsIds) ? -1 : 1); |
||
49 | }); |
||
50 | break;} |
||
51 | } |
||
52 | |||
53 | return $teams; |
||
54 | } |
||
57 |