Complex classes like cfg_handler 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 cfg_handler, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 18 | class cfg_handler extends cfg_fields |
||
| 19 | { |
||
| 20 | /** @var driver_interface */ |
||
| 21 | protected $db; |
||
| 22 | |||
| 23 | /** @var request_interface */ |
||
| 24 | protected $request; |
||
| 25 | |||
| 26 | /** @var template */ |
||
| 27 | protected $template; |
||
| 28 | |||
| 29 | /** @var user */ |
||
| 30 | protected $user; |
||
| 31 | |||
| 32 | /** @var string phpBB root path */ |
||
| 33 | protected $phpbb_root_path; |
||
| 34 | |||
| 35 | /** @var string phpEx */ |
||
| 36 | protected $php_ext; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Constructor |
||
| 40 | * |
||
| 41 | * @param driver_interface $db Database object |
||
| 42 | * @param request_interface $request Request object |
||
| 43 | * @param template $template Template object |
||
| 44 | * @param user $user User object |
||
| 45 | * @param string $phpbb_root_path phpBB root path |
||
| 46 | * @param string $php_ext phpEx |
||
| 47 | */ |
||
| 48 | 44 | public function __construct(driver_interface $db, request_interface $request, template $template, user $user, $phpbb_root_path, $php_ext) |
|
| 59 | |||
| 60 | /** |
||
| 61 | * @param array $block_data |
||
| 62 | * @param array $default_settings |
||
| 63 | * @return template|string |
||
| 64 | */ |
||
| 65 | 7 | public function get_edit_form(array $block_data, array $default_settings) |
|
| 95 | |||
| 96 | /** |
||
| 97 | * @param array $default_settings |
||
| 98 | * @return array|void |
||
| 99 | */ |
||
| 100 | 6 | public function get_submitted_settings(array $default_settings) |
|
| 121 | |||
| 122 | /** |
||
| 123 | * Generate block configuration fields |
||
| 124 | * |
||
| 125 | * @param array $db_settings |
||
| 126 | * @param array $default_settings |
||
| 127 | */ |
||
| 128 | 7 | private function _generate_config_fields(array &$db_settings, array $default_settings) |
|
| 150 | |||
| 151 | /** |
||
| 152 | * @param $field |
||
| 153 | * @param array $db_settings |
||
| 154 | * @param array $vars |
||
| 155 | * @return string |
||
| 156 | */ |
||
| 157 | 6 | private function _get_field_template($field, array &$db_settings, array &$vars) |
|
| 173 | |||
| 174 | /** |
||
| 175 | * @param string $field |
||
| 176 | * @param string|array $vars |
||
| 177 | * @return boolean |
||
| 178 | */ |
||
| 179 | 6 | private function _sets_legend($field, $vars) |
|
| 193 | |||
| 194 | /** |
||
| 195 | * @param array $vars |
||
| 196 | * @return mixed|string |
||
| 197 | */ |
||
| 198 | 6 | private function _explain_field(array $vars) |
|
| 208 | |||
| 209 | /** |
||
| 210 | * @param array $vars |
||
| 211 | * @return mixed|string |
||
| 212 | */ |
||
| 213 | 6 | private function _append_field(array $vars) |
|
| 223 | |||
| 224 | /** |
||
| 225 | * @param $field |
||
| 226 | * @param $vars |
||
| 227 | * @param $settings |
||
| 228 | */ |
||
| 229 | 5 | private function _set_params($field, &$vars, $settings) |
|
| 237 | |||
| 238 | /** |
||
| 239 | * @param $field |
||
| 240 | * @param $default |
||
| 241 | * @param $db_settings |
||
| 242 | * @return mixed |
||
| 243 | */ |
||
| 244 | 6 | private function _get_field_value($field, $default, $db_settings) |
|
| 248 | |||
| 249 | /** |
||
| 250 | * @param $vars |
||
| 251 | */ |
||
| 252 | 1 | private function _prep_select_field_for_display(&$vars) |
|
| 258 | |||
| 259 | /** |
||
| 260 | * @param $vars |
||
| 261 | * @param $type |
||
| 262 | * @param $field |
||
| 263 | */ |
||
| 264 | 2 | private function _prep_checkbox_field_for_display(&$vars, &$type, $field) |
|
| 272 | |||
| 273 | /** |
||
| 274 | * @param $vars |
||
| 275 | * @param $type |
||
| 276 | * @param $field |
||
| 277 | */ |
||
| 278 | 1 | private function _prep_multi_select_field_for_display(&$vars, &$type, $field) |
|
| 284 | |||
| 285 | /** |
||
| 286 | * @param $vars |
||
| 287 | * @param $type |
||
| 288 | */ |
||
| 289 | 1 | private function _prep_hidden_field_for_display(&$vars, &$type) |
|
| 296 | |||
| 297 | /** |
||
| 298 | * @param $vars |
||
| 299 | * @param $type |
||
| 300 | */ |
||
| 301 | 1 | private function _prep_custom_field_for_display(&$vars, &$type) |
|
| 306 | |||
| 307 | /** |
||
| 308 | * this looks bad but its the only way without modifying phpbb code |
||
| 309 | * this is for select items that do not need to be translated |
||
| 310 | * @param array $options |
||
| 311 | */ |
||
| 312 | 4 | private function _add_lang_vars(array $options) |
|
| 322 | |||
| 323 | /** |
||
| 324 | * @param array $cfg_array |
||
| 325 | * @param array $df_settings |
||
| 326 | */ |
||
| 327 | 5 | private function _get_multi_select(array &$cfg_array, array $df_settings) |
|
| 337 | |||
| 338 | /** |
||
| 339 | * @param string $selected |
||
| 340 | * @return string |
||
| 341 | */ |
||
| 342 | 7 | private function _get_group_options($selected = '') |
|
| 360 | |||
| 361 | /** |
||
| 362 | * @param array $row |
||
| 363 | * @return mixed|string |
||
| 364 | */ |
||
| 365 | 7 | private function _get_group_name(array $row) |
|
| 369 | } |
||
| 370 |