| Conditions | 10 |
| Paths | 1 |
| Total Lines | 24 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 14 |
| CRAP Score | 10 |
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 |
||
| 75 | 13 | public static function sortAdvices(array $advices) |
|
| 76 | { |
||
| 77 | 13 | $sortedAdvices = $advices; |
|
| 78 | 13 | uasort($sortedAdvices, function(Advice $first, Advice $second) { |
|
|
|
|||
| 79 | switch (true) { |
||
| 80 | 8 | case $first instanceof AdviceBefore && !($second instanceof AdviceBefore): |
|
| 81 | 3 | return -1; |
|
| 82 | |||
| 83 | 6 | case $first instanceof AdviceAround && !($second instanceof AdviceAround): |
|
| 84 | 3 | return 1; |
|
| 85 | |||
| 86 | 4 | case $first instanceof AdviceAfter && !($second instanceof AdviceAfter): |
|
| 87 | 2 | return $second instanceof AdviceBefore ? 1 : -1; |
|
| 88 | |||
| 89 | 2 | case ($first instanceof OrderedAdvice && $second instanceof OrderedAdvice): |
|
| 90 | 1 | return $first->getAdviceOrder() - $second->getAdviceOrder(); |
|
| 91 | |||
| 92 | default: |
||
| 93 | 1 | return 0; |
|
| 94 | } |
||
| 95 | 13 | }); |
|
| 96 | |||
| 97 | 13 | return $sortedAdvices; |
|
| 98 | } |
||
| 99 | } |
||
| 100 |