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