| Conditions | 21 |
| Paths | 140 |
| Total Lines | 77 |
| Code Lines | 53 |
| 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 |
||
| 109 | function wgfilemanager_RewriteUrl($module, $array, $type = 'content') |
||
| 110 | { |
||
| 111 | $comment = ''; |
||
| 112 | $helper = \XoopsModules\Wgfilemanager\Helper::getInstance(); |
||
| 113 | //$fileHandler = $helper->getHandler('file'); |
||
| 114 | $lenght_id = $helper->getConfig('lenght_id'); |
||
| 115 | $rewrite_url = $helper->getConfig('rewrite_url'); |
||
| 116 | |||
| 117 | if (0 != $lenght_id) { |
||
| 118 | $id = $array['content_id']; |
||
| 119 | while (\strlen($id) < $lenght_id) { |
||
| 120 | $id = '0' . $id; |
||
| 121 | } |
||
| 122 | } else { |
||
| 123 | $id = $array['content_id']; |
||
| 124 | } |
||
| 125 | |||
| 126 | if (isset($array['topic_alias']) && $array['topic_alias']) { |
||
| 127 | $topic_name = $array['topic_alias']; |
||
| 128 | } else { |
||
| 129 | $topic_name = wgfilemanager_Filter(xoops_getModuleOption('static_name', $module)); |
||
| 130 | } |
||
| 131 | |||
| 132 | switch ($rewrite_url) { |
||
| 133 | |||
| 134 | case 'none': |
||
| 135 | if($topic_name) { |
||
| 136 | $topic_name = 'topic=' . $topic_name . '&'; |
||
| 137 | } |
||
| 138 | $rewrite_base = '/modules/'; |
||
| 139 | $page = 'page=' . $array['content_alias']; |
||
| 140 | return \XOOPS_URL . $rewrite_base . $module . '/' . $type . '.php?' . $topic_name . 'id=' . $id . '&' . $page . $comment; |
||
| 141 | |||
| 142 | case 'rewrite': |
||
| 143 | if($topic_name) { |
||
| 144 | $topic_name .= '/'; |
||
| 145 | } |
||
| 146 | $rewrite_base = xoops_getModuleOption('rewrite_mode', $module); |
||
| 147 | $rewrite_ext = xoops_getModuleOption('rewrite_ext', $module); |
||
| 148 | $module_name = ''; |
||
| 149 | if(xoops_getModuleOption('rewrite_name', $module)) { |
||
| 150 | $module_name = xoops_getModuleOption('rewrite_name', $module) . '/'; |
||
| 151 | } |
||
| 152 | $page = $array['content_alias']; |
||
| 153 | $type .= '/'; |
||
| 154 | $id .= '/'; |
||
| 155 | if ('content/' === $type) { |
||
| 156 | $type = ''; |
||
| 157 | } |
||
| 158 | if ('comment-edit/' === $type || 'comment-reply/' === $type || 'comment-delete/' === $type) { |
||
| 159 | return \XOOPS_URL . $rewrite_base . $module_name . $type . $id . '/'; |
||
| 160 | } |
||
| 161 | |||
| 162 | return \XOOPS_URL . $rewrite_base . $module_name . $type . $topic_name . $id . $page . $rewrite_ext; |
||
| 163 | |||
| 164 | case 'short': |
||
| 165 | if($topic_name) { |
||
| 166 | $topic_name .= '/'; |
||
| 167 | } |
||
| 168 | $rewrite_base = xoops_getModuleOption('rewrite_mode', $module); |
||
| 169 | $rewrite_ext = xoops_getModuleOption('rewrite_ext', $module); |
||
| 170 | $module_name = ''; |
||
| 171 | if(xoops_getModuleOption('rewrite_name', $module)) { |
||
| 172 | $module_name = xoops_getModuleOption('rewrite_name', $module) . '/'; |
||
| 173 | } |
||
| 174 | $page = $array['content_alias']; |
||
| 175 | $type .= '/'; |
||
| 176 | if ('content/' === $type) { |
||
| 177 | $type = ''; |
||
| 178 | } |
||
| 179 | if ('comment-edit/' === $type || 'comment-reply/' === $type || 'comment-delete/' === $type) { |
||
| 180 | return \XOOPS_URL . $rewrite_base . $module_name . $type . $id . '/'; |
||
| 181 | } |
||
| 182 | |||
| 183 | return \XOOPS_URL . $rewrite_base . $module_name . $type . $topic_name . $page . $rewrite_ext; |
||
| 184 | } |
||
| 185 | return null; |
||
| 186 | } |
||
| 208 | } |