| Conditions | 12 |
| Paths | 20 |
| Total Lines | 35 |
| Code Lines | 18 |
| 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 |
||
| 73 | protected function getValuesForWildcardKey($data, array $keys) { |
||
| 74 | $values = []; |
||
| 75 | |||
| 76 | if ( ! is_array($data) && ! $data instanceof Traversable) { |
||
| 77 | if ($data instanceof IArrayable) { |
||
| 78 | $data = $data->toArray(); |
||
| 79 | } |
||
| 80 | |||
| 81 | if ( ! is_array($data)) { |
||
| 82 | $data = []; |
||
| 83 | } |
||
| 84 | } |
||
| 85 | |||
| 86 | if (count($keys) === 0) { |
||
| 87 | foreach ($data as $itemKey => $itemValue) { |
||
| 88 | $values[$itemKey] = $itemValue; |
||
| 89 | } |
||
| 90 | } |
||
| 91 | |||
| 92 | if (count($keys) > 0) { |
||
| 93 | foreach ($data as $itemKey => $itemValue) { |
||
| 94 | $nestedValues = $this->getValues($itemValue, $keys); |
||
| 95 | $isLastWildcard = ! array_contains($keys, '*'); |
||
| 96 | |||
| 97 | foreach ($nestedValues as $nestedKey => $nestedValue) { |
||
| 98 | // do no collect null values unless it is the last wildcard node |
||
| 99 | if ($nestedValue !== null || $isLastWildcard) { |
||
| 100 | $values[$this->buildKey($itemKey, $nestedKey)] = $nestedValue; |
||
| 101 | } |
||
| 102 | } |
||
| 103 | } |
||
| 104 | } |
||
| 105 | |||
| 106 | return $values; |
||
| 107 | } |
||
| 108 | |||
| 160 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.