| Conditions | 12 |
| Paths | 16 |
| Total Lines | 24 |
| Code Lines | 20 |
| 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 |
||
| 34 | function debug($var, $varName = "", $die = FALSE) |
||
| 35 | { |
||
| 36 | $html = '<style>*{margin: 0} body{background: rgb(36,36,36); padding: 5px;}</style>'; |
||
| 37 | $html .= '<pre style="padding: 10px; margin: 5px; display: block; background: rgb(41,41,41); color: white; border-radius: 5px;">'; |
||
| 38 | if(is_null($var)) { |
||
| 39 | if($varName) $html .= $varName . ' ==> <b>NULL</b>'; |
||
| 40 | } else { |
||
| 41 | $html .= print_r('(' . gettype($var) . ') ', TRUE); |
||
| 42 | if($varName) $html .= $varName . ' ==> '; |
||
| 43 | if("boolean" === gettype($var)) { |
||
| 44 | $html .= print_r($var ? "TRUE" : "FALSE", TRUE); |
||
| 45 | } else if((is_array($var) && !empty($var)) || (!is_array($var)) || ($var === 0)) { |
||
| 46 | $html .= print_r($var, TRUE); |
||
| 47 | } else { |
||
| 48 | $html .= 'empty'; |
||
| 49 | } |
||
| 50 | } |
||
| 51 | $html .= '</pre>'; |
||
| 52 | ob_start(); |
||
| 53 | echo $html; |
||
| 54 | ob_flush(); |
||
| 55 | ob_end_clean(); |
||
| 56 | if ($die || $var === "die") { |
||
| 57 | die; |
||
| 58 | } |
||
| 93 | } |