| Conditions | 11 |
| Paths | 1 |
| Total Lines | 27 |
| 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 |
||
| 39 | public function getOrderedByHighestDouble(): PlayerCollection |
||
| 40 | { |
||
| 41 | $elements = $this->elements; |
||
| 42 | |||
| 43 | usort( |
||
| 44 | $elements, |
||
| 45 | static function (Player $playerA, Player $playerB): int { |
||
| 46 | $doubleA = $playerA->getHighestDouble(); |
||
| 47 | $doubleB = $playerB->getHighestDouble(); |
||
| 48 | |||
| 49 | if (null === $doubleA && null === $doubleB) { |
||
| 50 | return 0; |
||
| 51 | } |
||
| 52 | |||
| 53 | if ((null !== $doubleA) && $doubleA->isDouble() && (null === $doubleB || !$doubleB->isDouble())) { |
||
| 54 | return 0; |
||
| 55 | } |
||
| 56 | |||
| 57 | if ((null !== $doubleB) && $doubleB->isDouble() && (null === $doubleA || !$doubleA->isDouble())) { |
||
| 58 | return 1; |
||
| 59 | } |
||
| 60 | |||
| 61 | return $doubleB->getValue() <=> $doubleA->getValue(); |
||
| 62 | } |
||
| 63 | ); |
||
| 64 | |||
| 65 | return new static($elements); |
||
| 66 | } |
||
| 98 |