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