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\user */ |
||
| 15 | protected $user; |
||
| 16 | |||
| 17 | /** @var bool */ |
||
| 18 | private $expanded = true; |
||
| 19 | |||
| 20 | /** @var integer */ |
||
| 21 | private $max_depth = 100; |
||
| 22 | |||
| 23 | /** @var integer */ |
||
| 24 | private $min_depth = 0; |
||
| 25 | |||
| 26 | /** @var array */ |
||
| 27 | private $parental_depth; |
||
| 28 | |||
| 29 | /** @var array */ |
||
| 30 | private $current_item; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Construct |
||
| 34 | * |
||
| 35 | * @param \phpbb\db\driver\driver_interface $db Database connection |
||
| 36 | * @param \phpbb\user $user User Object |
||
| 37 | * @param string $menu_items_table Menu Items table |
||
| 38 | * @param string $pk Primary key |
||
| 39 | */ |
||
| 40 | 2 | public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\user $user, $menu_items_table, $pk) |
|
| 46 | |||
| 47 | /** |
||
| 48 | * @param array $params |
||
| 49 | * @return void |
||
| 50 | */ |
||
| 51 | 2 | public function set_params(array $params) |
|
| 56 | |||
| 57 | /** |
||
| 58 | * @param array $data |
||
| 59 | * @param \phpbb\template\twig\twig $template |
||
| 60 | * @param string $handle |
||
| 61 | * @return void |
||
| 62 | */ |
||
| 63 | 2 | public function display_navlist(array $data, \phpbb\template\twig\twig &$template, $handle = 'tree') |
|
| 84 | |||
| 85 | /** |
||
| 86 | * @param array $data |
||
| 87 | * @return bool |
||
| 88 | */ |
||
| 89 | 2 | protected function set_current_item(array $data) |
|
| 112 | |||
| 113 | /** |
||
| 114 | * @return string |
||
| 115 | */ |
||
| 116 | 2 | protected function get_current_path() |
|
| 125 | |||
| 126 | /** |
||
| 127 | * return void |
||
| 128 | */ |
||
| 129 | protected function default_current_item() |
||
| 142 | |||
| 143 | /** |
||
| 144 | * @param array $data |
||
| 145 | * @return void |
||
| 146 | */ |
||
| 147 | 2 | protected function prepare_items(array &$data) |
|
| 188 | |||
| 189 | /** |
||
| 190 | * @param array $row |
||
| 191 | * @param array $leaf |
||
| 192 | * @return bool |
||
| 193 | */ |
||
| 194 | 2 | protected function should_skip_branch(array $row, array $leaf) |
|
| 198 | |||
| 199 | /** |
||
| 200 | * @param array $row |
||
| 201 | * @return bool |
||
| 202 | */ |
||
| 203 | 2 | protected function is_current_item(array $row) |
|
| 207 | |||
| 208 | /** |
||
| 209 | * @param array $row |
||
| 210 | * @return bool |
||
| 211 | */ |
||
| 212 | 2 | protected function is_parent_of_current_item(array $row) |
|
| 216 | |||
| 217 | /** |
||
| 218 | * Does the branch end here? |
||
| 219 | * |
||
| 220 | * @param array $row |
||
| 221 | * @param bool $is_current_item |
||
| 222 | * @param bool $is_current_items_parent |
||
| 223 | * @return array |
||
| 224 | */ |
||
| 225 | 2 | protected function get_leaf_node(array $row, $is_current_item, $is_current_items_parent) |
|
| 229 | |||
| 230 | /** |
||
| 231 | * @param array $row |
||
| 232 | * @param bool $is_current_items_parent |
||
| 233 | * @return bool |
||
| 234 | */ |
||
| 235 | 2 | protected function must_not_expand(array $row, $is_current_items_parent) |
|
| 239 | |||
| 240 | /** |
||
| 241 | * @param \phpbb\template\twig\twig $template |
||
| 242 | * @param string $handle |
||
| 243 | * @param int $repeat |
||
| 244 | * @return void |
||
| 245 | */ |
||
| 246 | 2 | protected function close_open_tags(\phpbb\template\twig\twig &$template, $handle, $repeat) |
|
| 253 | |||
| 254 | /** |
||
| 255 | * @param int $items_depth |
||
| 256 | * return bool |
||
| 257 | * @return bool |
||
| 258 | */ |
||
| 259 | 2 | protected function needs_adjustment($items_depth) |
|
| 263 | |||
| 264 | /** |
||
| 265 | * @param array $row |
||
| 266 | * @return void |
||
| 267 | */ |
||
| 268 | 2 | protected function adjust_depth(array $row) |
|
| 277 | |||
| 278 | /** |
||
| 279 | * @param int $item_id |
||
| 280 | * @param array $data |
||
| 281 | * @param array $leaf |
||
| 282 | * @return void |
||
| 283 | */ |
||
| 284 | protected function adjust_right_id($item_id, array &$data, array $leaf) |
||
| 291 | |||
| 292 | /** |
||
| 293 | * Append session id to local, non-directory paths |
||
| 294 | * |
||
| 295 | * @param array $row |
||
| 296 | * @return string |
||
| 297 | */ |
||
| 298 | 2 | protected function get_full_url(array $row) |
|
| 308 | |||
| 309 | /** |
||
| 310 | * @param int $depth |
||
| 311 | * @param int $adjustment |
||
| 312 | */ |
||
| 313 | 1 | protected function set_depth_limits($depth, $adjustment) |
|
| 318 | } |
||
| 319 |