Complex classes like Editor 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 Editor, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 18 | class Editor extends Controller |
||
| 19 | { |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Editor model instance |
||
| 23 | * @var \gplcart\modules\editor\models\Editor $editor |
||
| 24 | */ |
||
| 25 | protected $editor; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * The current module |
||
| 29 | * @var array |
||
| 30 | */ |
||
| 31 | protected $data_module = array(); |
||
| 32 | |||
| 33 | /** |
||
| 34 | * The current module file |
||
| 35 | * @var string |
||
| 36 | */ |
||
| 37 | protected $data_file; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * The current file extension |
||
| 41 | * @var string |
||
| 42 | */ |
||
| 43 | protected $data_extension; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @param EditorModel $editor |
||
| 47 | */ |
||
| 48 | public function __construct(EditorModel $editor) |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Route callback to display the select theme page |
||
| 57 | */ |
||
| 58 | public function themeEditor() |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Set title on the select theme page |
||
| 68 | */ |
||
| 69 | protected function setTitleThemeEditor() |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Set breadcrumbs on the select theme page |
||
| 76 | */ |
||
| 77 | protected function setBreadcrumbThemeEditor() |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Output rendered templates on the select theme page |
||
| 96 | */ |
||
| 97 | protected function outputThemeEditor() |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Route callback |
||
| 104 | * Displays the module file overview page |
||
| 105 | * @param integer $module_id |
||
| 106 | */ |
||
| 107 | public function listEditor($module_id) |
||
| 118 | |||
| 119 | /** |
||
| 120 | * Returns an array of module data |
||
| 121 | * @param string $module_id |
||
| 122 | */ |
||
| 123 | protected function setModuleEditor($module_id) |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Returns an array of files to edit |
||
| 138 | * @return array |
||
| 139 | */ |
||
| 140 | protected function getFilesEditor() |
||
| 145 | |||
| 146 | /** |
||
| 147 | * Prepares an array of files to be edited |
||
| 148 | * @param array $data |
||
| 149 | * @return array |
||
| 150 | */ |
||
| 151 | protected function prepareFilesEditor(array $data) |
||
| 180 | |||
| 181 | /** |
||
| 182 | * Sets title on theme files overview page |
||
| 183 | */ |
||
| 184 | protected function setTitleListEditor() |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Sets breadcrumbs on theme files overview page |
||
| 192 | */ |
||
| 193 | protected function setBreadcrumbListEditor() |
||
| 209 | |||
| 210 | /** |
||
| 211 | * Renders templates of theme files overview page |
||
| 212 | */ |
||
| 213 | protected function outputListEditor() |
||
| 217 | |||
| 218 | /** |
||
| 219 | * Route callback |
||
| 220 | * Displays the file edit page |
||
| 221 | * @param string $module_id |
||
| 222 | * @param string $file_id |
||
| 223 | */ |
||
| 224 | public function editEditor($module_id, $file_id) |
||
| 241 | |||
| 242 | /** |
||
| 243 | * Sets messages on the file edit page |
||
| 244 | */ |
||
| 245 | protected function setMessageEditEditor() |
||
| 258 | |||
| 259 | /** |
||
| 260 | * Sets JavaScript settings on the file edit page |
||
| 261 | */ |
||
| 262 | protected function setJsSettingsEditor() |
||
| 271 | |||
| 272 | /** |
||
| 273 | * Saves an array of submitted data |
||
| 274 | */ |
||
| 275 | protected function submitEditor() |
||
| 281 | |||
| 282 | /** |
||
| 283 | * Validates a submitted data when editing a theme file |
||
| 284 | * @return bool |
||
| 285 | */ |
||
| 286 | protected function validateEditor() |
||
| 298 | |||
| 299 | /** |
||
| 300 | * Validate syntax of a submitted file |
||
| 301 | */ |
||
| 302 | protected function validateSyntaxEditor() |
||
| 319 | |||
| 320 | /** |
||
| 321 | * Writes a submitted content to a theme file |
||
| 322 | */ |
||
| 323 | protected function saveEditor() |
||
| 337 | |||
| 338 | /** |
||
| 339 | * Whether the current user can save the file |
||
| 340 | */ |
||
| 341 | protected function canSaveEditor() |
||
| 345 | |||
| 346 | /** |
||
| 347 | * Controls permissions to save a theme file for the current user |
||
| 348 | */ |
||
| 349 | protected function controlAccessSaveEditor() |
||
| 355 | |||
| 356 | /** |
||
| 357 | * Sets titles on the file edit page |
||
| 358 | */ |
||
| 359 | protected function setTitleEditEditor() |
||
| 364 | |||
| 365 | /** |
||
| 366 | * Sets breadcrumbs on the file edit page |
||
| 367 | */ |
||
| 368 | protected function setBreadcrumbEditEditor() |
||
| 394 | |||
| 395 | /** |
||
| 396 | * Renders the file edit page |
||
| 397 | */ |
||
| 398 | protected function outputEditEditor() |
||
| 402 | |||
| 403 | /** |
||
| 404 | * Returns a path to the file to be edited |
||
| 405 | * @param string $encoded_filename URL encoded base64 hash |
||
| 406 | */ |
||
| 407 | protected function setFilePathEditor($encoded_filename) |
||
| 418 | |||
| 419 | } |
||
| 420 |