| 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 |
||
| 94 | public function set($data) |
||
| 95 | { |
||
| 96 | if(is_array($data) || is_object($data)) { |
||
| 97 | $mapper = \net\authorize\util\Mapper::Instance(); |
||
| 98 | foreach($data AS $key => $value) { |
||
| 99 | $classDetails = $mapper->getClass(get_class() , $key); |
||
| 100 | |||
| 101 | if($classDetails !== NULL ) { |
||
| 102 | if ($classDetails->isArray) { |
||
| 103 | if ($classDetails->isCustomDefined) { |
||
| 104 | foreach($value AS $keyChild => $valueChild) { |
||
| 105 | $type = new $classDetails->className; |
||
| 106 | $type->set($valueChild); |
||
| 107 | $this->{'addTo' . $key}($type); |
||
| 108 | } |
||
| 109 | } |
||
| 110 | else if ($classDetails->className === 'DateTime' || $classDetails->className === 'Date' ) { |
||
| 111 | foreach($value AS $keyChild => $valueChild) { |
||
| 112 | $type = new \DateTime($valueChild); |
||
| 113 | $this->{'addTo' . $key}($type); |
||
| 114 | } |
||
| 115 | } |
||
| 116 | else { |
||
| 117 | foreach($value AS $keyChild => $valueChild) { |
||
| 118 | $this->{'addTo' . $key}($valueChild); |
||
| 119 | } |
||
| 120 | } |
||
| 121 | } |
||
| 122 | else { |
||
| 123 | if ($classDetails->isCustomDefined){ |
||
| 124 | $type = new $classDetails->className; |
||
| 125 | $type->set($value); |
||
| 126 | $this->{'set' . $key}($type); |
||
| 127 | } |
||
| 128 | else if ($classDetails->className === 'DateTime' || $classDetails->className === 'Date' ) { |
||
| 129 | $type = new \DateTime($value); |
||
| 130 | $this->{'set' . $key}($type); |
||
| 131 | } |
||
| 132 | else { |
||
| 133 | $this->{'set' . $key}($value); |
||
| 134 | } |
||
| 135 | } |
||
| 136 | } |
||
| 137 | } |
||
| 138 | } |
||
| 139 | } |
||
| 140 | |||
| 143 |