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