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) |
|
151 | |||
152 | /** |
||
153 | * @param array $data |
||
154 | * @return bool |
||
155 | */ |
||
156 | 10 | protected function set_current_item(array $data) |
|
177 | |||
178 | /** |
||
179 | * return void |
||
180 | */ |
||
181 | 4 | protected function default_current_item() |
|
194 | |||
195 | /** |
||
196 | * @param string $curr_page |
||
197 | * @param array $curr_parts |
||
198 | * @param array $row |
||
199 | * @return bool |
||
200 | */ |
||
201 | 10 | protected function is_current_path($curr_page, array $curr_parts, array $row) |
|
205 | |||
206 | /** |
||
207 | * @param array $row |
||
208 | * @return bool |
||
209 | */ |
||
210 | 10 | protected function is_current_item(array $row) |
|
214 | |||
215 | /** |
||
216 | * @param array $row |
||
217 | * @return bool |
||
218 | */ |
||
219 | 9 | protected function is_child_of_current_item(array $row) |
|
223 | |||
224 | /** |
||
225 | * Does the branch end here? |
||
226 | * |
||
227 | * @param array $row |
||
228 | * @param bool $is_current_item |
||
229 | * @return array |
||
230 | */ |
||
231 | 10 | protected function get_leaf_node(array $row, $is_current_item) |
|
235 | |||
236 | /** |
||
237 | * @param array $row |
||
238 | * @return bool |
||
239 | */ |
||
240 | 10 | protected function must_not_expand(array $row) |
|
244 | |||
245 | /** |
||
246 | * @param \phpbb\template\twig\twig $template |
||
247 | * @param string $handle |
||
248 | * @param int $repeat |
||
249 | * @return void |
||
250 | */ |
||
251 | 10 | protected function close_open_tags(\phpbb\template\twig\twig &$template, $handle, $repeat) |
|
258 | |||
259 | /** |
||
260 | * @param int $items_depth |
||
261 | * return bool |
||
262 | * @return bool |
||
263 | */ |
||
264 | 6 | protected function needs_adjustment($items_depth) |
|
268 | |||
269 | /** |
||
270 | * @param array $row |
||
271 | * @return void |
||
272 | */ |
||
273 | 6 | protected function adjust_depth(array $row) |
|
282 | |||
283 | /** |
||
284 | * @param int $item_id |
||
285 | * @param array $data |
||
286 | * @param array $leaf |
||
287 | * @return void |
||
288 | */ |
||
289 | 4 | protected function adjust_right_id($item_id, array &$data, array $leaf) |
|
296 | |||
297 | /** |
||
298 | * @param array $data |
||
299 | * @param int $parent_id |
||
300 | * @return void |
||
301 | */ |
||
302 | 8 | protected function find_parents(array $data, $parent_id) |
|
315 | |||
316 | /** |
||
317 | * Append session id to local, non-directory paths |
||
318 | * |
||
319 | * @param array $row |
||
320 | * @return string |
||
321 | */ |
||
322 | 10 | protected function get_full_url(array $row) |
|
332 | |||
333 | /** |
||
334 | * @param int $depth |
||
335 | * @param int $adjustment |
||
336 | */ |
||
337 | 3 | protected function set_depth_limits($depth, $adjustment) |
|
342 | } |
||
343 |