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 permissions |
||
| 13 | { |
||
| 14 | /** @var string */ |
||
| 15 | protected $phpbb_root_path; |
||
| 16 | |||
| 17 | /** @var string */ |
||
| 18 | protected $php_ext; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Constructor |
||
| 22 | * |
||
| 23 | * @param \phpbb\auth\auth $auth Auth object |
||
| 24 | * @param \phpbb\config\db $config Config object |
||
| 25 | * @param \phpbb\user $user User object |
||
| 26 | * @param string $phpbb_root_path Path to the phpbb includes directory. |
||
| 27 | * @param string $php_ext php file extension |
||
| 28 | */ |
||
| 29 | public function __construct(\phpbb\auth\auth $auth, \phpbb\config\db $config, \phpbb\user $user, $phpbb_root_path, $php_ext) |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @param array $post_data |
||
| 39 | * @param array $topic_data |
||
| 40 | * @param string $cp_mode |
||
| 41 | * @return string |
||
| 42 | */ |
||
| 43 | public function get_edit_url(array $post_data, array $topic_data, $cp_mode = '') |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @param array $post_data |
||
| 51 | * @param array $topic_data |
||
| 52 | * @param string $cp_mode |
||
| 53 | * @return string |
||
| 54 | */ |
||
| 55 | public function get_delete_url(array $post_data, array $topic_data, $cp_mode = '') |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @param array $post_data |
||
| 63 | * @param array $topic_data |
||
| 64 | * @return string |
||
| 65 | */ |
||
| 66 | public function get_quote_url(array $post_data, array $topic_data) |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @param array $topic_data |
||
| 73 | * @return string |
||
| 74 | */ |
||
| 75 | public function get_viewtopic_url(array $topic_data) |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @param array $topic_data |
||
| 82 | * @return string |
||
| 83 | */ |
||
| 84 | public function get_print_topic_url(array $topic_data) |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @param array $topic_data |
||
| 91 | * @return string |
||
| 92 | */ |
||
| 93 | public function get_email_topic_url(array $topic_data) |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @param int $forum_id |
||
| 100 | * @param string $username |
||
| 101 | * @return string |
||
| 102 | */ |
||
| 103 | public function get_search_users_posts_url($forum_id, $username) |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @param array $post_data |
||
| 110 | * @return string |
||
| 111 | */ |
||
| 112 | public function get_info_url(array $post_data) |
||
| 117 | |||
| 118 | /** |
||
| 119 | * @param array $post_data |
||
| 120 | * @param string $viewtopic_url |
||
| 121 | * @return string |
||
| 122 | */ |
||
| 123 | public function get_approve_url(array $post_data, $viewtopic_url) |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @param array $post_data |
||
| 130 | * @param array $topic_data |
||
| 131 | * @return string |
||
| 132 | */ |
||
| 133 | public function get_mcp_edit_url(array $post_data, array $topic_data) |
||
| 137 | |||
| 138 | /** |
||
| 139 | * @param array $post_data |
||
| 140 | * @return string |
||
| 141 | */ |
||
| 142 | public function get_mcp_report_url(array $post_data) |
||
| 146 | |||
| 147 | /** |
||
| 148 | * @param array $post_data |
||
| 149 | * @param array $topic_data |
||
| 150 | * @return string |
||
| 151 | */ |
||
| 152 | public function get_mcp_restore_url(array $post_data, array $topic_data) |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @param array $post_data |
||
| 159 | * @return string |
||
| 160 | */ |
||
| 161 | public function get_notes_url(array $post_data) |
||
| 165 | |||
| 166 | /** |
||
| 167 | * @param array $post_data |
||
| 168 | * @return string |
||
| 169 | */ |
||
| 170 | public function get_warning_url(array $post_data) |
||
| 174 | |||
| 175 | /** |
||
| 176 | * @param int $topic_id |
||
| 177 | * @return string |
||
| 178 | */ |
||
| 179 | public function get_mcp_queue_url($topic_id) |
||
| 183 | |||
| 184 | /** |
||
| 185 | * @param string $content_type |
||
| 186 | * @param int $topic_id |
||
| 187 | * @return string |
||
| 188 | */ |
||
| 189 | public function get_mcp_review_url($content_type, $topic_id) |
||
| 193 | |||
| 194 | /** |
||
| 195 | * @param int $forum_id |
||
| 196 | * @param int $topic_id |
||
| 197 | * @return string |
||
| 198 | */ |
||
| 199 | public function get_mcp_url($forum_id, $topic_id) |
||
| 215 | |||
| 216 | /** |
||
| 217 | * @param array $post_data |
||
| 218 | * @param array $topic_data |
||
| 219 | * @param string $cp_mode |
||
| 220 | * @return string |
||
| 221 | */ |
||
| 222 | protected function get_cp_param(array $post_data, array $topic_data, $cp_mode) |
||
| 231 | } |
||
| 232 |