Conditions | 13 |
Paths | 10 |
Total Lines | 30 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
48 | protected function convertItem($item) |
||
49 | { |
||
50 | foreach ($this->itemConverters as $converter) { |
||
51 | $item = $converter->convert($item); |
||
52 | if ($item && !(is_array($item) || ($item instanceof \ArrayAccess && $item instanceof \Traversable))) { |
||
53 | throw new UnexpectedTypeException($item, 'false or array'); |
||
54 | } |
||
55 | |||
56 | if (!$item) { |
||
57 | return $item; |
||
58 | } |
||
59 | } |
||
60 | |||
61 | if ($item && !(is_array($item) || ($item instanceof \ArrayAccess && $item instanceof \Traversable))) { |
||
62 | throw new UnexpectedTypeException($item, 'false or array'); |
||
63 | } |
||
64 | |||
65 | foreach ($this->valueConverters as $property => $converters) { |
||
66 | //is this is targeting a nested field |
||
67 | if (strpos($property, '/') !== false) { |
||
68 | $properties = explode('/', $property); |
||
69 | $item = $this->recursivelyConvertValues($properties, $item, $converters); |
||
70 | |||
71 | } else { |
||
72 | $item = $this->recursivelyConvertValues([$property], $item, $converters); |
||
73 | } |
||
74 | } |
||
75 | |||
76 | return $item; |
||
77 | } |
||
78 | |||
128 |