| Conditions | 21 |
| Paths | 140 |
| Total Lines | 80 |
| Code Lines | 57 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 1 |
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 |
||
| 136 | function mymodule3_RewriteUrl($module, $array, $type = 'content') |
||
| 137 | { |
||
| 138 | $comment = ''; |
||
| 139 | $helper = \XoopsModules\Mymodule3\Helper::getInstance(); |
||
| 140 | $testfieldsHandler = $helper->getHandler('testfields'); |
||
| 141 | $lenght_id = $helper->getConfig('lenght_id'); |
||
| 142 | $rewrite_url = $helper->getConfig('rewrite_url'); |
||
| 143 | |||
| 144 | if ($lenght_id != 0) { |
||
| 145 | $id = $array['content_id']; |
||
| 146 | while (strlen($id) < $lenght_id) { |
||
| 147 | $id = '0' . $id; |
||
| 148 | } |
||
| 149 | } else { |
||
| 150 | $id = $array['content_id']; |
||
| 151 | } |
||
| 152 | |||
| 153 | if (isset($array['topic_alias']) && $array['topic_alias']) { |
||
| 154 | $topic_name = $array['topic_alias']; |
||
| 155 | } else { |
||
| 156 | $topic_name = mymodule3_Filter(xoops_getModuleOption('static_name', $module)); |
||
| 157 | } |
||
| 158 | |||
| 159 | switch ($rewrite_url) { |
||
| 160 | |||
| 161 | case 'none': |
||
| 162 | if($topic_name) { |
||
| 163 | $topic_name = 'topic=' . $topic_name . '&'; |
||
| 164 | } |
||
| 165 | $rewrite_base = '/modules/'; |
||
| 166 | $page = 'page=' . $array['content_alias']; |
||
| 167 | return XOOPS_URL . $rewrite_base . $module . '/' . $type . '.php?' . $topic_name . 'id=' . $id . '&' . $page . $comment; |
||
| 168 | break; |
||
| 169 | |||
| 170 | case 'rewrite': |
||
| 171 | if($topic_name) { |
||
| 172 | $topic_name .= '/'; |
||
| 173 | } |
||
| 174 | $rewrite_base = xoops_getModuleOption('rewrite_mode', $module); |
||
| 175 | $rewrite_ext = xoops_getModuleOption('rewrite_ext', $module); |
||
| 176 | $module_name = ''; |
||
| 177 | if(xoops_getModuleOption('rewrite_name', $module)) { |
||
| 178 | $module_name = xoops_getModuleOption('rewrite_name', $module) . '/'; |
||
| 179 | } |
||
| 180 | $page = $array['content_alias']; |
||
| 181 | $type .= '/'; |
||
| 182 | $id .= '/'; |
||
| 183 | if ($type === 'content/') { |
||
| 184 | $type = ''; |
||
| 185 | } |
||
| 186 | if ($type === 'comment-edit/' || $type === 'comment-reply/' || $type === 'comment-delete/') { |
||
| 187 | return XOOPS_URL . $rewrite_base . $module_name . $type . $id . '/'; |
||
| 188 | } |
||
| 189 | |||
| 190 | return XOOPS_URL . $rewrite_base . $module_name . $type . $topic_name . $id . $page . $rewrite_ext; |
||
| 191 | break; |
||
| 192 | |||
| 193 | case 'short': |
||
| 194 | if($topic_name) { |
||
| 195 | $topic_name .= '/'; |
||
| 196 | } |
||
| 197 | $rewrite_base = xoops_getModuleOption('rewrite_mode', $module); |
||
| 198 | $rewrite_ext = xoops_getModuleOption('rewrite_ext', $module); |
||
| 199 | $module_name = ''; |
||
| 200 | if(xoops_getModuleOption('rewrite_name', $module)) { |
||
| 201 | $module_name = xoops_getModuleOption('rewrite_name', $module) . '/'; |
||
| 202 | } |
||
| 203 | $page = $array['content_alias']; |
||
| 204 | $type .= '/'; |
||
| 205 | if ($type === 'content/') { |
||
| 206 | $type = ''; |
||
| 207 | } |
||
| 208 | if ($type === 'comment-edit/' || $type === 'comment-reply/' || $type === 'comment-delete/') { |
||
| 209 | return XOOPS_URL . $rewrite_base . $module_name . $type . $id . '/'; |
||
| 210 | } |
||
| 211 | |||
| 212 | return XOOPS_URL . $rewrite_base . $module_name . $type . $topic_name . $page . $rewrite_ext; |
||
| 213 | break; |
||
| 214 | } |
||
| 215 | return null; |
||
| 216 | } |
||
| 239 | } |