Conditions | 22 |
Paths | 5790 |
Total Lines | 121 |
Code Lines | 55 |
Lines | 15 |
Ratio | 12.4 % |
Changes | 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 |
||
19 | function smarty_function_columnsort($params, $smarty) |
||
20 | { |
||
21 | $selected_class = null; |
||
22 | $current_id = 0; |
||
23 | $SMCS_id = 'default'; |
||
24 | //static $sort_asc_image = null; |
||
25 | //static $sort_desc_image = null; |
||
26 | $sort_asc_image = WWW_ROOT_THEMES_CORE . 'images/icons/asc.png'; |
||
27 | $sort_desc_image = WWW_ROOT_THEMES_CORE . 'images/icons/desc.png'; |
||
28 | |||
29 | View Code Duplication | if ($params['cid'] !== null) { |
|
30 | if ($SMCS_id !== $params['cid']) { |
||
31 | $current_id = 0; |
||
32 | } |
||
33 | |||
34 | $SMCS_id = $params['cid']; |
||
35 | } |
||
36 | |||
37 | // Retrieve the $_SESSION columnsort object. |
||
38 | if (!isset($_SESSION['SmartyColumnSort'][$SMCS_id])) { |
||
39 | trigger_error('columnsort: SmartyColumnSort.class.php needs to be included for columnsort to work.'); |
||
40 | |||
41 | return; |
||
42 | } |
||
43 | $columnsort = $_SESSION['SmartyColumnSort'][$SMCS_id]; |
||
44 | |||
45 | // HTML |
||
46 | if (!isset($params['html'])) { |
||
47 | trigger_error('columnsort: missing "html" parameter.'); |
||
48 | |||
49 | return; |
||
50 | } |
||
51 | |||
52 | /* |
||
53 | if ($params['translate'] != 0) { |
||
54 | $params['html'] = _($params['html']); |
||
55 | } */ |
||
56 | $html = $params['html']; |
||
57 | |||
58 | // selected_class |
||
59 | if ($params['selected_class'] !== null) { |
||
60 | $selected_class = $params['selected_class']; |
||
61 | } |
||
62 | |||
63 | // ID for column table |
||
64 | View Code Duplication | if ($params['id'] !== null) { |
|
65 | $id = $params['id']; |
||
66 | |||
67 | // Increase current id with 1 to prepare for next value |
||
68 | $current_id = $id + 1; |
||
69 | } else { |
||
70 | $id = $current_id++; |
||
71 | } |
||
72 | |||
73 | /* disabled |
||
74 | if (($params['asc_image'] !== null) && ($params['desc_image'] !== null)) { |
||
75 | // Set asc and desc sort images (will be placed after the sorted column) |
||
76 | $sort_asc_image = $params['asc_image']; |
||
77 | $sort_desc_image = $params['desc_image']; |
||
78 | } elseif ($params['asc_image']) || isset($params['desc_image'] !== null) { |
||
79 | trigger_error('columnsort: Both "asc_image" and "desc_image" needs to be present, or none of them.'); |
||
80 | } |
||
81 | */ |
||
82 | |||
83 | // alt for image |
||
84 | if ($params['img_alt'] !== null) { |
||
85 | $img_alt = $params['img_alt']; |
||
86 | } else { |
||
87 | $img_alt = ''; |
||
88 | } |
||
89 | |||
90 | // Get current sort order for current column id |
||
91 | $sort_order = _smarty_columnsort_sort_order($id, $columnsort['column_array'], $columnsort['default_sort'], $smarty); |
||
92 | |||
93 | if ($sort_order === false) { |
||
94 | trigger_error('columnsort: too few columns in translate table!'); |
||
95 | |||
96 | return; |
||
97 | } |
||
98 | |||
99 | // The column is selected if the get vars exists and is the current column OR |
||
100 | // if the get vars does not exist and the current column is default. |
||
101 | if ($columnsort['current_column'] !== null and $columnsort['current_column'] === $id) { |
||
102 | $selected = true; |
||
103 | } |
||
104 | |||
105 | // Reverse sort order for the output. |
||
106 | if ($columnsort['current_sort']) { |
||
107 | $sort_order = mb_strtolower($columnsort['current_sort']) === 'asc' ? 'desc' : 'asc'; |
||
108 | } elseif ($columnsort['current_column'] === null and $id === $columnsort['default_column']) { |
||
109 | $selected = true; |
||
110 | |||
111 | // Reverse sort order for the output. |
||
112 | $sort_order = $sort_order === 'asc' ? 'desc' : 'asc'; |
||
113 | } else { |
||
114 | $selected = false; |
||
115 | } |
||
116 | |||
117 | $columnsort['target_page'] .= (mb_strpos($columnsort['target_page'], '?') !== false ? '&' : '?'); |
||
118 | |||
119 | $url = $columnsort['target_page'] . $columnsort['column_var'] . "=$id&" . $columnsort['sort_var'] . "=$sort_order"; |
||
120 | |||
121 | // XML compliance patch by Vaccafoeda |
||
122 | $url = str_replace('&', '&', $url); |
||
123 | |||
124 | // If asc/desc image exists, append it. |
||
125 | if ($selected && $sort_asc_image !== null) { |
||
126 | $image_src = $sort_order === 'asc' ? $sort_desc_image : $sort_asc_image; |
||
127 | $image = " <img src=\"$image_src\" alt=\"$img_alt\" border=\"0\" />"; |
||
128 | } else { |
||
129 | $image = ''; |
||
130 | } |
||
131 | |||
132 | $class = $selected && $selected_class ? "class=\"$selected_class\"" : ''; |
||
133 | |||
134 | $result = '<a ' . $class . ' href="' . $url . '>' . |
||
135 | '<span style="width:100%;padding:0px;margin:0px;text-align:center;">' . |
||
136 | $html . ' ' . $image . '</span></a>'; |
||
137 | |||
138 | return $result; |
||
139 | } |
||
140 | |||
162 |
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.