| Conditions | 17 |
| Paths | 15 |
| Total Lines | 60 |
| Code Lines | 54 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 89 | private static function dumpInternal($var, $level) |
||
| 90 | { |
||
| 91 | switch (gettype($var)) { |
||
| 92 | case 'boolean': |
||
| 93 | self::$_output .= $var ? 'true' : 'false'; |
||
| 94 | break; |
||
| 95 | case 'integer': |
||
| 96 | self::$_output .= "$var"; |
||
| 97 | break; |
||
| 98 | case 'double': |
||
| 99 | self::$_output .= "$var"; |
||
| 100 | break; |
||
| 101 | case 'string': |
||
| 102 | self::$_output .= "'" . addslashes($var) . "'"; |
||
| 103 | break; |
||
| 104 | case 'resource': |
||
| 105 | self::$_output .= '{resource}'; |
||
| 106 | break; |
||
| 107 | case 'NULL': |
||
| 108 | self::$_output .= "null"; |
||
| 109 | break; |
||
| 110 | case 'unknown type': |
||
| 111 | self::$_output .= '{unknown}'; |
||
| 112 | break; |
||
| 113 | case 'array': |
||
| 114 | if (self::$_depth <= $level) { |
||
| 115 | self::$_output .= '[...]'; |
||
| 116 | } elseif (empty($var)) { |
||
| 117 | self::$_output .= '[]'; |
||
| 118 | } else { |
||
| 119 | $keys = array_keys($var); |
||
| 120 | $spaces = str_repeat(' ', $level * 4); |
||
| 121 | self::$_output .= '['; |
||
| 122 | foreach ($keys as $key) { |
||
| 123 | self::$_output .= "\n" . $spaces . ' '; |
||
| 124 | self::dumpInternal($key, 0); |
||
| 125 | self::$_output .= ' => '; |
||
| 126 | self::dumpInternal($var[$key], $level + 1); |
||
| 127 | } |
||
| 128 | self::$_output .= "\n" . $spaces . ']'; |
||
| 129 | } |
||
| 130 | break; |
||
| 131 | case 'object': |
||
| 132 | if (false !== ($id = array_search($var, self::$_objects, true))) { |
||
| 133 | self::$_output .= get_class($var) . '#' . ($id + 1) . '(...)'; |
||
| 134 | } elseif (self::$_depth <= $level) { |
||
| 135 | self::$_output .= get_class($var) . '(...)'; |
||
| 136 | } else { |
||
| 137 | $id = array_push(self::$_objects, $var); |
||
| 138 | $className = get_class($var); |
||
| 139 | $spaces = str_repeat(' ', $level * 4); |
||
| 140 | self::$_output .= "$className#$id\n" . $spaces . '('; |
||
| 141 | foreach ((array)$var as $key => $value) { |
||
| 142 | $keyDisplay = strtr(trim($key), "\0", ':'); |
||
| 143 | self::$_output .= "\n" . $spaces . " [$keyDisplay] => "; |
||
| 144 | self::dumpInternal($value, $level + 1); |
||
| 145 | } |
||
| 146 | self::$_output .= "\n" . $spaces . ')'; |
||
| 147 | } |
||
| 148 | break; |
||
| 149 | } |
||
| 220 |