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 bool */ |
||
| 21 | private $expanded = false; |
||
| 22 | |||
| 23 | /** @var integer */ |
||
| 24 | private $max_depth = 0; |
||
| 25 | |||
| 26 | /** @var integer */ |
||
| 27 | private $min_depth = 0; |
||
| 28 | |||
| 29 | /** @var array */ |
||
| 30 | private $parental_depth; |
||
| 31 | |||
| 32 | /** @var array */ |
||
| 33 | private $current_item; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Construct |
||
| 37 | * |
||
| 38 | * @param \phpbb\db\driver\driver_interface $db Database connection |
||
| 39 | * @param \phpbb\template\template $template Template object |
||
| 40 | * @param \phpbb\user $user User Object |
||
| 41 | * @param string $menu_items_table Menu Items table |
||
| 42 | * @param string $pk Primary key |
||
| 43 | */ |
||
| 44 | 18 | public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\template\template $template, \phpbb\user $user, $menu_items_table, $pk) |
|
| 51 | |||
| 52 | 7 | public function set_params(array $params) |
|
| 57 | |||
| 58 | /** |
||
| 59 | * |
||
| 60 | */ |
||
| 61 | 7 | public function display_navlist(array $data, \phpbb\template\twig\twig &$template, $handle = 'tree') |
|
| 81 | |||
| 82 | 5 | public function generate_breadcrumb(array $data) |
|
| 86 | |||
| 87 | 7 | protected function prepare_items(array &$data) |
|
| 134 | |||
| 135 | 7 | protected function set_current_item($data) |
|
| 155 | |||
| 156 | 1 | protected function default_current_item() |
|
| 169 | |||
| 170 | 7 | protected function is_current_path($curr_page, array $curr_parts, array $row) |
|
| 174 | |||
| 175 | 7 | protected function is_current_item(array $row) |
|
| 179 | |||
| 180 | 7 | protected function set_parental_depth($row, $depth, $is_current_item) |
|
| 187 | |||
| 188 | 7 | protected function close_open_tags(\phpbb\template\twig\twig &$template, $handle, $repeat) |
|
| 195 | |||
| 196 | 6 | protected function needs_adjustment($items_depth) |
|
| 200 | |||
| 201 | 6 | protected function adjust_depth(array $row) |
|
| 211 | |||
| 212 | 4 | protected function adjust_right_id($item_id, array &$data, array $leaf) |
|
| 219 | |||
| 220 | 5 | protected function find_parents(array $data, $parent_id) |
|
| 233 | } |
||
| 234 |