Complex classes like Translator 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 Translator, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 19 | class Translator extends BackendController |
||
| 20 | { |
||
| 21 | |||
| 22 | /** |
||
| 23 | * File model class instance |
||
| 24 | * @var \gplcart\core\models\File $file |
||
| 25 | */ |
||
| 26 | protected $file; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Translator model class instance |
||
| 30 | * @var \gplcart\modules\translator\models\Translator $translator |
||
| 31 | */ |
||
| 32 | protected $translator; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * The current translation file |
||
| 36 | * @var string |
||
| 37 | */ |
||
| 38 | protected $data_file; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * An array of translation strings |
||
| 42 | * @var array |
||
| 43 | */ |
||
| 44 | protected $data_content; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * The current language |
||
| 48 | * @var array |
||
| 49 | */ |
||
| 50 | protected $data_language; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @param FileModel $file |
||
| 54 | * @param TranslatorModuleModel $translator |
||
| 55 | */ |
||
| 56 | public function __construct(FileModel $file, |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Displays the language list page |
||
| 67 | */ |
||
| 68 | public function languageTranslator() |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Returns an array of sorted languages |
||
| 80 | * @return array |
||
| 81 | */ |
||
| 82 | protected function getLanguagesTranslator() |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Set titles on the language list page |
||
| 91 | */ |
||
| 92 | protected function setTitleLanguageTranslator() |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Sets breadcrumbs on the language list page |
||
| 99 | */ |
||
| 100 | protected function setBreadcrumbLanguageTranslator() |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Render and output the language list page |
||
| 107 | */ |
||
| 108 | protected function outputLanguageTranslator() |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Displays the file overview page |
||
| 115 | * @param string $langcode |
||
| 116 | */ |
||
| 117 | public function filesTranslator($langcode) |
||
| 132 | |||
| 133 | /** |
||
| 134 | * Download a translation file |
||
| 135 | */ |
||
| 136 | protected function downloadFileTranslator() |
||
| 146 | |||
| 147 | /** |
||
| 148 | * Returns an array of file |
||
| 149 | * @param string $hash |
||
| 150 | * @return array |
||
| 151 | */ |
||
| 152 | protected function getDownloadFileTranslator($hash) |
||
| 169 | |||
| 170 | /** |
||
| 171 | * Parses a hash string containing module ID and translation file |
||
| 172 | * @param string $hash |
||
| 173 | * @return array |
||
| 174 | */ |
||
| 175 | protected function parseHashTranslator($hash) |
||
| 204 | |||
| 205 | /** |
||
| 206 | * Applies an action to the selected translation files |
||
| 207 | */ |
||
| 208 | protected function actionFilesTranslator() |
||
| 224 | |||
| 225 | /** |
||
| 226 | * Deletes a translation file |
||
| 227 | * @param string $id |
||
| 228 | * @return boolean |
||
| 229 | */ |
||
| 230 | protected function deleteFileTranslator($id) |
||
| 240 | |||
| 241 | /** |
||
| 242 | * Returns an array of files for the language |
||
| 243 | * @return array |
||
| 244 | */ |
||
| 245 | protected function getFilesTranslator() |
||
| 253 | |||
| 254 | /** |
||
| 255 | * Sets titles on the file overview page |
||
| 256 | */ |
||
| 257 | protected function setTitleFilesTranslator() |
||
| 262 | |||
| 263 | /** |
||
| 264 | * Sets breadcrumbs on the files overview page |
||
| 265 | */ |
||
| 266 | protected function setBreadcrumbFilesTranslator() |
||
| 282 | |||
| 283 | /** |
||
| 284 | * Displays the upload translation page |
||
| 285 | * @param string $langcode |
||
| 286 | */ |
||
| 287 | public function uploadTranslator($langcode) |
||
| 301 | |||
| 302 | /** |
||
| 303 | * Controls access to upload a translation file |
||
| 304 | */ |
||
| 305 | protected function controlAccessUploadTranslator() |
||
| 310 | |||
| 311 | /** |
||
| 312 | * Sets titles on the upload translation page |
||
| 313 | */ |
||
| 314 | protected function setTitleUploadTranslator() |
||
| 319 | |||
| 320 | /** |
||
| 321 | * Sets breadcrumbs on the upload translation page |
||
| 322 | */ |
||
| 323 | protected function setBreadcrumbUploadTranslator() |
||
| 344 | |||
| 345 | /** |
||
| 346 | * Handles submission of translation file |
||
| 347 | */ |
||
| 348 | protected function submitUploadTranslator() |
||
| 354 | |||
| 355 | /** |
||
| 356 | * Validates a uploaded translation file |
||
| 357 | * @return boolean |
||
| 358 | */ |
||
| 359 | protected function validateUploadTranslator() |
||
| 368 | |||
| 369 | /** |
||
| 370 | * Validates scope of uploaded file |
||
| 371 | * @return boolean |
||
| 372 | */ |
||
| 373 | protected function validateUploadScopeTranslator() |
||
| 385 | |||
| 386 | /** |
||
| 387 | * Validates uploaded translation file |
||
| 388 | * @return boolean|null |
||
| 389 | */ |
||
| 390 | protected function validateUploadFileTranslator() |
||
| 413 | |||
| 414 | /** |
||
| 415 | * Copy a uploaded translation |
||
| 416 | */ |
||
| 417 | protected function copyFileTranslator() |
||
| 431 | |||
| 432 | /** |
||
| 433 | * Render and output the upload translation page |
||
| 434 | */ |
||
| 435 | protected function outputUploadTranslator() |
||
| 439 | |||
| 440 | /** |
||
| 441 | * Render and output the file overview page |
||
| 442 | */ |
||
| 443 | protected function outputFilesTranslator() |
||
| 447 | |||
| 448 | /** |
||
| 449 | * Returns an array of primary translations |
||
| 450 | * @return array |
||
| 451 | */ |
||
| 452 | protected function getPrimaryFilesTranslator() |
||
| 470 | |||
| 471 | /** |
||
| 472 | * Returns an array of compiled translation files |
||
| 473 | * @return array |
||
| 474 | */ |
||
| 475 | protected function getCompiledFilesTranslator() |
||
| 488 | |||
| 489 | /** |
||
| 490 | * Build translation file info |
||
| 491 | * @param string $file |
||
| 492 | * @return array |
||
| 493 | */ |
||
| 494 | protected function buildFileInfoTranslator($file) |
||
| 520 | |||
| 521 | /** |
||
| 522 | * Sets the current language |
||
| 523 | * @param string $langcode |
||
| 524 | */ |
||
| 525 | protected function setLanguageTranslator($langcode) |
||
| 533 | |||
| 534 | /** |
||
| 535 | * Displays list of translation files available for import |
||
| 536 | * @param string $langcode |
||
| 537 | */ |
||
| 538 | public function listImportTranslator($langcode) |
||
| 557 | |||
| 558 | /** |
||
| 559 | * Handles submitted import |
||
| 560 | */ |
||
| 561 | protected function submitImportTranslator() |
||
| 570 | |||
| 571 | /** |
||
| 572 | * Bulk actions for selected translations |
||
| 573 | */ |
||
| 574 | protected function actionImportTranslator() |
||
| 600 | |||
| 601 | /** |
||
| 602 | * Sets titles on the translation list page |
||
| 603 | */ |
||
| 604 | protected function setTitleListImportTranslator() |
||
| 609 | |||
| 610 | /** |
||
| 611 | * Sets breadcrumbs on the translation list page |
||
| 612 | */ |
||
| 613 | protected function setBreadcrumbListImportTranslator() |
||
| 629 | |||
| 630 | /** |
||
| 631 | * Render and output the translation list page |
||
| 632 | */ |
||
| 633 | protected function outputListImportTranslator() |
||
| 637 | |||
| 638 | /** |
||
| 639 | * Displays the translation view page |
||
| 640 | * @param string $langcode |
||
| 641 | * @param string $id |
||
| 642 | */ |
||
| 643 | public function viewTranslator($langcode, $id) |
||
| 655 | |||
| 656 | /** |
||
| 657 | * Read content from ZIP file |
||
| 658 | * @param string $hash |
||
| 659 | */ |
||
| 660 | protected function setContentTranslator($hash) |
||
| 686 | |||
| 687 | /** |
||
| 688 | * Sets titles on the translation view page |
||
| 689 | */ |
||
| 690 | protected function setTitleViewTranslator() |
||
| 695 | |||
| 696 | /** |
||
| 697 | * Sets breadcrumbs on the translation view page |
||
| 698 | */ |
||
| 699 | protected function setBreadcrumbViewTranslator() |
||
| 720 | |||
| 721 | /** |
||
| 722 | * Render and output the translation view page |
||
| 723 | */ |
||
| 724 | protected function outputViewTranslator() |
||
| 728 | |||
| 729 | } |
||
| 730 |