function.popup.php ➔ smarty_function_popup()   F
last analyzed

Complexity

Conditions 62
Paths 365

Size

Total Lines 94
Code Lines 79

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 3906
Metric Value
cc 62
eloc 79
nc 365
nop 2
dl 0
loc 94
ccs 0
cts 84
cp 0
crap 3906
rs 3.4722

How to fix   Long Method    Complexity   

Long Method

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:

1
<?php
2
/**
3
 * Smarty plugin
4
 * @package Smarty
5
 * @subpackage plugins
6
 */
7
8
9
/**
10
 * Smarty {popup} function plugin
11
 *
12
 * Type:     function<br>
13
 * Name:     popup<br>
14
 * Purpose:  make text pop up in windows via overlib
15
 * @link http://smarty.php.net/manual/en/language.function.popup.php {popup}
16
 *          (Smarty online manual)
17
 * @author   Monte Ohrt <monte at ohrt dot com>
18
 * @param array
19
 * @param Smarty
20
 * @return string
21
 */
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)) {
0 ignored issues
show
Bug introduced by
The variable $text seems to never exist, and therefore empty should always return true. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() 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.

Loading history...
Bug introduced by
The variable $inarray seems to never exist, and therefore isset should always return false. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() 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.

Loading history...
Bug introduced by
The variable $function seems to never exist, and therefore empty should always return true. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() 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.

Loading history...
102
        $smarty->trigger_error("overlib: attribute 'text' or 'inarray' or 'function' required");
103
        return false;
104
    }
105
106
    if (empty($trigger)) { $trigger = "onmouseover"; }
0 ignored issues
show
Bug introduced by
The variable $trigger seems only to be defined at a later point. As such the call to empty() seems to always evaluate to true.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
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
117
/* vim: set expandtab: */
118
119
?>
120