Complex classes like contacts 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 contacts, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
12 | abstract class contacts |
||
13 | { |
||
14 | /** @var \phpbb\auth\auth */ |
||
15 | protected $auth; |
||
16 | |||
17 | /** @var \phpbb\config\config */ |
||
18 | protected $config; |
||
19 | |||
20 | /** @var \phpbb\language\language */ |
||
21 | protected $translator; |
||
22 | |||
23 | /** @var \phpbb\user */ |
||
24 | protected $user; |
||
25 | |||
26 | /** @var string */ |
||
27 | protected $phpbb_root_path; |
||
28 | |||
29 | /** @var string */ |
||
30 | protected $php_ext; |
||
31 | |||
32 | /** @var bool */ |
||
33 | protected $mailto_allowed; |
||
34 | |||
35 | /** @var bool */ |
||
36 | protected $email_form_allowed; |
||
37 | |||
38 | /** @var bool */ |
||
39 | protected $jabber_allowed; |
||
40 | |||
41 | /** |
||
42 | * Constructor |
||
43 | * |
||
44 | * @param \phpbb\auth\auth $auth Auth object |
||
45 | * @param \phpbb\config\config $config Config object |
||
46 | * @param \phpbb\language\language $translator Language object |
||
47 | * @param \phpbb\user $user User Object |
||
48 | * @param string $phpbb_root_path Path to the phpbb includes directory. |
||
49 | * @param string $php_ext php file extension |
||
50 | */ |
||
51 | 95 | public function __construct(\phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\language\language $translator, \phpbb\user $user, $phpbb_root_path, $php_ext) |
|
64 | |||
65 | /** |
||
66 | * @param array $row |
||
67 | * @return array |
||
68 | */ |
||
69 | 14 | protected function get_email_contact(array $row) |
|
83 | |||
84 | /** |
||
85 | * @param array $row |
||
86 | * @return bool |
||
87 | */ |
||
88 | 14 | protected function user_email_allowed(array $row) |
|
92 | |||
93 | /** |
||
94 | * @param array $row |
||
95 | * @return string |
||
96 | */ |
||
97 | 14 | protected function get_email_url(array $row) |
|
101 | |||
102 | /** |
||
103 | * @return bool |
||
104 | */ |
||
105 | 95 | protected function get_email_form_allowed() |
|
109 | |||
110 | /** |
||
111 | * @return bool |
||
112 | */ |
||
113 | 95 | protected function get_mailto_allowed() |
|
117 | |||
118 | /** |
||
119 | * @param array $row |
||
120 | * @return array |
||
121 | */ |
||
122 | 14 | protected function get_jabber_contact(array $row) |
|
136 | |||
137 | /** |
||
138 | * @return bool |
||
139 | */ |
||
140 | 95 | protected function get_jabber_allowed() |
|
144 | |||
145 | /** |
||
146 | * @param array $row |
||
147 | * @param array $can_receive_pm_list |
||
148 | * @param array $permanently_banned_users |
||
149 | * @return array |
||
150 | */ |
||
151 | 14 | protected function get_pm_contact(array $row, array $can_receive_pm_list, array $permanently_banned_users) |
|
165 | |||
166 | /** |
||
167 | * @return bool |
||
168 | */ |
||
169 | 14 | protected function user_can_pm() |
|
173 | |||
174 | /** |
||
175 | * @param array $row |
||
176 | * @param array $can_receive_pm_list |
||
177 | * @param array $permanently_banned_users |
||
178 | * @return bool |
||
179 | */ |
||
180 | 14 | protected function can_receive_pm(array $row, array $can_receive_pm_list, array $permanently_banned_users) |
|
192 | |||
193 | /** |
||
194 | * @param array $row |
||
195 | * @param array $permanently_banned_users |
||
196 | * @return bool |
||
197 | */ |
||
198 | 14 | protected function user_is_allowed_to_pm(array $row, array $permanently_banned_users) |
|
208 | |||
209 | /** |
||
210 | * @param array $row |
||
211 | * @return bool |
||
212 | */ |
||
213 | 14 | protected function user_type_can_pm(array $row) |
|
223 | |||
224 | /** |
||
225 | * @param bool $user_allow_pm |
||
226 | * @return bool |
||
227 | */ |
||
228 | 4 | protected function user_allows_pm_contact($user_allow_pm) |
|
232 | |||
233 | /** |
||
234 | * Get the list of users who can receive private messages |
||
235 | * |
||
236 | * @param array $user_ids |
||
237 | * @return array |
||
238 | */ |
||
239 | 14 | protected function get_can_receive_pm_list(array $user_ids) |
|
244 | |||
245 | /** |
||
246 | * Get the list of permanently banned users |
||
247 | * |
||
248 | * @param array $user_ids |
||
249 | * @return array |
||
250 | */ |
||
251 | 14 | protected function get_banned_users_list(array $user_ids) |
|
260 | } |
||
261 |