Complex classes like data 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 data, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 12 | class data extends query_builder |
||
| 13 | { |
||
| 14 | /** @var \phpbb\auth\auth */ |
||
| 15 | protected $auth; |
||
| 16 | |||
| 17 | /** @var \phpbb\config\config */ |
||
| 18 | protected $config; |
||
| 19 | |||
| 20 | /** @var \phpbb\content_visibility */ |
||
| 21 | protected $content_visibility; |
||
| 22 | |||
| 23 | /** @var \phpbb\db\driver\driver_interface */ |
||
| 24 | protected $db; |
||
| 25 | |||
| 26 | /** @var \phpbb\user */ |
||
| 27 | protected $user; |
||
| 28 | |||
| 29 | /** @var \blitze\sitemaker\services\user_data */ |
||
| 30 | protected $user_data; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Constructor |
||
| 34 | * |
||
| 35 | * @param \phpbb\auth\auth $auth Auth object |
||
| 36 | * @param \phpbb\config\config $config Config object |
||
| 37 | * @param \phpbb\content_visibility $content_visibility Content visibility |
||
| 38 | * @param \phpbb\db\driver\driver_interface $db Database connection |
||
| 39 | * @param \phpbb\user $user User object |
||
| 40 | * @param \blitze\sitemaker\services\user_data $user_data Sitemaker User data object |
||
| 41 | * @param integer $cache_time Cache results for 3 hours by default |
||
| 42 | */ |
||
| 43 | public function __construct(\phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\content_visibility $content_visibility, \phpbb\db\driver\driver_interface $db, \phpbb\user $user, \blitze\sitemaker\services\user_data $user_data, $cache_time = 10800) |
||
| 54 | |||
| 55 | 29 | /** |
|
| 56 | 29 | * Get topics count |
|
| 57 | 29 | * |
|
| 58 | 29 | * @return integer |
|
| 59 | 29 | */ |
|
| 60 | 29 | public function get_topics_count() |
|
| 74 | 1 | ||
| 75 | 1 | /** |
|
| 76 | 1 | * Get topic data |
|
| 77 | 1 | * |
|
| 78 | 1 | * @param mixed|false $limit |
|
| 79 | 1 | * @param int $start |
|
| 80 | 1 | * @return array |
|
| 81 | */ |
||
| 82 | 1 | public function get_topic_data($limit = false, $start = 0) |
|
| 100 | |||
| 101 | 10 | /** |
|
| 102 | 10 | * Get post data |
|
| 103 | 10 | * |
|
| 104 | 10 | * @param mixed|false $topic_first_or_last_post (first|last) |
|
| 105 | 10 | * @param array $post_ids |
|
| 106 | 12 | * @param bool|false $limit |
|
| 107 | * @param int $start |
||
| 108 | 12 | * @param array $sql_array |
|
| 109 | * @return array |
||
| 110 | */ |
||
| 111 | public function get_post_data($topic_first_or_last_post = false, $post_ids = array(), $limit = false, $start = 0, $sql_array = array()) |
||
| 129 | 9 | ||
| 130 | 9 | /** |
|
| 131 | 9 | * Get attachments... |
|
| 132 | 9 | * |
|
| 133 | 9 | * @param int $forum_id |
|
| 134 | 9 | * @param array $allowed_extensions |
|
| 135 | 10 | * @param mixed|bool $limit |
|
| 136 | * @param bool $exclude_in_message |
||
| 137 | 10 | * @param string $order_by |
|
| 138 | * @return array |
||
| 139 | */ |
||
| 140 | public function get_attachments($forum_id = 0, $allowed_extensions = array(), $limit = false, $exclude_in_message = true, $order_by = 'filetime DESC') |
||
| 160 | 6 | ||
| 161 | /** |
||
| 162 | 6 | * Get topic tracking info |
|
| 163 | 6 | * |
|
| 164 | 6 | * @param int $forum_id |
|
| 165 | 6 | * @return array |
|
| 166 | 7 | */ |
|
| 167 | public function get_topic_tracking_info($forum_id = 0) |
||
| 178 | |||
| 179 | 5 | /** |
|
| 180 | 5 | * Returns an array of topic first post or last post ids |
|
| 181 | * |
||
| 182 | * @param string $first_or_last_post |
||
| 183 | * @return array |
||
| 184 | 5 | */ |
|
| 185 | public function get_topic_post_ids($first_or_last_post = 'first') |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Returns an array of topic first post or last post ids |
||
| 192 | */ |
||
| 193 | public function get_posters_info() |
||
| 204 | |||
| 205 | /** |
||
| 206 | * @param mixed $topic_first_or_last_post |
||
| 207 | * @param array $post_ids |
||
| 208 | * @param array $sql_array |
||
| 209 | * @return array |
||
| 210 | */ |
||
| 211 | private function _get_posts_sql_array($topic_first_or_last_post, array $post_ids, array $sql_array) |
||
| 228 | 10 | ||
| 229 | 10 | /** |
|
| 230 | * @param array $post_ids |
||
| 231 | 10 | * @param string $topic_first_or_last_post |
|
| 232 | * @return array |
||
| 233 | 10 | */ |
|
| 234 | 10 | private function _get_post_data_where(array $post_ids, $topic_first_or_last_post) |
|
| 251 | 2 | ||
| 252 | 8 | /** |
|
| 253 | 8 | * @param array $sql_where |
|
| 254 | 3 | * @param string $topic_first_or_last_post |
|
| 255 | 3 | */ |
|
| 256 | private function _limit_posts_by_topic(array &$sql_where, $topic_first_or_last_post) |
||
| 265 | |||
| 266 | 3 | /** |
|
| 267 | * @return array |
||
| 268 | 3 | */ |
|
| 269 | private function _get_tracking_info() |
||
| 283 | 5 | ||
| 284 | 4 | /** |
|
| 285 | 4 | * @param string $function |
|
| 286 | 1 | * @return array |
|
| 287 | 1 | */ |
|
| 288 | 1 | private function _build_tracking_info($function) |
|
| 298 | 5 | ||
| 299 | /** |
||
| 300 | 5 | * @return bool |
|
| 301 | 5 | */ |
|
| 302 | private function _can_track_by_lastread() |
||
| 306 | 5 | ||
| 307 | /** |
||
| 308 | * @return bool |
||
| 309 | */ |
||
| 310 | private function _can_track_anonymous() |
||
| 314 | 5 | ||
| 315 | /** |
||
| 316 | * @param int $forum_id |
||
| 317 | * @return bool |
||
| 318 | */ |
||
| 319 | private function _attachments_allowed($forum_id) |
||
| 323 | |||
| 324 | /** |
||
| 325 | * @param int $forum_id |
||
| 326 | * @return bool |
||
| 327 | */ |
||
| 328 | private function _user_can_download_attachments($forum_id) |
||
| 332 | |||
| 333 | /** |
||
| 334 | * @param array $allowed_extensions |
||
| 335 | * @param bool $exclude_in_message |
||
| 336 | * @param string $order_by |
||
| 337 | * @return string |
||
| 338 | 6 | */ |
|
| 339 | private function _get_attachment_sql($allowed_extensions, $exclude_in_message, $order_by) |
||
| 348 | } |
||
| 349 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.