Conditions | 14 |
Paths | 73 |
Total Lines | 45 |
Code Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 1 |
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 |
||
197 | public function getClassesWithPropertyNames() |
||
198 | { |
||
199 | if ($this->hasBeenCalculated) { |
||
200 | return $this->calculatedOutput; |
||
201 | } |
||
202 | |||
203 | $result = $this->classes; |
||
204 | |||
205 | //Link the subClasses |
||
206 | foreach ($result as &$resultingClass) { |
||
207 | if (!empty($resultingClass->subClassOf)) { |
||
208 | foreach ($resultingClass->subClassOf as &$class) { |
||
209 | $class = $result[$class]; |
||
210 | } |
||
211 | } |
||
212 | } |
||
213 | |||
214 | //Add the properties |
||
215 | foreach ($this->properties as $propertyName => $propertyStructure) { |
||
216 | foreach ($propertyStructure['usedOnClass'] as $class) { |
||
217 | $result[$class]->properties[$propertyName] = ['name' => $propertyName, 'parent' => $class]; |
||
218 | } |
||
219 | } |
||
220 | |||
221 | //Flatten the properties for easy use. |
||
222 | foreach ($result as $resultingClass) { |
||
223 | if (!empty($resultingClass->subClassOf) && is_array($resultingClass->subClassOf)) { |
||
224 | foreach ($resultingClass->subClassOf as $stdClassObject) { |
||
225 | if (is_object($stdClassObject)) { |
||
226 | $resultingClass->properties = array_merge($resultingClass->properties, $stdClassObject->properties); |
||
227 | |||
228 | $next = $stdClassObject->subClassOf; |
||
229 | while (false !== $next && $object = array_pop($next)) { |
||
230 | $resultingClass->properties = array_merge($resultingClass->properties, $object->properties); |
||
231 | } |
||
232 | } |
||
233 | } |
||
234 | } |
||
235 | } |
||
236 | |||
237 | $this->hasBeenCalculated = true; |
||
238 | $this->calculatedOutput = $result; |
||
239 | |||
240 | return $result; |
||
241 | } |
||
242 | } |
||
243 |