Complex classes like display 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 display, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 12 | class display extends \blitze\sitemaker\services\tree\display |
||
| 13 | { |
||
| 14 | /** @var \phpbb\template\template */ |
||
| 15 | protected $template; |
||
| 16 | |||
| 17 | /** @var \phpbb\user */ |
||
| 18 | protected $user; |
||
| 19 | |||
| 20 | /** @var string */ |
||
| 21 | protected $php_ext; |
||
| 22 | |||
| 23 | /** @var bool */ |
||
| 24 | private $expanded = false; |
||
| 25 | |||
| 26 | /** @var integer */ |
||
| 27 | private $max_depth = 0; |
||
| 28 | |||
| 29 | /** @var integer */ |
||
| 30 | private $min_depth = 0; |
||
| 31 | |||
| 32 | /** @var array */ |
||
| 33 | private $parental_depth; |
||
| 34 | |||
| 35 | /** @var array */ |
||
| 36 | private $current_item; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Construct |
||
| 40 | * |
||
| 41 | * @param \phpbb\db\driver\driver_interface $db Database connection |
||
| 42 | * @param \phpbb\template\template $template Template object |
||
| 43 | * @param \phpbb\user $user User Object |
||
| 44 | * @param string $menu_items_table Menu Items table |
||
| 45 | * @param string $pk Primary key |
||
| 46 | * @param string $php_ext php file extension |
||
| 47 | */ |
||
| 48 | 21 | public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\template\template $template, \phpbb\user $user, $menu_items_table, $pk, $php_ext) |
|
| 56 | |||
| 57 | /** |
||
| 58 | * @param array $params |
||
| 59 | * @return void |
||
| 60 | */ |
||
| 61 | 10 | public function set_params(array $params) |
|
| 66 | |||
| 67 | /** |
||
| 68 | * @param array $data |
||
| 69 | * @param \phpbb\template\twig\twig $template |
||
| 70 | * @param string $handle |
||
| 71 | * @return void |
||
| 72 | */ |
||
| 73 | 10 | public function display_navlist(array $data, \phpbb\template\twig\twig &$template, $handle = 'tree') |
|
| 93 | |||
| 94 | /** |
||
| 95 | * @param array $data |
||
| 96 | * @return void |
||
| 97 | */ |
||
| 98 | 8 | public function generate_breadcrumb(array $data) |
|
| 102 | |||
| 103 | /** |
||
| 104 | * @param array $data |
||
| 105 | * @return void |
||
| 106 | */ |
||
| 107 | 10 | protected function prepare_items(array &$data) |
|
| 148 | |||
| 149 | /** |
||
| 150 | * @param array $row |
||
| 151 | * @param array $leaf |
||
| 152 | * @return bool |
||
| 153 | */ |
||
| 154 | 10 | protected function should_skip_branch(array $row, array $leaf) |
|
| 158 | |||
| 159 | /** |
||
| 160 | * @param array $data |
||
| 161 | * @return bool |
||
| 162 | */ |
||
| 163 | 10 | protected function set_current_item(array $data) |
|
| 184 | |||
| 185 | /** |
||
| 186 | * return void |
||
| 187 | */ |
||
| 188 | 4 | protected function default_current_item() |
|
| 201 | |||
| 202 | /** |
||
| 203 | * @param string $curr_page |
||
| 204 | * @param array $curr_parts |
||
| 205 | * @param array $row |
||
| 206 | * @return bool |
||
| 207 | */ |
||
| 208 | 10 | protected function is_current_path($curr_page, array $curr_parts, array $row) |
|
| 212 | |||
| 213 | /** |
||
| 214 | * @param array $row |
||
| 215 | * @return bool |
||
| 216 | */ |
||
| 217 | 10 | protected function is_current_item(array $row) |
|
| 221 | |||
| 222 | /** |
||
| 223 | * @param array $row |
||
| 224 | * @return bool |
||
| 225 | */ |
||
| 226 | 9 | protected function is_child_of_current_item(array $row) |
|
| 230 | |||
| 231 | /** |
||
| 232 | * Does the branch end here? |
||
| 233 | * |
||
| 234 | * @param array $row |
||
| 235 | * @param bool $is_current_item |
||
| 236 | * @return array |
||
| 237 | */ |
||
| 238 | 10 | protected function get_leaf_node(array $row, $is_current_item) |
|
| 242 | |||
| 243 | /** |
||
| 244 | * @param array $row |
||
| 245 | * @return bool |
||
| 246 | */ |
||
| 247 | 10 | protected function must_not_expand(array $row) |
|
| 251 | |||
| 252 | /** |
||
| 253 | * @param \phpbb\template\twig\twig $template |
||
| 254 | * @param string $handle |
||
| 255 | * @param int $repeat |
||
| 256 | * @return void |
||
| 257 | */ |
||
| 258 | 10 | protected function close_open_tags(\phpbb\template\twig\twig &$template, $handle, $repeat) |
|
| 265 | |||
| 266 | /** |
||
| 267 | * @param int $items_depth |
||
| 268 | * return bool |
||
| 269 | * @return bool |
||
| 270 | */ |
||
| 271 | 6 | protected function needs_adjustment($items_depth) |
|
| 275 | |||
| 276 | /** |
||
| 277 | * @param array $row |
||
| 278 | * @return void |
||
| 279 | */ |
||
| 280 | 6 | protected function adjust_depth(array $row) |
|
| 289 | |||
| 290 | /** |
||
| 291 | * @param int $item_id |
||
| 292 | * @param array $data |
||
| 293 | * @param array $leaf |
||
| 294 | * @return void |
||
| 295 | */ |
||
| 296 | 4 | protected function adjust_right_id($item_id, array &$data, array $leaf) |
|
| 303 | |||
| 304 | /** |
||
| 305 | * @param array $data |
||
| 306 | * @param int $parent_id |
||
| 307 | * @return void |
||
| 308 | */ |
||
| 309 | 8 | protected function find_parents(array $data, $parent_id) |
|
| 322 | |||
| 323 | /** |
||
| 324 | * Append session id to local, non-directory paths |
||
| 325 | * |
||
| 326 | * @param array $row |
||
| 327 | * @return string |
||
| 328 | */ |
||
| 329 | 10 | protected function get_full_url(array $row) |
|
| 339 | |||
| 340 | /** |
||
| 341 | * @param int $depth |
||
| 342 | * @param int $adjustment |
||
| 343 | */ |
||
| 344 | 3 | protected function set_depth_limits($depth, $adjustment) |
|
| 349 | } |
||
| 350 |