Conditions | 10 |
Paths | 12 |
Total Lines | 37 |
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 |
||
98 | protected function setProperties(array $properties, array $mappings = null, string $column = null) |
||
99 | { |
||
100 | if ($mappings === null) { |
||
101 | $mappings = $this->mappings; |
||
102 | } |
||
103 | |||
104 | foreach ($properties as $key => $value) { |
||
105 | if (!isset($mappings[$key])) { |
||
106 | throw new RuntimeException(sprintf('Missing mapping for key "%s"', $key)); |
||
107 | } |
||
108 | |||
109 | if (is_array($value) && is_array($mappings[$key])) { |
||
110 | // recursion |
||
111 | if (isset($mappings[$key]['__multi'])) { |
||
112 | // handle multi target structure (with columns) |
||
113 | /** |
||
114 | * @var array $value |
||
115 | */ |
||
116 | foreach ($value as $_column => $_value) { |
||
117 | $this->setProperties($_value, $mappings[$key], $_column); |
||
118 | } |
||
119 | } else { |
||
120 | // handle single target structure |
||
121 | $this->setProperties($value, $mappings[$key]); |
||
122 | } |
||
123 | } elseif (is_callable($mappings[$key])) { |
||
124 | // call single and multi target mapping |
||
125 | // if column is set it is used to get object from the callback in __multi |
||
126 | $mappings[$key]( |
||
127 | $value, |
||
128 | $column !== null ? $mappings['__multi']($column) : null |
||
129 | ); |
||
130 | } else { |
||
131 | throw new RuntimeException(sprintf('Invalid mapping for key "%s"', $key)); |
||
132 | } |
||
133 | } |
||
134 | } |
||
135 | } |
||
136 |