Conditions | 15 |
Paths | 9 |
Total Lines | 46 |
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 |
||
159 | public function set($data) |
||
160 | { |
||
161 | if(is_array($data) || is_object($data)) { |
||
162 | $mapper = \net\authorize\util\Mapper::Instance(); |
||
163 | foreach($data AS $key => $value) { |
||
164 | $classDetails = $mapper->getClass(get_class() , $key); |
||
165 | |||
166 | if($classDetails !== NULL ) { |
||
167 | if ($classDetails->isArray) { |
||
168 | if ($classDetails->isCustomDefined) { |
||
169 | foreach($value AS $keyChild => $valueChild) { |
||
170 | $type = new $classDetails->className; |
||
171 | $type->set($valueChild); |
||
172 | $this->{'addTo' . $key}($type); |
||
173 | } |
||
174 | } |
||
175 | else if ($classDetails->className === 'DateTime' || $classDetails->className === 'Date' ) { |
||
176 | foreach($value AS $keyChild => $valueChild) { |
||
177 | $type = new \DateTime($valueChild); |
||
178 | $this->{'addTo' . $key}($type); |
||
179 | } |
||
180 | } |
||
181 | else { |
||
182 | foreach($value AS $keyChild => $valueChild) { |
||
183 | $this->{'addTo' . $key}($valueChild); |
||
184 | } |
||
185 | } |
||
186 | } |
||
187 | else { |
||
188 | if ($classDetails->isCustomDefined){ |
||
189 | $type = new $classDetails->className; |
||
190 | $type->set($value); |
||
191 | $this->{'set' . $key}($type); |
||
192 | } |
||
193 | else if ($classDetails->className === 'DateTime' || $classDetails->className === 'Date' ) { |
||
194 | $type = new \DateTime($value); |
||
195 | $this->{'set' . $key}($type); |
||
196 | } |
||
197 | else { |
||
198 | $this->{'set' . $key}($value); |
||
199 | } |
||
200 | } |
||
201 | } |
||
202 | } |
||
203 | } |
||
204 | } |
||
205 | |||
208 |