Conditions | 8 |
Paths | 33 |
Total Lines | 60 |
Code Lines | 30 |
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:
1 | <?php namespace Mbh\Collection\Traits; |
||
74 | public function heapSort(callable $callback): SequenceableInterface |
||
75 | { |
||
76 | $h = new CallbackHeap($callback); |
||
77 | foreach ($this as $elem) { |
||
78 | $h->insert($elem); |
||
79 | } |
||
80 | |||
81 | return static::fromItems($h); |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * Fallback behaviour to use the builtin array sort functions |
||
86 | * |
||
87 | * @param callable $callback The callback for comparison |
||
88 | * @return SequenceableInterface |
||
89 | */ |
||
90 | public function arraySort(callable $callback = null): SequenceableInterface |
||
91 | { |
||
92 | $array = $this->toArray(); |
||
93 | |||
94 | if ($callback) { |
||
95 | usort($array, $callback); |
||
96 | } else { |
||
97 | sort($array); |
||
98 | } |
||
99 | |||
100 | return static::fromArray($array); |
||
101 | } |
||
102 | } |
||
103 |