| Conditions | 15 |
| Paths | 103 |
| Total Lines | 64 |
| Code Lines | 43 |
| 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 |
||
| 85 | function smarty_resource_db_tplinfo($tpl_name) |
||
| 86 | { |
||
| 87 | static $cache = array(); |
||
| 88 | global $xoopsConfig; |
||
| 89 | |||
| 90 | if (isset($cache[$tpl_name])) { |
||
| 91 | return $cache[$tpl_name]; |
||
| 92 | } |
||
| 93 | $tplset = $xoopsConfig['template_set']; |
||
| 94 | $theme = isset($xoopsConfig['theme_set']) ? $xoopsConfig['theme_set'] : 'default'; |
||
| 95 | /** @var \XoopsTplfileHandler $tplfile_handler */ |
||
| 96 | $tplfile_handler = xoops_getHandler('tplfile'); |
||
| 97 | // If we're not using the "default" template set, then get the templates from the DB |
||
| 98 | if ($tplset !== 'default') { |
||
| 99 | $tplobj = $tplfile_handler->find($tplset, null, null, null, $tpl_name, true); |
||
| 100 | if (count($tplobj)) { |
||
| 101 | return $cache[$tpl_name] = $tplobj[0]; |
||
| 102 | } |
||
| 103 | } |
||
| 104 | // If we're using the default tplset, get the template from the filesystem |
||
| 105 | $tplobj = $tplfile_handler->find('default', null, null, null, $tpl_name, true); |
||
| 106 | |||
| 107 | if (!count($tplobj)) { |
||
| 108 | return $cache[$tpl_name] = false; |
||
| 109 | } |
||
| 110 | $tplobj = $tplobj[0]; |
||
| 111 | $module = $tplobj->getVar('tpl_module', 'n'); |
||
| 112 | $type = $tplobj->getVar('tpl_type', 'n'); |
||
| 113 | // Construct template path |
||
| 114 | switch ($type) { |
||
| 115 | case 'block': |
||
| 116 | $directory = XOOPS_THEME_PATH; |
||
| 117 | $path = 'blocks/'; |
||
| 118 | if (class_exists('XoopsSystemCpanel', false)) { |
||
| 119 | $directory = XOOPS_ADMINTHEME_PATH; |
||
| 120 | $theme = isset($xoopsConfig['cpanel']) ? $xoopsConfig['cpanel'] : 'default'; |
||
| 121 | } |
||
| 122 | break; |
||
| 123 | case 'admin': |
||
| 124 | $theme = isset($xoopsConfig['cpanel']) ? $xoopsConfig['cpanel'] : 'default'; |
||
| 125 | $directory = XOOPS_ADMINTHEME_PATH; |
||
| 126 | $path = 'admin/'; |
||
| 127 | break; |
||
| 128 | default: |
||
| 129 | // at time of this comment, this only includes type 'module' |
||
| 130 | $directory = XOOPS_THEME_PATH; |
||
| 131 | $path = ''; |
||
| 132 | if (class_exists('XoopsSystemCpanel', false)) { |
||
| 133 | $directory = XOOPS_ADMINTHEME_PATH; |
||
| 134 | $theme = isset($xoopsConfig['cpanel']) ? $xoopsConfig['cpanel'] : 'default'; |
||
| 135 | } |
||
| 136 | break; |
||
| 137 | } |
||
| 138 | // First, check for an overloaded version within the theme folder |
||
| 139 | $filepath = $directory . "/{$theme}/modules/{$module}/{$path}{$tpl_name}"; |
||
| 140 | if (!file_exists($filepath)) { |
||
| 141 | // If no custom version exists, get the tpl from its default location |
||
| 142 | $filepath = XOOPS_ROOT_PATH . "/modules/{$module}/templates/{$path}{$tpl_name}"; |
||
| 143 | if (!file_exists($filepath)) { |
||
| 144 | return $cache[$tpl_name] = $tplobj; |
||
| 145 | } |
||
| 146 | } |
||
| 147 | |||
| 148 | return $cache[$tpl_name] = $filepath; |
||
| 149 | } |
||
| 150 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.