| 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 |
||
| 74 | public function set($data) |
||
| 75 | { |
||
| 76 | if(is_array($data) || is_object($data)) { |
||
| 77 | $mapper = \net\authorize\util\Mapper::Instance(); |
||
| 78 | foreach($data AS $key => $value) { |
||
| 79 | $classDetails = $mapper->getClass(get_class() , $key); |
||
| 80 | |||
| 81 | if($classDetails !== NULL ) { |
||
| 82 | if ($classDetails->isArray) { |
||
| 83 | if ($classDetails->isCustomDefined) { |
||
| 84 | foreach($value AS $keyChild => $valueChild) { |
||
| 85 | $type = new $classDetails->className; |
||
| 86 | $type->set($valueChild); |
||
| 87 | $this->{'addTo' . $key}($type); |
||
| 88 | } |
||
| 89 | } |
||
| 90 | else if ($classDetails->className === 'DateTime' || $classDetails->className === 'Date' ) { |
||
| 91 | foreach($value AS $keyChild => $valueChild) { |
||
| 92 | $type = new \DateTime($valueChild); |
||
| 93 | $this->{'addTo' . $key}($type); |
||
| 94 | } |
||
| 95 | } |
||
| 96 | else { |
||
| 97 | foreach($value AS $keyChild => $valueChild) { |
||
| 98 | $this->{'addTo' . $key}($valueChild); |
||
| 99 | } |
||
| 100 | } |
||
| 101 | } |
||
| 102 | else { |
||
| 103 | if ($classDetails->isCustomDefined){ |
||
| 104 | $type = new $classDetails->className; |
||
| 105 | $type->set($value); |
||
| 106 | $this->{'set' . $key}($type); |
||
| 107 | } |
||
| 108 | else if ($classDetails->className === 'DateTime' || $classDetails->className === 'Date' ) { |
||
| 109 | $type = new \DateTime($value); |
||
| 110 | $this->{'set' . $key}($type); |
||
| 111 | } |
||
| 112 | else { |
||
| 113 | $this->{'set' . $key}($value); |
||
| 114 | } |
||
| 115 | } |
||
| 116 | } |
||
| 117 | } |
||
| 118 | } |
||
| 119 | } |
||
| 120 | |||
| 123 |