| Conditions | 11 |
| Paths | 121 |
| Total Lines | 16 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 10 |
| CRAP Score | 11.0908 |
| Changes | 2 | ||
| 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 |
||
| 15 | 1 | public function filter(&$store) |
|
| 16 | { |
||
| 17 | 1 | foreach ($store as $key => &$value) { |
|
| 18 | 1 | $value = is_string($value) ? trim($value) : $value; |
|
| 19 | 1 | $empty = $value === null || (is_array($value) && empty($value)); |
|
| 20 | |||
| 21 | 1 | $empty = $empty || (is_scalar($value) && $value !== false && (string) $value === ''); |
|
| 22 | |||
| 23 | 1 | if ($empty) { |
|
| 24 | 1 | $store[$key] = null; |
|
| 25 | } else { |
||
| 26 | 1 | if (is_object($value)) { |
|
| 27 | $value = (array) $value; |
||
| 28 | } |
||
| 29 | 1 | if (is_array($value)) { |
|
| 30 | 1 | $this->filter($value); |
|
| 31 | } |
||
| 36 |