Conditions | 11 |
Paths | 12 |
Total Lines | 40 |
Code Lines | 24 |
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 |
||
87 | protected function recursivelyConvertValues(array $properties, array $data, array $converters) |
||
88 | { |
||
89 | $property = array_shift($properties); |
||
90 | $isCollection = false; |
||
91 | if (substr($property, -2) === "[]") { |
||
92 | $isCollection = true; |
||
93 | $property = substr($property, 0, -2); |
||
94 | } |
||
95 | |||
96 | if (!count($properties)) { |
||
97 | //this is the deepest field |
||
98 | |||
99 | //apply to all properties |
||
100 | if ($property === '*') { |
||
101 | $data = array_map(function ($value) use ($converters) { |
||
102 | foreach ($converters as $converter) { |
||
103 | $value = $converter->convert($value); |
||
104 | } |
||
105 | return $value; |
||
106 | }, $data); |
||
107 | } elseif (isset($data[$property]) || array_key_exists($property, $data)) { |
||
108 | //This is an associative array |
||
109 | foreach ($converters as $converter) { |
||
110 | $data[$property] = $converter->convert($data[$property]); |
||
111 | } |
||
112 | } |
||
113 | } else { |
||
114 | if (isset($data[$property])) { |
||
115 | if ($isCollection) { |
||
116 | foreach ($data[$property] as $key => $item) { |
||
117 | $data[$property][$key] = $this->recursivelyConvertValues($properties, $item, $converters); |
||
118 | } |
||
119 | |||
120 | } else { |
||
121 | $data[$property] = $this->recursivelyConvertValues($properties, $data[$property], $converters); |
||
122 | } |
||
123 | } |
||
124 | } |
||
125 | return $data; |
||
126 | } |
||
127 | } |
||
128 |