| Conditions | 62 |
| Paths | 365 |
| Total Lines | 94 |
| Code Lines | 79 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 3906 |
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 |
||
| 22 | function smarty_function_popup($params, &$smarty) |
||
| 23 | { |
||
| 24 | $append = ''; |
||
| 25 | foreach ($params as $_key=>$_value) { |
||
| 26 | switch ($_key) { |
||
| 27 | case 'text': |
||
| 28 | case 'trigger': |
||
| 29 | case 'function': |
||
| 30 | case 'inarray': |
||
| 31 | $$_key = (string)$_value; |
||
| 32 | if ($_key == 'function' || $_key == 'inarray') |
||
| 33 | $append .= ',' . strtoupper($_key) . ",'$_value'"; |
||
| 34 | break; |
||
| 35 | |||
| 36 | case 'caption': |
||
| 37 | case 'closetext': |
||
| 38 | case 'status': |
||
| 39 | $append .= ',' . strtoupper($_key) . ",'" . str_replace("'","\'",$_value) . "'"; |
||
| 40 | break; |
||
| 41 | |||
| 42 | case 'fgcolor': |
||
| 43 | case 'bgcolor': |
||
| 44 | case 'textcolor': |
||
| 45 | case 'capcolor': |
||
| 46 | case 'closecolor': |
||
| 47 | case 'textfont': |
||
| 48 | case 'captionfont': |
||
| 49 | case 'closefont': |
||
| 50 | case 'fgbackground': |
||
| 51 | case 'bgbackground': |
||
| 52 | case 'caparray': |
||
| 53 | case 'capicon': |
||
| 54 | case 'background': |
||
| 55 | case 'frame': |
||
| 56 | $append .= ',' . strtoupper($_key) . ",'$_value'"; |
||
| 57 | break; |
||
| 58 | |||
| 59 | case 'textsize': |
||
| 60 | case 'captionsize': |
||
| 61 | case 'closesize': |
||
| 62 | case 'width': |
||
| 63 | case 'height': |
||
| 64 | case 'border': |
||
| 65 | case 'offsetx': |
||
| 66 | case 'offsety': |
||
| 67 | case 'snapx': |
||
| 68 | case 'snapy': |
||
| 69 | case 'fixx': |
||
| 70 | case 'fixy': |
||
| 71 | case 'padx': |
||
| 72 | case 'pady': |
||
| 73 | case 'timeout': |
||
| 74 | case 'delay': |
||
| 75 | $append .= ',' . strtoupper($_key) . ",$_value"; |
||
| 76 | break; |
||
| 77 | |||
| 78 | case 'sticky': |
||
| 79 | case 'left': |
||
| 80 | case 'right': |
||
| 81 | case 'center': |
||
| 82 | case 'above': |
||
| 83 | case 'below': |
||
| 84 | case 'noclose': |
||
| 85 | case 'autostatus': |
||
| 86 | case 'autostatuscap': |
||
| 87 | case 'fullhtml': |
||
| 88 | case 'hauto': |
||
| 89 | case 'vauto': |
||
| 90 | case 'mouseoff': |
||
| 91 | case 'followmouse': |
||
| 92 | case 'closeclick': |
||
| 93 | if ($_value) $append .= ',' . strtoupper($_key); |
||
| 94 | break; |
||
| 95 | |||
| 96 | default: |
||
| 97 | $smarty->trigger_error("[popup] unknown parameter $_key", E_USER_WARNING); |
||
| 98 | } |
||
| 99 | } |
||
| 100 | |||
| 101 | if (empty($text) && !isset($inarray) && empty($function)) { |
||
| 102 | $smarty->trigger_error("overlib: attribute 'text' or 'inarray' or 'function' required"); |
||
| 103 | return false; |
||
| 104 | } |
||
| 105 | |||
| 106 | if (empty($trigger)) { $trigger = "onmouseover"; } |
||
| 107 | |||
| 108 | $retval = $trigger . '="return overlib(\''.preg_replace(array("!'!","![\r\n]!"),array("\'",'\r'),$text).'\''; |
||
| 109 | $retval .= $append . ');"'; |
||
| 110 | if ($trigger == 'onmouseover') |
||
| 111 | $retval .= ' onmouseout="nd();"'; |
||
| 112 | |||
| 113 | |||
| 114 | return $retval; |
||
| 115 | } |
||
| 116 | |||
| 120 |
This check looks for calls to
isset(...)orempty()on variables that are yet undefined. These calls will always produce the same result and can be removed.This is most likely caused by the renaming of a variable or the removal of a function/method parameter.