| 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 |
||
| 42 | public function set($data) |
||
| 43 | { |
||
| 44 | if(is_array($data) || is_object($data)) { |
||
| 45 | $mapper = \net\authorize\util\Mapper::Instance(); |
||
| 46 | foreach($data AS $key => $value) { |
||
| 47 | $classDetails = $mapper->getClass(get_class() , $key); |
||
| 48 | |||
| 49 | if($classDetails !== NULL ) { |
||
| 50 | if ($classDetails->isArray) { |
||
| 51 | if ($classDetails->isCustomDefined) { |
||
| 52 | foreach($value AS $keyChild => $valueChild) { |
||
| 53 | $type = new $classDetails->className; |
||
| 54 | $type->set($valueChild); |
||
| 55 | $this->{'addTo' . $key}($type); |
||
| 56 | } |
||
| 57 | } |
||
| 58 | else if ($classDetails->className === 'DateTime' || $classDetails->className === 'Date' ) { |
||
| 59 | foreach($value AS $keyChild => $valueChild) { |
||
| 60 | $type = new \DateTime($valueChild); |
||
| 61 | $this->{'addTo' . $key}($type); |
||
| 62 | } |
||
| 63 | } |
||
| 64 | else { |
||
| 65 | foreach($value AS $keyChild => $valueChild) { |
||
| 66 | $this->{'addTo' . $key}($valueChild); |
||
| 67 | } |
||
| 68 | } |
||
| 69 | } |
||
| 70 | else { |
||
| 71 | if ($classDetails->isCustomDefined){ |
||
| 72 | $type = new $classDetails->className; |
||
| 73 | $type->set($value); |
||
| 74 | $this->{'set' . $key}($type); |
||
| 75 | } |
||
| 76 | else if ($classDetails->className === 'DateTime' || $classDetails->className === 'Date' ) { |
||
| 77 | $type = new \DateTime($value); |
||
| 78 | $this->{'set' . $key}($type); |
||
| 79 | } |
||
| 80 | else { |
||
| 81 | $this->{'set' . $key}($value); |
||
| 82 | } |
||
| 83 | } |
||
| 84 | } |
||
| 85 | } |
||
| 86 | } |
||
| 87 | } |
||
| 88 | |||
| 91 |