Complex classes like helper 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 helper, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
12 | class helper extends urls |
||
13 | { |
||
14 | /** |
||
15 | * @param array $post_data |
||
16 | * @return bool |
||
17 | */ |
||
18 | public function display_attachments_notice(array $post_data) |
||
22 | |||
23 | /** |
||
24 | * @param array $post_data |
||
25 | * @return bool |
||
26 | */ |
||
27 | public function permanent_delete_allowed(array $post_data) |
||
32 | |||
33 | /** |
||
34 | * @param int $poster_id |
||
35 | * @return bool |
||
36 | */ |
||
37 | public function user_is_poster($poster_id) |
||
41 | |||
42 | /** |
||
43 | * @param int $forum_id |
||
44 | * @return bool |
||
45 | */ |
||
46 | public function can_report_post($forum_id) |
||
50 | |||
51 | /** |
||
52 | * @param array $topic_data |
||
53 | * @return bool |
||
54 | */ |
||
55 | public function topic_has_unapproved_posts(array $topic_data) |
||
59 | |||
60 | /** |
||
61 | * @param array $topic_data |
||
62 | * @return bool |
||
63 | */ |
||
64 | public function topic_is_reported(array $topic_data) |
||
68 | |||
69 | /** |
||
70 | * @param array $topic_data |
||
71 | * @return bool |
||
72 | */ |
||
73 | public function topic_is_locked(array $topic_data) |
||
77 | |||
78 | /** |
||
79 | * @param array $post_data |
||
80 | * @return bool |
||
81 | */ |
||
82 | public function post_is_unapproved(array $post_data) |
||
86 | |||
87 | /** |
||
88 | * @param array $post_data |
||
89 | * @param array $topic_data |
||
90 | * @return bool |
||
91 | */ |
||
92 | protected function edit_allowed(array $post_data, array $topic_data) |
||
100 | |||
101 | /** |
||
102 | * @param array $topic_data |
||
103 | * @return bool |
||
104 | */ |
||
105 | protected function quote_allowed(array $topic_data) |
||
111 | |||
112 | /** |
||
113 | * @param array $post_data |
||
114 | * @param array $topic_data |
||
115 | * @return bool |
||
116 | */ |
||
117 | protected function post_is_quotable(array $post_data, array $topic_data) |
||
121 | |||
122 | /** |
||
123 | * @param array $post_data |
||
124 | * @param array $topic_data |
||
125 | * @return bool |
||
126 | */ |
||
127 | protected function delete_allowed(array $post_data, array $topic_data) |
||
136 | |||
137 | /** |
||
138 | * @param array $post_data |
||
139 | * @return bool |
||
140 | */ |
||
141 | protected function softdelete_allowed(array $post_data) |
||
146 | |||
147 | /** |
||
148 | * @param array $post_data |
||
149 | * @return bool |
||
150 | */ |
||
151 | protected function cannot_edit(array $post_data) |
||
155 | |||
156 | /** |
||
157 | * @param array $post_data |
||
158 | * @return bool |
||
159 | */ |
||
160 | protected function cannot_edit_time(array $post_data) |
||
164 | |||
165 | /** |
||
166 | * @param array $post_data |
||
167 | * @param array $topic_data |
||
168 | * @return bool |
||
169 | */ |
||
170 | protected function cannot_edit_locked(array $post_data, array $topic_data) |
||
174 | |||
175 | /** |
||
176 | * @param array $post_data |
||
177 | * @return bool |
||
178 | */ |
||
179 | protected function cannot_delete(array $post_data) |
||
186 | |||
187 | /** |
||
188 | * @param array $post_data |
||
189 | * @param array $topic_data |
||
190 | * @return bool |
||
191 | */ |
||
192 | protected function cannot_delete_lastpost(array $post_data, array $topic_data) |
||
196 | |||
197 | /** |
||
198 | * @param array $post_data |
||
199 | * @return bool |
||
200 | */ |
||
201 | protected function cannot_delete_time(array $post_data) |
||
205 | |||
206 | /** |
||
207 | * we do not want to allow removal of the last post if a moderator locked it! |
||
208 | * @param array $post_data |
||
209 | * @param array $topic_data |
||
210 | * @return bool |
||
211 | */ |
||
212 | protected function cannot_delete_locked(array $post_data, array $topic_data) |
||
216 | } |
||
217 |