Complex classes like Application 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 Application, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 29 | class Application extends BaseApplication |
||
| 30 | { |
||
| 31 | /** |
||
| 32 | * @var string |
||
| 33 | */ |
||
| 34 | const APP_NAME = 'n98-magerun'; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var string |
||
| 38 | */ |
||
| 39 | const APP_VERSION = '1.98.0'; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var int |
||
| 43 | */ |
||
| 44 | const MAGENTO_MAJOR_VERSION_1 = 1; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var int |
||
| 48 | */ |
||
| 49 | const MAGENTO_MAJOR_VERSION_2 = 2; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @var string |
||
| 53 | */ |
||
| 54 | private static $logo = " |
||
| 55 | ___ ___ |
||
| 56 | _ _/ _ ( _ )___ _ __ __ _ __ _ ___ _ _ _ _ _ _ |
||
| 57 | | ' \\_, / _ \\___| ' \\/ _` / _` / -_) '_| || | ' \\ |
||
| 58 | |_||_/_/\\___/ |_|_|_\\__,_\\__, \\___|_| \\_,_|_||_| |
||
| 59 | |___/ |
||
| 60 | "; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Shadow copy of the Application parent when using this concrete setAutoExit() implementation |
||
| 64 | * |
||
| 65 | * @see \Symfony\Component\Console\Application::$autoExit |
||
| 66 | * @var bool |
||
| 67 | */ |
||
| 68 | private $autoExitShadow = true; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @var ClassLoader |
||
| 72 | */ |
||
| 73 | protected $autoloader; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @var Config |
||
| 77 | */ |
||
| 78 | protected $config; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @see \N98\Magento\Application::setConfigurationLoader() |
||
| 82 | * @var ConfigurationLoader |
||
| 83 | */ |
||
| 84 | private $configurationLoaderInjected; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @var string |
||
| 88 | */ |
||
| 89 | protected $_magentoRootFolder = null; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @var bool |
||
| 93 | */ |
||
| 94 | protected $_magentoEnterprise = false; |
||
| 95 | |||
| 96 | /** |
||
| 97 | * @var int |
||
| 98 | */ |
||
| 99 | protected $_magentoMajorVersion = self::MAGENTO_MAJOR_VERSION_1; |
||
| 100 | |||
| 101 | /** |
||
| 102 | * @var EntryPoint |
||
| 103 | */ |
||
| 104 | protected $_magento2EntryPoint = null; |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @var bool |
||
| 108 | */ |
||
| 109 | protected $_isPharMode = false; |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @var bool |
||
| 113 | */ |
||
| 114 | protected $_magerunStopFileFound = false; |
||
| 115 | |||
| 116 | /** |
||
| 117 | * @var string |
||
| 118 | */ |
||
| 119 | protected $_magerunStopFileFolder = null; |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @var null |
||
| 123 | */ |
||
| 124 | protected $_magerunUseDeveloperMode = null; |
||
| 125 | |||
| 126 | /** |
||
| 127 | * @var bool |
||
| 128 | */ |
||
| 129 | protected $_isInitialized = false; |
||
| 130 | |||
| 131 | /** |
||
| 132 | * @var EventDispatcher |
||
| 133 | */ |
||
| 134 | protected $dispatcher; |
||
| 135 | |||
| 136 | /** |
||
| 137 | * If root dir is set by root-dir option this flag is true |
||
| 138 | * |
||
| 139 | * @var bool |
||
| 140 | */ |
||
| 141 | protected $_directRootDir = false; |
||
| 142 | |||
| 143 | /** |
||
| 144 | * @var bool |
||
| 145 | */ |
||
| 146 | protected $_magentoDetected = false; |
||
| 147 | |||
| 148 | /** |
||
| 149 | * @param ClassLoader $autoloader |
||
| 150 | */ |
||
| 151 | public function __construct($autoloader = null) |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @param bool $boolean |
||
| 159 | * @return bool previous auto-exit state |
||
| 160 | */ |
||
| 161 | public function setAutoExit($boolean) |
||
| 169 | |||
| 170 | /** |
||
| 171 | * @return InputDefinition |
||
| 172 | */ |
||
| 173 | protected function getDefaultInputDefinition() |
||
| 224 | |||
| 225 | /** |
||
| 226 | * Search for magento root folder |
||
| 227 | * |
||
| 228 | * @param InputInterface $input [optional] |
||
| 229 | * @param OutputInterface $output [optional] |
||
| 230 | * @return void |
||
| 231 | */ |
||
| 232 | public function detectMagento(InputInterface $input = null, OutputInterface $output = null) |
||
| 271 | |||
| 272 | /** |
||
| 273 | * Add own helpers to helperset. |
||
| 274 | * |
||
| 275 | * @return void |
||
| 276 | */ |
||
| 277 | protected function registerHelpers() |
||
| 297 | |||
| 298 | /** |
||
| 299 | * @param InputInterface $input |
||
| 300 | * |
||
| 301 | * @return ArgvInput|InputInterface |
||
| 302 | */ |
||
| 303 | protected function checkConfigCommandAlias(InputInterface $input) |
||
| 309 | |||
| 310 | /** |
||
| 311 | * @param Command $command |
||
| 312 | */ |
||
| 313 | protected function registerConfigCommandAlias(Command $command) |
||
| 319 | |||
| 320 | /** |
||
| 321 | * Adds autoloader prefixes from user's config |
||
| 322 | */ |
||
| 323 | protected function registerCustomAutoloaders() |
||
| 329 | |||
| 330 | /** |
||
| 331 | * @return bool |
||
| 332 | */ |
||
| 333 | protected function hasCustomCommands() |
||
| 339 | |||
| 340 | /** |
||
| 341 | * @return void |
||
| 342 | */ |
||
| 343 | protected function registerCustomCommands() |
||
| 349 | |||
| 350 | /** |
||
| 351 | * @param string $class |
||
| 352 | * @return bool |
||
| 353 | */ |
||
| 354 | protected function isCommandDisabled($class) |
||
| 362 | |||
| 363 | /** |
||
| 364 | * Override standard command registration. We want alias support. |
||
| 365 | * |
||
| 366 | * @param Command $command |
||
| 367 | * |
||
| 368 | * @return Command |
||
| 369 | */ |
||
| 370 | public function add(Command $command) |
||
| 378 | |||
| 379 | /** |
||
| 380 | * @param bool $mode |
||
| 381 | */ |
||
| 382 | public function setPharMode($mode) |
||
| 386 | |||
| 387 | /** |
||
| 388 | * @return bool |
||
| 389 | */ |
||
| 390 | public function isPharMode() |
||
| 394 | |||
| 395 | /** |
||
| 396 | * @TODO Move logic into "EventSubscriber" |
||
| 397 | * |
||
| 398 | * @param OutputInterface $output |
||
| 399 | * @return null|false |
||
| 400 | */ |
||
| 401 | public function checkVarDir(OutputInterface $output) |
||
| 458 | |||
| 459 | /** |
||
| 460 | * Loads and initializes the Magento application |
||
| 461 | * |
||
| 462 | * @param bool $soft |
||
| 463 | * |
||
| 464 | * @return bool false if magento root folder is not set, true otherwise |
||
| 465 | */ |
||
| 466 | public function initMagento($soft = false) |
||
| 481 | |||
| 482 | /** |
||
| 483 | * @return string |
||
| 484 | */ |
||
| 485 | public function getHelp() |
||
| 489 | |||
| 490 | public function getLongVersion() |
||
| 494 | |||
| 495 | /** |
||
| 496 | * @return boolean |
||
| 497 | */ |
||
| 498 | public function isMagentoEnterprise() |
||
| 502 | |||
| 503 | /** |
||
| 504 | * @return string |
||
| 505 | */ |
||
| 506 | public function getMagentoRootFolder() |
||
| 510 | |||
| 511 | /** |
||
| 512 | * @param string $magentoRootFolder |
||
| 513 | */ |
||
| 514 | public function setMagentoRootFolder($magentoRootFolder) |
||
| 518 | |||
| 519 | /** |
||
| 520 | * @return int |
||
| 521 | */ |
||
| 522 | public function getMagentoMajorVersion() |
||
| 526 | |||
| 527 | /** |
||
| 528 | * @return ClassLoader |
||
| 529 | */ |
||
| 530 | public function getAutoloader() |
||
| 534 | |||
| 535 | /** |
||
| 536 | * @param ClassLoader $autoloader |
||
| 537 | */ |
||
| 538 | public function setAutoloader(ClassLoader $autoloader) |
||
| 542 | |||
| 543 | /** |
||
| 544 | * Get config array |
||
| 545 | * |
||
| 546 | * Specify one key per parameter to traverse the config. Then returns null |
||
| 547 | * if the path of the key(s) can not be obtained. |
||
| 548 | * |
||
| 549 | * @param string|int $key ... (optional) |
||
| 550 | * |
||
| 551 | * @return array|null |
||
| 552 | */ |
||
| 553 | public function getConfig($key = null) |
||
| 570 | |||
| 571 | /** |
||
| 572 | * @param array $config |
||
| 573 | */ |
||
| 574 | public function setConfig($config) |
||
| 578 | |||
| 579 | /** |
||
| 580 | * @return boolean |
||
| 581 | */ |
||
| 582 | public function isMagerunStopFileFound() |
||
| 586 | |||
| 587 | /** |
||
| 588 | * Runs the current application with possible command aliases |
||
| 589 | * |
||
| 590 | * @param InputInterface $input An Input instance |
||
| 591 | * @param OutputInterface $output An Output instance |
||
| 592 | * |
||
| 593 | * @return integer 0 if everything went fine, or an error code |
||
| 594 | */ |
||
| 595 | public function doRun(InputInterface $input, OutputInterface $output) |
||
| 613 | |||
| 614 | /** |
||
| 615 | * @param InputInterface $input [optional] |
||
| 616 | * @param OutputInterface $output [optional] |
||
| 617 | * |
||
| 618 | * @return int |
||
| 619 | */ |
||
| 620 | public function run(InputInterface $input = null, OutputInterface $output = null) |
||
| 652 | |||
| 653 | /** |
||
| 654 | * @param array $initConfig [optional] |
||
| 655 | * @param InputInterface $input [optional] |
||
| 656 | * @param OutputInterface $output [optional] |
||
| 657 | * |
||
| 658 | * @return void |
||
| 659 | */ |
||
| 660 | public function init(array $initConfig = array(), InputInterface $input = null, OutputInterface $output = null) |
||
| 702 | |||
| 703 | /** |
||
| 704 | * @param array $initConfig [optional] |
||
| 705 | * @param InputInterface $input [optional] |
||
| 706 | * @param OutputInterface $output [optional] |
||
| 707 | */ |
||
| 708 | public function reinit($initConfig = array(), InputInterface $input = null, OutputInterface $output = null) |
||
| 716 | |||
| 717 | /** |
||
| 718 | * @return void |
||
| 719 | */ |
||
| 720 | protected function registerEventSubscribers() |
||
| 729 | |||
| 730 | /** |
||
| 731 | * @param InputInterface $input |
||
| 732 | * @return bool |
||
| 733 | * @deprecated 1.97.27 |
||
| 734 | */ |
||
| 735 | protected function _checkSkipConfigOption(InputInterface $input) |
||
| 744 | |||
| 745 | /** |
||
| 746 | * @param InputInterface $input |
||
| 747 | * @return string |
||
| 748 | */ |
||
| 749 | protected function _checkRootDirOption(InputInterface $input) |
||
| 756 | |||
| 757 | /** |
||
| 758 | * Set root dir (chdir()) of magento directory |
||
| 759 | * |
||
| 760 | * @param string $path to Magento directory |
||
| 761 | */ |
||
| 762 | private function setRootDir($path) |
||
| 774 | |||
| 775 | /** |
||
| 776 | * @param bool $soft |
||
| 777 | * |
||
| 778 | * @return void |
||
| 779 | */ |
||
| 780 | protected function _initMagento1($soft = false) |
||
| 797 | |||
| 798 | /** |
||
| 799 | * @return void |
||
| 800 | */ |
||
| 801 | protected function _initMagento2() |
||
| 805 | |||
| 806 | /** |
||
| 807 | * Show a hint that this is Magento incompatible with Magerun and how to obtain the correct Magerun for it |
||
| 808 | * |
||
| 809 | * @param string $version of Magento, "1" or "2", that is incompatible |
||
| 810 | */ |
||
| 811 | private function outputMagerunCompatibilityNotice($version) |
||
| 846 | |||
| 847 | /** |
||
| 848 | * @return EventDispatcher |
||
| 849 | */ |
||
| 850 | public function getDispatcher() |
||
| 854 | |||
| 855 | /** |
||
| 856 | * @param array $initConfig |
||
| 857 | * @param OutputInterface $output |
||
| 858 | * @return ConfigurationLoader |
||
| 859 | */ |
||
| 860 | public function getConfigurationLoader(array $initConfig, OutputInterface $output) |
||
| 874 | |||
| 875 | /** |
||
| 876 | * @param ConfigurationLoader $configurationLoader |
||
| 877 | * |
||
| 878 | * @return $this |
||
| 879 | */ |
||
| 880 | public function setConfigurationLoader(ConfigurationLoader $configurationLoader) |
||
| 892 | |||
| 893 | /** |
||
| 894 | * @param OutputInterface $output |
||
| 895 | */ |
||
| 896 | protected function _addOutputStyles(OutputInterface $output) |
||
| 901 | } |
||
| 902 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.