| Conditions | 14 | 
| Paths | 96 | 
| Total Lines | 33 | 
| Code Lines | 20 | 
| Lines | 15 | 
| Ratio | 45.45 % | 
| 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 | ||
| 16 | function data_views_object_to_xml($data, $name = "", $n = 0) { | ||
| 17 | $classname = ($name == "" ? get_class($data) : $name); | ||
| 18 | |||
| 19 | $vars = method_exists($data, "export") ? get_object_vars($data->export()) : get_object_vars($data); | ||
| 20 | |||
| 21 | $output = ""; | ||
| 22 | |||
| 23 | 	if (($n == 0) || ( is_object($data) && !($data instanceof \stdClass))) { | ||
| 24 | $output = "<$classname>"; | ||
| 25 | } | ||
| 26 | |||
| 27 | View Code Duplication | 	foreach ($vars as $key => $value) { | |
| 28 | $output .= "<$key type=\"" . gettype($value) . "\">"; | ||
| 29 | |||
| 30 | 		if (is_object($value)) { | ||
| 31 | $output .= data_views_object_to_xml($value, $key, $n + 1); | ||
| 32 | 		} else if (is_array($value)) { | ||
| 33 | $output .= data_views_array_to_xml($value, $n + 1); | ||
| 34 | 		} else if (gettype($value) == "boolean") { | ||
| 35 | $output .= $value ? "true" : "false"; | ||
| 36 | 		} else { | ||
| 37 | $output .= htmlspecialchars($value, ENT_NOQUOTES, 'UTF-8'); | ||
| 38 | } | ||
| 39 | |||
| 40 | $output .= "</$key>\n"; | ||
| 41 | } | ||
| 42 | |||
| 43 | 	if (($n == 0) || (is_object($data) && !($data instanceof \stdClass))) { | ||
| 44 | $output .= "</$classname>\n"; | ||
| 45 | } | ||
| 46 | |||
| 47 | return $output; | ||
| 48 | } | ||
| 49 | |||
| 94 |