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 = true; |
||
25 | |||
26 | /** @var integer */ |
||
27 | private $max_depth = 100; |
||
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 | 11 | 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 | 11 | public function display_navlist(array $data, \phpbb\template\twig\twig &$template, $handle = 'tree') |
|
94 | |||
95 | /** |
||
96 | * Comment this out for now. May revisit this later |
||
97 | * |
||
98 | * @param array $data |
||
99 | * @return void |
||
100 | * |
||
101 | public function generate_breadcrumb(array $data) |
||
102 | { |
||
103 | $this->find_parents($data, $this->current_item['parent_id']); |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * @param array $data |
||
108 | * @param int $parent_id |
||
109 | * @return void |
||
110 | * |
||
111 | protected function find_parents(array $data, $parent_id) |
||
112 | { |
||
113 | if (isset($data[$parent_id]) && $data[$parent_id]['item_url'] !== 'index.php') |
||
114 | { |
||
115 | $row = $data[$parent_id]; |
||
116 | $this->template->alter_block_array('navlinks', array( |
||
117 | 'FORUM_NAME' => $row['item_title'], |
||
118 | 'U_VIEW_FORUM' => $row['full_url'], |
||
119 | )); |
||
120 | |||
121 | $this->find_parents($data, $row['parent_id']); |
||
122 | } |
||
123 | } |
||
124 | */ |
||
125 | |||
126 | /** |
||
127 | * @param array $data |
||
128 | * @return bool |
||
129 | */ |
||
130 | 11 | protected function set_current_item(array $data) |
|
153 | 5 | ||
154 | /** |
||
155 | * @return string |
||
156 | */ |
||
157 | protected function get_current_path() |
||
166 | |||
167 | 11 | /** |
|
168 | * return void |
||
169 | */ |
||
170 | protected function default_current_item() |
||
183 | 5 | ||
184 | 5 | /** |
|
185 | * @param array $data |
||
186 | * @return void |
||
187 | */ |
||
188 | protected function prepare_items(array &$data) |
||
229 | 11 | ||
230 | 11 | /** |
|
231 | 11 | * @param array $row |
|
232 | * @param array $leaf |
||
233 | * @return bool |
||
234 | */ |
||
235 | protected function should_skip_branch(array $row, array $leaf) |
||
239 | |||
240 | 11 | /** |
|
241 | * @param array $row |
||
242 | * @return bool |
||
243 | */ |
||
244 | protected function is_current_item(array $row) |
||
248 | |||
249 | 11 | /** |
|
250 | * @param array $row |
||
251 | * @return bool |
||
252 | */ |
||
253 | protected function is_parent_of_current_item(array $row) |
||
257 | |||
258 | 11 | /** |
|
259 | * Does the branch end here? |
||
260 | * |
||
261 | * @param array $row |
||
262 | * @param bool $is_current_item |
||
263 | * @param bool $is_current_items_parent |
||
264 | * @return array |
||
265 | */ |
||
266 | protected function get_leaf_node(array $row, $is_current_item, $is_current_items_parent) |
||
270 | |||
271 | 11 | /** |
|
272 | * @param array $row |
||
273 | * @param bool $is_current_items_parent |
||
274 | * @return bool |
||
275 | */ |
||
276 | protected function must_not_expand(array $row, $is_current_items_parent) |
||
280 | |||
281 | 11 | /** |
|
282 | * @param \phpbb\template\twig\twig $template |
||
283 | * @param string $handle |
||
284 | * @param int $repeat |
||
285 | * @return void |
||
286 | */ |
||
287 | protected function close_open_tags(\phpbb\template\twig\twig &$template, $handle, $repeat) |
||
294 | 9 | ||
295 | 9 | /** |
|
296 | 11 | * @param int $items_depth |
|
297 | * return bool |
||
298 | * @return bool |
||
299 | */ |
||
300 | protected function needs_adjustment($items_depth) |
||
304 | |||
305 | 6 | /** |
|
306 | * @param array $row |
||
307 | * @return void |
||
308 | */ |
||
309 | protected function adjust_depth(array $row) |
||
318 | 2 | ||
319 | 2 | /** |
|
320 | 6 | * @param int $item_id |
|
321 | * @param array $data |
||
322 | * @param array $leaf |
||
323 | * @return void |
||
324 | */ |
||
325 | protected function adjust_right_id($item_id, array &$data, array $leaf) |
||
332 | 4 | ||
333 | 4 | /** |
|
334 | 4 | * Append session id to local, non-directory paths |
|
335 | * |
||
336 | * @param array $row |
||
337 | * @return string |
||
338 | */ |
||
339 | protected function get_full_url(array $row) |
||
349 | |||
350 | 11 | /** |
|
351 | * @param int $depth |
||
352 | * @param int $adjustment |
||
353 | */ |
||
354 | protected function set_depth_limits($depth, $adjustment) |
||
359 | } |
||
360 |