| Conditions | 29 |
| Paths | 49 |
| Total Lines | 135 |
| Code Lines | 101 |
| 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 declare(strict_types=1); |
||
| 43 | function replace_links(array $matches): string |
||
| 44 | { |
||
| 45 | switch ($matches[5]) { |
||
| 46 | case 'index.php': |
||
| 47 | $add_to_url = ''; |
||
| 48 | $req_string = $matches[6]; |
||
| 49 | if (!empty($matches[6])) { |
||
| 50 | // replacing cat=x |
||
| 51 | if (preg_match('/cat=(\d+)/', (string) $matches[6], $mvars)) { |
||
| 52 | $add_to_url = 'c-' . $mvars[1] . '/' . forum_seo_cat((int)$mvars[1]) . ''; |
||
| 53 | $req_string = preg_replace('/cat=\d+/', '', (string) $matches[6]); |
||
| 54 | } else { |
||
| 55 | return $matches['0']; |
||
| 56 | } |
||
| 57 | } |
||
| 58 | break; |
||
| 59 | case 'viewpost.php': |
||
| 60 | $add_to_url = ''; |
||
| 61 | $req_string = $matches[6]; |
||
| 62 | if (!empty($matches[6])) { |
||
| 63 | // replacing status=x |
||
| 64 | if (preg_match('/status=([a-z]+)/', (string) $matches[6], $mvars)) { |
||
| 65 | $add_to_url = 'viewpost.php' . $matches[6]; |
||
| 66 | $req_string = preg_replace('/status=([a-z])+/', '', (string) $matches[6]); |
||
| 67 | } else { |
||
| 68 | return $matches['0']; |
||
| 69 | } |
||
| 70 | } else { |
||
| 71 | $add_to_url = 'viewpost.php' . $matches[6]; |
||
| 72 | } |
||
| 73 | break; |
||
| 74 | case 'rss.php': |
||
| 75 | $add_to_url = ''; |
||
| 76 | $req_string = $matches[6]; |
||
| 77 | if (!empty($matches[6])) { |
||
| 78 | // replacing c=x |
||
| 79 | if (preg_match('/c=(\d+)/', (string) $matches[6], $mvars)) { |
||
| 80 | $add_to_url = 'rc-'; |
||
| 81 | if ($mvars[1] > 0) { |
||
| 82 | $add_to_url .= $mvars[1] . '/' . forum_seo_cat((int)$mvars[1]) . ''; |
||
| 83 | } else { |
||
| 84 | $add_to_url .= $mvars[1] . '/rss.html'; |
||
| 85 | } |
||
| 86 | $req_string = preg_replace('/c=\d+/', '', (string) $matches[6]); |
||
| 87 | } elseif (preg_match('/f=(\d+)/', (string) $matches[6], $mvars)) { |
||
| 88 | $add_to_url = 'rf-'; |
||
| 89 | if ($mvars[1] > 0) { |
||
| 90 | $add_to_url .= $mvars[1] . '/' . forum_seo_forum((int)$mvars[1]) . ''; |
||
| 91 | } else { |
||
| 92 | $add_to_url .= $mvars[1] . '/rss.html'; |
||
| 93 | } |
||
| 94 | $req_string = preg_replace('/f=\d+/', '', (string) $matches[6]); |
||
| 95 | } else { |
||
| 96 | return $matches['0']; |
||
| 97 | } |
||
| 98 | //$add_to_url .= 'rss-feed.html'; |
||
| 99 | } |
||
| 100 | break; |
||
| 101 | case 'viewforum.php': |
||
| 102 | $add_to_url = ''; |
||
| 103 | $req_string = $matches[6]; |
||
| 104 | if (!empty($matches[6])) { |
||
| 105 | // replacing forum=x |
||
| 106 | if (preg_match('/forum=(\d+)/', (string) $matches[6], $mvars)) { |
||
| 107 | $add_to_url = 'f-' . $mvars[1] . '/' . forum_seo_forum((int)$mvars[1]) . ''; |
||
| 108 | $req_string = preg_replace('/forum=\d+/', '', (string) $matches[6]); |
||
| 109 | } else { |
||
| 110 | return $matches['0']; |
||
| 111 | } |
||
| 112 | } |
||
| 113 | break; |
||
| 114 | case 'viewtopic.php': |
||
| 115 | $add_to_url = ''; |
||
| 116 | $req_string = $matches[6]; |
||
| 117 | if (!empty($matches[6])) { |
||
| 118 | // replacing topic_id=x |
||
| 119 | if (preg_match('/topic_id=(\d+)/', (string) $matches[6], $mvars)) { |
||
| 120 | $add_to_url = 't-' . $mvars[1] . '/' . forum_seo_topic((int)$mvars[1]) . ''; |
||
| 121 | $req_string = preg_replace('/topic_id=\d+/', '', (string) $matches[6]); |
||
| 122 | } //replacing post_id=x |
||
| 123 | elseif (preg_match('/post_id=(\d+)/', (string) $matches[6], $mvars)) { |
||
| 124 | $add_to_url = 'p-' . $mvars[1] . '/' . forum_seo_post((int)$mvars[1]) . ''; |
||
| 125 | $req_string = preg_replace('/post_id=\d+/', '', (string) $matches[6]); |
||
| 126 | } else { |
||
| 127 | return $matches['0']; |
||
| 128 | } |
||
| 129 | } |
||
| 130 | break; |
||
| 131 | case 'print.php': |
||
| 132 | $add_to_url = ''; |
||
| 133 | $req_string = $matches[6]; |
||
| 134 | if (!empty($matches[6])) { |
||
| 135 | // replacing topic_id=x |
||
| 136 | if (preg_match('/topic_id=(\d+)/', (string) $matches[6], $mvars)) { |
||
| 137 | $add_to_url = 'pr-' . $mvars[1] . '/' . forum_seo_topic((int)$mvars[1]) . ''; |
||
| 138 | $req_string = preg_replace('/topic_id=\d+/', '', (string) $matches[6]); |
||
| 139 | } //replacing post_id=x |
||
| 140 | elseif (preg_match('/post_id=(\d+)/', (string) $matches[6], $mvars)) { |
||
| 141 | $add_to_url = 'pr-' . $mvars[1] . '/' . forum_seo_post((int)$mvars[1]) . ''; |
||
| 142 | $req_string = preg_replace('/post_id=\d+/', '', (string) $matches[6]); |
||
| 143 | } else { |
||
| 144 | return $matches['0']; |
||
| 145 | } |
||
| 146 | } |
||
| 147 | break; |
||
| 148 | case 'makepdf.php': |
||
| 149 | $add_to_url = ''; |
||
| 150 | $req_string = $matches[6]; |
||
| 151 | if (!empty($matches[6])) { |
||
| 152 | // replacing topic_id=x |
||
| 153 | if (preg_match('/topic_id=(\d+)/', (string) $matches[6], $mvars)) { |
||
| 154 | $add_to_url = 'pdf-' . $mvars[1] . '/' . forum_seo_topic((int)$mvars[1]) . ''; |
||
| 155 | $req_string = preg_replace('/topic_id=\d+/', '', (string) $matches[6]); |
||
| 156 | } //replacing post_id=x |
||
| 157 | elseif (preg_match('/post_id=(\d+)/', (string) $matches[6], $mvars)) { |
||
| 158 | $add_to_url = 'pdf-' . $mvars[1] . '/' . forum_seo_post((int)$mvars[1]) . ''; |
||
| 159 | $req_string = preg_replace('/post_id=\d+/', '', (string) $matches[6]); |
||
| 160 | } else { |
||
| 161 | return $matches['0']; |
||
| 162 | } |
||
| 163 | } |
||
| 164 | break; |
||
| 165 | default: |
||
| 166 | $req_string = $matches[6]; |
||
| 167 | $add_to_url = $matches[5]; |
||
| 168 | //if ($add_to_url === '') $add_to_url ='index.php'; |
||
| 169 | break; |
||
| 170 | } |
||
| 171 | if ('?' === $req_string) { |
||
| 172 | $req_string = ''; |
||
| 173 | } |
||
| 174 | $ret = '<' . $matches[1] . $matches[2] . $matches[3] . '=' . $matches[4] . XOOPS_URL . '/' . SEO_MODULE_NAME . '/' . $add_to_url . $req_string . $matches[7] . $matches[8] . '>'; |
||
| 175 | |||
| 176 | //$ret = '<'.$matches[1].$matches[2].$matches[3].'='.$matches[4].XOOPS_URL.'/'.REAL_MODULE_NAME.'/'.$add_to_url.$req_string.$matches[7].$matches[8].'>'; |
||
| 177 | return $ret; |
||
| 178 | } |
||
| 442 |