| Conditions | 13 |
| Paths | 16 |
| Total Lines | 31 |
| Code Lines | 20 |
| Lines | 3 |
| Ratio | 9.68 % |
| Tests | 23 |
| CRAP Score | 13.0122 |
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 |
||
| 75 | 78 | private function sliceRecursive($value, array $keys) |
|
| 76 | { |
||
| 77 | 78 | if (is_array($value) && !empty($value) && array_keys($value) !== range(0, count($value) - 1)) { |
|
| 78 | 10 | $value = (object) $value; |
|
| 79 | 5 | } |
|
| 80 | |||
| 81 | 78 | if (is_object($value)) { |
|
| 82 | 78 | $result = new \stdClass(); |
|
| 83 | |||
| 84 | 78 | $key = array_shift($keys); |
|
| 85 | 78 | if (property_exists($value, $key)) { |
|
| 86 | 78 | if (empty($keys)) { |
|
| 87 | 68 | $result->{$key} = $value->{$key}; |
|
| 88 | 70 | View Code Duplication | } elseif (is_object($value->{$key}) || is_array($value->{$key})) { |
| 89 | 62 | $result->{$key} = $this->sliceRecursive($value->{$key}, $keys); |
|
| 90 | 31 | } |
|
| 91 | 39 | } |
|
| 92 | |||
| 93 | 78 | return $result; |
|
| 94 | } else { |
||
| 95 | 30 | $result = []; |
|
| 96 | 30 | foreach ($value as $subvalue) { |
|
| 97 | 30 | if (empty($keys)) { |
|
| 98 | $result[] = $subvalue; |
||
| 99 | 30 | } elseif (is_object($subvalue) || is_array($subvalue)) { |
|
| 100 | 30 | $result[] = $this->sliceRecursive($subvalue, $keys); |
|
| 101 | 15 | } |
|
| 102 | 15 | } |
|
| 103 | 30 | return $result; |
|
| 104 | } |
||
| 105 | } |
||
| 106 | |||
| 156 |
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.