| 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 |
||
| 13 | public function set($data) |
||
| 14 | { |
||
| 15 | if(is_array($data) || is_object($data)) { |
||
| 16 | $mapper = \net\authorize\util\Mapper::Instance(); |
||
| 17 | foreach($data AS $key => $value) { |
||
| 18 | $classDetails = $mapper->getClass(get_class() , $key); |
||
| 19 | |||
| 20 | if($classDetails !== NULL ) { |
||
| 21 | if ($classDetails->isArray) { |
||
| 22 | if ($classDetails->isCustomDefined) { |
||
| 23 | foreach($value AS $keyChild => $valueChild) { |
||
| 24 | $type = new $classDetails->className; |
||
| 25 | $type->set($valueChild); |
||
| 26 | $this->{'addTo' . $key}($type); |
||
| 27 | } |
||
| 28 | } |
||
| 29 | else if ($classDetails->className === 'DateTime' || $classDetails->className === 'Date' ) { |
||
| 30 | foreach($value AS $keyChild => $valueChild) { |
||
| 31 | $type = new \DateTime($valueChild); |
||
| 32 | $this->{'addTo' . $key}($type); |
||
| 33 | } |
||
| 34 | } |
||
| 35 | else { |
||
| 36 | foreach($value AS $keyChild => $valueChild) { |
||
| 37 | $this->{'addTo' . $key}($valueChild); |
||
| 38 | } |
||
| 39 | } |
||
| 40 | } |
||
| 41 | else { |
||
| 42 | if ($classDetails->isCustomDefined){ |
||
| 43 | $type = new $classDetails->className; |
||
| 44 | $type->set($value); |
||
| 45 | $this->{'set' . $key}($type); |
||
| 46 | } |
||
| 47 | else if ($classDetails->className === 'DateTime' || $classDetails->className === 'Date' ) { |
||
| 48 | $type = new \DateTime($value); |
||
| 49 | $this->{'set' . $key}($type); |
||
| 50 | } |
||
| 51 | else { |
||
| 52 | $this->{'set' . $key}($value); |
||
| 53 | } |
||
| 54 | } |
||
| 55 | } |
||
| 56 | } |
||
| 57 | } |
||
| 58 | } |
||
| 59 | |||
| 62 |