| Conditions | 11 |
| Paths | 1 |
| Total Lines | 25 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 14 |
| CRAP Score | 11.6653 |
| 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 | 3 | public function format($items) |
|
| 12 | { |
||
| 13 | 3 | $column = $this->config('column', 'id'); |
|
| 14 | |||
| 15 | usort($items, function($a, $b) use ($column) { |
||
| 16 | 3 | $aVal = $a->getItem($column); |
|
| 17 | 3 | $bVal = $b->getItem($column); |
|
| 18 | 3 | if(is_null($aVal) && is_null($bVal)) { |
|
| 19 | return 0; |
||
| 20 | } |
||
| 21 | 3 | if(is_null($aVal) && !is_null($bVal)) { |
|
| 22 | return 1; |
||
| 23 | } |
||
| 24 | 3 | if(!is_null($aVal) && is_null($bVal)) { |
|
| 25 | 1 | return -1; |
|
| 26 | } |
||
| 27 | 3 | if(is_string($aVal) || is_string($bVal)) { |
|
| 28 | 1 | return $this->compareStrings($aVal, $bVal); |
|
| 29 | } |
||
| 30 | 2 | if(is_int($aVal) || is_int($bVal)) { |
|
| 31 | 2 | return $this->compareInts($aVal, $bVal); |
|
| 32 | } |
||
| 33 | return 0; |
||
| 34 | 3 | }); |
|
| 35 | 3 | return $items; |
|
| 36 | } |
||
| 60 | } |