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 | /** |
||
39 | * Constructor |
||
40 | * |
||
41 | * @param \phpbb\auth\auth $auth Auth object |
||
42 | * @param \phpbb\config\config $config Config object |
||
43 | * @param \phpbb\language\language $translator Language object |
||
44 | * @param \phpbb\user $user User Object |
||
45 | * @param string $phpbb_root_path Path to the phpbb includes directory. |
||
46 | * @param string $php_ext php file extension |
||
47 | */ |
||
48 | 88 | public function __construct(\phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\language\language $translator, \phpbb\user $user, $phpbb_root_path, $php_ext) |
|
60 | |||
61 | /** |
||
62 | * @param array $row |
||
63 | * @return array |
||
64 | */ |
||
65 | 8 | protected function get_email_contact(array $row) |
|
79 | |||
80 | /** |
||
81 | * @param array $row |
||
82 | * @return bool |
||
83 | */ |
||
84 | 8 | protected function user_email_allowed(array $row) |
|
88 | |||
89 | /** |
||
90 | * @param array $row |
||
91 | * @return string |
||
92 | */ |
||
93 | 8 | protected function get_email_url(array $row) |
|
97 | |||
98 | /** |
||
99 | * @return bool |
||
100 | */ |
||
101 | 88 | protected function get_email_form_allowed() |
|
105 | |||
106 | /** |
||
107 | * @return bool |
||
108 | */ |
||
109 | 88 | protected function get_mailto_allowed() |
|
113 | |||
114 | /** |
||
115 | * @param array $row |
||
116 | * @return array |
||
117 | */ |
||
118 | 8 | protected function get_jabber_contact(array $row) |
|
132 | |||
133 | /** |
||
134 | * @param array $row |
||
135 | * @return bool |
||
136 | */ |
||
137 | 8 | protected function user_can_jabber(array $row) |
|
141 | |||
142 | /** |
||
143 | * @param array $row |
||
144 | * @param array $can_receive_pm_list |
||
145 | * @param array $permanently_banned_users |
||
146 | * @return array |
||
147 | */ |
||
148 | 8 | protected function get_pm_contact(array $row, array $can_receive_pm_list, array $permanently_banned_users) |
|
162 | |||
163 | /** |
||
164 | * @return bool |
||
165 | */ |
||
166 | 8 | protected function user_can_pm() |
|
170 | |||
171 | /** |
||
172 | * @param array $row |
||
173 | * @param array $can_receive_pm_list |
||
174 | * @param array $permanently_banned_users |
||
175 | * @return bool |
||
176 | */ |
||
177 | 8 | protected function can_receive_pm(array $row, array $can_receive_pm_list, array $permanently_banned_users) |
|
196 | |||
197 | /** |
||
198 | * Get the list of users who can receive private messages |
||
199 | * |
||
200 | * @param array $user_ids |
||
201 | * @return array |
||
202 | */ |
||
203 | 8 | protected function get_can_receive_pm_list(array $user_ids) |
|
208 | |||
209 | /** |
||
210 | * Get the list of permanently banned users |
||
211 | * |
||
212 | * @param array $user_ids |
||
213 | * @return array |
||
214 | */ |
||
215 | 8 | protected function get_banned_users_list(array $user_ids) |
|
224 | } |
||
225 |