| Conditions | 10 |
| Paths | 13 |
| Total Lines | 24 |
| Code Lines | 13 |
| 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 |
||
| 20 | public function toOptions() |
||
| 21 | { |
||
| 22 | $options = []; |
||
| 23 | |||
| 24 | foreach ($this as $prop => $value) |
||
|
|
|||
| 25 | { |
||
| 26 | $key = (strpos($prop, "on") !== 0) ? Inflector::underscore($prop) : $prop; |
||
| 27 | |||
| 28 | if ($value instanceof Optionable){ |
||
| 29 | $value = $value->toOptions(); |
||
| 30 | } elseif (is_array($value)) { |
||
| 31 | foreach ($value as $k => $v) { |
||
| 32 | if ($v instanceof Optionable) { |
||
| 33 | $value[$k] = $v->toOptions(); |
||
| 34 | } |
||
| 35 | } |
||
| 36 | } |
||
| 37 | |||
| 38 | if (!is_array($value) && $value !== null || !empty($value)) { |
||
| 39 | $options[$key] = $value; |
||
| 40 | } |
||
| 41 | } |
||
| 42 | return $options; |
||
| 43 | } |
||
| 44 | |||
| 45 | } |