| Conditions | 20 | 
| Paths | 17 | 
| Total Lines | 68 | 
| Code Lines | 60 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 2 | ||
| Bugs | 0 | Features | 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 | ||
| 59 | private static function dumpInternal($var, $level) | ||
| 60 | 	{ | ||
| 61 | 		switch (gettype($var)) { | ||
| 62 | case 'boolean': | ||
| 63 | self::$_output .= $var ? 'true' : 'false'; | ||
| 64 | break; | ||
| 65 | case 'integer': | ||
| 66 | self::$_output .= "$var"; | ||
| 67 | break; | ||
| 68 | case 'double': | ||
| 69 | self::$_output .= "$var"; | ||
| 70 | break; | ||
| 71 | case 'string': | ||
| 72 | self::$_output .= "'" . addslashes($var) . "'"; | ||
| 73 | break; | ||
| 74 | case 'resource': | ||
| 75 | 				self::$_output .= '{resource}'; | ||
| 76 | break; | ||
| 77 | case 'NULL': | ||
| 78 | self::$_output .= "null"; | ||
| 79 | break; | ||
| 80 | case 'unknown type': | ||
| 81 | 				self::$_output .= '{unknown}'; | ||
| 82 | break; | ||
| 83 | case 'array': | ||
| 84 | 				if (self::$_depth <= $level) { | ||
| 85 | self::$_output .= 'array(...)'; | ||
| 86 | 				} elseif (empty($var)) { | ||
| 87 | self::$_output .= 'array()'; | ||
| 88 | 				} else { | ||
| 89 | $keys = array_keys($var); | ||
| 90 | 					$spaces = str_repeat(' ', $level * 4); | ||
| 91 | 					self::$_output .= "array\n" . $spaces . '('; | ||
| 92 | 					foreach ($keys as $key) { | ||
| 93 | self::$_output .= "\n" . $spaces . ' '; | ||
| 94 | self::dumpInternal($key, 0); | ||
| 95 | self::$_output .= ' => '; | ||
| 96 | self::dumpInternal($var[$key], $level + 1); | ||
| 97 | } | ||
| 98 | self::$_output .= "\n" . $spaces . ')'; | ||
| 99 | } | ||
| 100 | break; | ||
| 101 | case 'object': | ||
| 102 | 				if (($id = array_search($var, self::$_objects, true)) !== false) { | ||
| 103 | self::$_output .= $var::class . '#' . ($id + 1) . '(...)'; | ||
| 104 | 				} elseif (self::$_depth <= $level) { | ||
| 105 | self::$_output .= $var::class . '(...)'; | ||
| 106 | 				} else { | ||
| 107 | $id = array_push(self::$_objects, $var); | ||
| 108 | $className = $var::class; | ||
| 109 | 					$spaces = str_repeat(' ', $level * 4); | ||
| 110 | 					self::$_output .= "$className#$id\n" . $spaces . '('; | ||
| 111 | 					if ('__PHP_Incomplete_Class' !== get_class($var) && method_exists($var, '__debugInfo')) { | ||
| 112 | $members = $var->__debugInfo(); | ||
| 113 | 						if (!is_array($members)) { | ||
| 114 | 							throw new TInvalidDataValueException('vardumper_not_array'); | ||
| 115 | } | ||
| 116 | 					} else { | ||
| 117 | $members = (array) $var; | ||
| 118 | } | ||
| 119 | 					foreach ($members as $key => $value) { | ||
| 120 | $keyDisplay = strtr(trim($key), ["\0" => ':']); | ||
| 121 | self::$_output .= "\n" . $spaces . " [$keyDisplay] => "; | ||
| 122 | self::$_output .= self::dumpInternal($value, $level + 1); | ||
| 123 | } | ||
| 124 | self::$_output .= "\n" . $spaces . ')'; | ||
| 125 | } | ||
| 126 | break; | ||
| 127 | } | ||
| 130 |