Complex classes like urls often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use urls, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
12 | abstract class urls |
||
13 | { |
||
14 | /** @var \phpbb\auth\auth */ |
||
15 | protected $auth; |
||
16 | |||
17 | /** @var \phpbb\config\db */ |
||
18 | protected $config; |
||
19 | |||
20 | /** @var \phpbb\user */ |
||
21 | protected $user; |
||
22 | |||
23 | /** @var string */ |
||
24 | protected $phpbb_root_path; |
||
25 | |||
26 | /** @var string */ |
||
27 | protected $php_ext; |
||
28 | |||
29 | /** |
||
30 | * Constructor |
||
31 | * |
||
32 | * @param \phpbb\auth\auth $auth Auth object |
||
33 | * @param \phpbb\config\db $config Config object |
||
34 | * @param \phpbb\user $user User object |
||
35 | * @param string $phpbb_root_path Path to the phpbb includes directory. |
||
36 | * @param string $php_ext php file extension |
||
37 | */ |
||
38 | public function __construct(\phpbb\auth\auth $auth, \phpbb\config\db $config, \phpbb\user $user, $phpbb_root_path, $php_ext) |
||
46 | |||
47 | /** |
||
48 | * @param array $post_data |
||
49 | * @param array $topic_data |
||
50 | * @param string $cp_mode |
||
51 | * @return string |
||
52 | */ |
||
53 | public function get_edit_url(array $post_data, array $topic_data, $cp_mode = '') |
||
58 | |||
59 | /** |
||
60 | * @param array $post_data |
||
61 | * @param array $topic_data |
||
62 | * @param string $cp_mode |
||
63 | * @return string |
||
64 | */ |
||
65 | public function get_delete_url(array $post_data, array $topic_data, $cp_mode = '') |
||
70 | |||
71 | /** |
||
72 | * @param array $post_data |
||
73 | * @param array $topic_data |
||
74 | * @return string |
||
75 | */ |
||
76 | public function get_quote_url(array $post_data, array $topic_data) |
||
80 | |||
81 | /** |
||
82 | * @param array $topic_data |
||
83 | * @return string |
||
84 | */ |
||
85 | public function get_viewtopic_url(array $topic_data) |
||
89 | |||
90 | /** |
||
91 | * @param array $topic_data |
||
92 | * @return string |
||
93 | */ |
||
94 | public function get_print_topic_url(array $topic_data) |
||
98 | |||
99 | /** |
||
100 | * @param array $topic_data |
||
101 | * @return string |
||
102 | */ |
||
103 | public function get_email_topic_url(array $topic_data) |
||
107 | |||
108 | /** |
||
109 | * @param int $forum_id |
||
110 | * @param string $username |
||
111 | * @return string |
||
112 | */ |
||
113 | public function get_search_users_posts_url($forum_id, $username) |
||
117 | |||
118 | /** |
||
119 | * @param array $post_data |
||
120 | * @return string |
||
121 | */ |
||
122 | public function get_info_url(array $post_data) |
||
127 | |||
128 | /** |
||
129 | * @param array $post_data |
||
130 | * @param string $viewtopic_url |
||
131 | * @return string |
||
132 | */ |
||
133 | public function get_approve_url(array $post_data, $viewtopic_url) |
||
137 | |||
138 | /** |
||
139 | * @param array $post_data |
||
140 | * @param array $topic_data |
||
141 | * @return string |
||
142 | */ |
||
143 | public function get_mcp_edit_url(array $post_data, array $topic_data) |
||
147 | |||
148 | /** |
||
149 | * @param array $post_data |
||
150 | * @return string |
||
151 | * |
||
152 | public function get_mcp_approve_url(array $post_data) |
||
153 | { |
||
154 | return append_sid("{$this->phpbb_root_path}mcp.$this->php_ext", 'i=queue&mode=approve_details&f=' . $post_data['forum_id'] . '&p=' . $post_data['post_id'], true, $this->user->session_id); |
||
155 | } |
||
156 | */ |
||
157 | |||
158 | /** |
||
159 | * @param array $post_data |
||
160 | * @return string |
||
161 | */ |
||
162 | public function get_mcp_report_url(array $post_data) |
||
166 | |||
167 | /** |
||
168 | * @param array $post_data |
||
169 | * @param array $topic_data |
||
170 | * @return string |
||
171 | */ |
||
172 | public function get_mcp_restore_url(array $post_data, array $topic_data) |
||
176 | |||
177 | /** |
||
178 | * @param array $post_data |
||
179 | * @return string |
||
180 | */ |
||
181 | public function get_notes_url(array $post_data) |
||
185 | |||
186 | /** |
||
187 | * @param array $post_data |
||
188 | * @return string |
||
189 | */ |
||
190 | public function get_warning_url(array $post_data) |
||
194 | |||
195 | /** |
||
196 | * @param int $topic_id |
||
197 | * @return string |
||
198 | */ |
||
199 | public function get_mcp_queue_url($topic_id) |
||
203 | |||
204 | /** |
||
205 | * @param string $content_type |
||
206 | * @param int $topic_id |
||
207 | * @return string |
||
208 | */ |
||
209 | public function get_mcp_review_url($content_type, $topic_id) |
||
213 | |||
214 | /** |
||
215 | * @return string |
||
216 | */ |
||
217 | public function get_mcp_url($forum_id, $topic_id) |
||
233 | |||
234 | /** |
||
235 | * @param array $post_data |
||
236 | * @param array $topic_data |
||
237 | * @param string $cp_mode |
||
238 | * @return string |
||
239 | */ |
||
240 | protected function get_cp_param(array $post_data, array $topic_data, $cp_mode) |
||
249 | } |
||
250 |