| Conditions | 21 |
| Paths | 140 |
| Total Lines | 80 |
| Code Lines | 56 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 109 | function wggithub_RewriteUrl($module, $array, $type = 'content') |
||
| 110 | {
|
||
| 111 | $comment = ''; |
||
| 112 | $helper = \XoopsModules\Wggithub\Helper::getInstance(); |
||
| 113 | //$readmesHandler = $helper->getHandler('readmes');
|
||
| 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 = wggithub_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 | break; |
||
| 142 | |||
| 143 | case 'rewrite': |
||
| 144 | if($topic_name) {
|
||
| 145 | $topic_name .= '/'; |
||
| 146 | } |
||
| 147 | $rewrite_base = xoops_getModuleOption('rewrite_mode', $module);
|
||
| 148 | $rewrite_ext = xoops_getModuleOption('rewrite_ext', $module);
|
||
| 149 | $module_name = ''; |
||
| 150 | if(xoops_getModuleOption('rewrite_name', $module)) {
|
||
| 151 | $module_name = xoops_getModuleOption('rewrite_name', $module) . '/';
|
||
| 152 | } |
||
| 153 | $page = $array['content_alias']; |
||
| 154 | $type .= '/'; |
||
| 155 | $id .= '/'; |
||
| 156 | if ('content/' === $type) {
|
||
| 157 | $type = ''; |
||
| 158 | } |
||
| 159 | if ('comment-edit/' === $type || 'comment-reply/' === $type || 'comment-delete/' === $type) {
|
||
| 160 | return \XOOPS_URL . $rewrite_base . $module_name . $type . $id . '/'; |
||
| 161 | } |
||
| 162 | |||
| 163 | return \XOOPS_URL . $rewrite_base . $module_name . $type . $topic_name . $id . $page . $rewrite_ext; |
||
| 164 | break; |
||
| 165 | |||
| 166 | case 'short': |
||
| 167 | if($topic_name) {
|
||
| 168 | $topic_name .= '/'; |
||
| 169 | } |
||
| 170 | $rewrite_base = xoops_getModuleOption('rewrite_mode', $module);
|
||
| 171 | $rewrite_ext = xoops_getModuleOption('rewrite_ext', $module);
|
||
| 172 | $module_name = ''; |
||
| 173 | if(xoops_getModuleOption('rewrite_name', $module)) {
|
||
| 174 | $module_name = xoops_getModuleOption('rewrite_name', $module) . '/';
|
||
| 175 | } |
||
| 176 | $page = $array['content_alias']; |
||
| 177 | $type .= '/'; |
||
| 178 | if ('content/' === $type) {
|
||
| 179 | $type = ''; |
||
| 180 | } |
||
| 181 | if ('comment-edit/' === $type || 'comment-reply/' === $type || 'comment-delete/' === $type) {
|
||
| 182 | return \XOOPS_URL . $rewrite_base . $module_name . $type . $id . '/'; |
||
| 183 | } |
||
| 184 | |||
| 185 | return \XOOPS_URL . $rewrite_base . $module_name . $type . $topic_name . $page . $rewrite_ext; |
||
| 186 | break; |
||
| 187 | } |
||
| 188 | return null; |
||
| 189 | } |
||
| 211 | } |