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() |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Set titles on the language list page |
||
| 77 | */ |
||
| 78 | protected function setTitleLanguageTranslator() |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Sets breadcrumbs on the language list page |
||
| 85 | */ |
||
| 86 | protected function setBreadcrumbLanguageTranslator() |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Render and output the language list page |
||
| 93 | */ |
||
| 94 | protected function outputLanguageTranslator() |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Displays the file overview page |
||
| 101 | * @param string $langcode |
||
| 102 | */ |
||
| 103 | public function filesTranslator($langcode) |
||
| 118 | |||
| 119 | /** |
||
| 120 | * Download a translation file |
||
| 121 | */ |
||
| 122 | protected function downloadFileTranslator() |
||
| 132 | |||
| 133 | /** |
||
| 134 | * Returns an array of file |
||
| 135 | * @param string $hash |
||
| 136 | * @return array |
||
| 137 | */ |
||
| 138 | protected function getDownloadFileTranslator($hash) |
||
| 155 | |||
| 156 | /** |
||
| 157 | * Parses a hash string containing module ID and translation file |
||
| 158 | * @param string $hash |
||
| 159 | * @return boolean |
||
| 160 | */ |
||
| 161 | protected function parseHashTranslator($hash) |
||
| 190 | |||
| 191 | /** |
||
| 192 | * Applies an action to the selected translation files |
||
| 193 | */ |
||
| 194 | protected function actionFilesTranslator() |
||
| 210 | |||
| 211 | /** |
||
| 212 | * Deletes a translation file |
||
| 213 | * @param string $id |
||
| 214 | * @return boolean |
||
| 215 | */ |
||
| 216 | protected function deleteFileTranslator($id) |
||
| 226 | |||
| 227 | /** |
||
| 228 | * Returns an array of files for the language |
||
| 229 | * @return array |
||
| 230 | */ |
||
| 231 | protected function getFilesTranslator() |
||
| 239 | |||
| 240 | /** |
||
| 241 | * Sets titles on the file overview page |
||
| 242 | */ |
||
| 243 | protected function setTitleFilesTranslator() |
||
| 248 | |||
| 249 | /** |
||
| 250 | * Sets breadcrumbs on the files overview page |
||
| 251 | */ |
||
| 252 | protected function setBreadcrumbFilesTranslator() |
||
| 268 | |||
| 269 | /** |
||
| 270 | * Displays the upload translation page |
||
| 271 | * @param string $langcode |
||
| 272 | */ |
||
| 273 | public function uploadTranslator($langcode) |
||
| 287 | |||
| 288 | /** |
||
| 289 | * Controls access to upload a translation file |
||
| 290 | */ |
||
| 291 | protected function controlAccessUploadTranslator() |
||
| 296 | |||
| 297 | /** |
||
| 298 | * Sets titles on the upload translation page |
||
| 299 | */ |
||
| 300 | protected function setTitleUploadTranslator() |
||
| 305 | |||
| 306 | /** |
||
| 307 | * Sets breadcrumbs on the upload translation page |
||
| 308 | */ |
||
| 309 | protected function setBreadcrumbUploadTranslator() |
||
| 330 | |||
| 331 | /** |
||
| 332 | * Handles submission of translation file |
||
| 333 | */ |
||
| 334 | protected function submitUploadTranslator() |
||
| 340 | |||
| 341 | /** |
||
| 342 | * Validates a uploaded translation file |
||
| 343 | * @return boolean |
||
| 344 | */ |
||
| 345 | protected function validateUploadTranslator() |
||
| 354 | |||
| 355 | /** |
||
| 356 | * Validates scope of uploaded file |
||
| 357 | * @return boolean |
||
| 358 | */ |
||
| 359 | protected function validateUploadScopeTranslator() |
||
| 371 | |||
| 372 | /** |
||
| 373 | * Validates uploaded translation file |
||
| 374 | * @return boolean|null |
||
| 375 | */ |
||
| 376 | protected function validateUploadFileTranslator() |
||
| 399 | |||
| 400 | /** |
||
| 401 | * Copy a uploaded translation |
||
| 402 | */ |
||
| 403 | protected function copyFileTranslator() |
||
| 417 | |||
| 418 | /** |
||
| 419 | * Render and output the upload translation page |
||
| 420 | */ |
||
| 421 | protected function outputUploadTranslator() |
||
| 425 | |||
| 426 | /** |
||
| 427 | * Render and output the file overview page |
||
| 428 | */ |
||
| 429 | protected function outputFilesTranslator() |
||
| 433 | |||
| 434 | /** |
||
| 435 | * Returns an array of primary translations |
||
| 436 | * @return array |
||
| 437 | */ |
||
| 438 | protected function getPrimaryFilesTranslator() |
||
| 456 | |||
| 457 | /** |
||
| 458 | * Returns an array of compiled translation files |
||
| 459 | * @return array |
||
| 460 | */ |
||
| 461 | protected function getCompiledFilesTranslator() |
||
| 474 | |||
| 475 | /** |
||
| 476 | * Build translation file info |
||
| 477 | * @param string $file |
||
| 478 | * @return array |
||
| 479 | */ |
||
| 480 | protected function buildFileInfoTranslator($file) |
||
| 506 | |||
| 507 | /** |
||
| 508 | * Sets the current language |
||
| 509 | * @param string $langcode |
||
| 510 | */ |
||
| 511 | protected function setLanguageTranslator($langcode) |
||
| 519 | |||
| 520 | /** |
||
| 521 | * Displays list of translation files available for import |
||
| 522 | */ |
||
| 523 | public function listImportTranslator($langcode) |
||
| 542 | |||
| 543 | /** |
||
| 544 | * Handles submitted import |
||
| 545 | */ |
||
| 546 | protected function submitImportTranslator() |
||
| 555 | |||
| 556 | /** |
||
| 557 | * Bulk actions for selected translations |
||
| 558 | * @return boolean |
||
| 559 | */ |
||
| 560 | protected function actionImportTranslator() |
||
| 587 | |||
| 588 | /** |
||
| 589 | * Sets titles on the translation list page |
||
| 590 | */ |
||
| 591 | protected function setTitleListImportTranslator() |
||
| 596 | |||
| 597 | /** |
||
| 598 | * Sets breadcrumbs on the translation list page |
||
| 599 | */ |
||
| 600 | protected function setBreadcrumbListImportTranslator() |
||
| 616 | |||
| 617 | /** |
||
| 618 | * Render and output the translation list page |
||
| 619 | */ |
||
| 620 | protected function outputListImportTranslator() |
||
| 624 | |||
| 625 | /** |
||
| 626 | * Displays the translation view page |
||
| 627 | * @param string $langcode |
||
| 628 | * @param string $id |
||
| 629 | */ |
||
| 630 | public function viewTranslator($langcode, $id) |
||
| 642 | |||
| 643 | /** |
||
| 644 | * Read content from ZIP file |
||
| 645 | * @param string $hash |
||
| 646 | */ |
||
| 647 | protected function setContentTranslator($hash) |
||
| 673 | |||
| 674 | /** |
||
| 675 | * Sets titles on the translation view page |
||
| 676 | */ |
||
| 677 | protected function setTitleViewTranslator() |
||
| 682 | |||
| 683 | /** |
||
| 684 | * Sets breadcrumbs on the translation view page |
||
| 685 | */ |
||
| 686 | protected function setBreadcrumbViewTranslator() |
||
| 707 | |||
| 708 | /** |
||
| 709 | * Render and output the translation view page |
||
| 710 | */ |
||
| 711 | protected function outputViewTranslator() |
||
| 715 | |||
| 716 | } |
||
| 717 |