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.101.1'; |
||
| 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() |
||
| 223 | |||
| 224 | /** |
||
| 225 | * Search for magento root folder |
||
| 226 | * |
||
| 227 | * @param InputInterface $input [optional] |
||
| 228 | * @param OutputInterface $output [optional] |
||
| 229 | * @return void |
||
| 230 | */ |
||
| 231 | public function detectMagento(InputInterface $input = null, OutputInterface $output = null) |
||
| 270 | |||
| 271 | /** |
||
| 272 | * Add own helpers to helperset. |
||
| 273 | * |
||
| 274 | * @return void |
||
| 275 | */ |
||
| 276 | protected function registerHelpers() |
||
| 296 | |||
| 297 | /** |
||
| 298 | * @param InputInterface $input |
||
| 299 | * |
||
| 300 | * @return ArgvInput|InputInterface |
||
| 301 | */ |
||
| 302 | protected function checkConfigCommandAlias(InputInterface $input) |
||
| 308 | |||
| 309 | /** |
||
| 310 | * @param Command $command |
||
| 311 | */ |
||
| 312 | protected function registerConfigCommandAlias(Command $command) |
||
| 318 | |||
| 319 | /** |
||
| 320 | * Adds autoloader prefixes from user's config |
||
| 321 | */ |
||
| 322 | protected function registerCustomAutoloaders() |
||
| 328 | |||
| 329 | /** |
||
| 330 | * @return bool |
||
| 331 | */ |
||
| 332 | protected function hasCustomCommands() |
||
| 338 | |||
| 339 | /** |
||
| 340 | * @return void |
||
| 341 | */ |
||
| 342 | protected function registerCustomCommands() |
||
| 348 | |||
| 349 | /** |
||
| 350 | * @param string $class |
||
| 351 | * @return bool |
||
| 352 | */ |
||
| 353 | protected function isCommandDisabled($class) |
||
| 361 | |||
| 362 | /** |
||
| 363 | * Override standard command registration. We want alias support. |
||
| 364 | * |
||
| 365 | * @param Command $command |
||
| 366 | * |
||
| 367 | * @return Command |
||
| 368 | */ |
||
| 369 | public function add(Command $command) |
||
| 377 | |||
| 378 | /** |
||
| 379 | * @param bool $mode |
||
| 380 | */ |
||
| 381 | public function setPharMode($mode) |
||
| 385 | |||
| 386 | /** |
||
| 387 | * @return bool |
||
| 388 | */ |
||
| 389 | public function isPharMode() |
||
| 393 | |||
| 394 | /** |
||
| 395 | * @TODO Move logic into "EventSubscriber" |
||
| 396 | * |
||
| 397 | * @param OutputInterface $output |
||
| 398 | * @return null|false |
||
| 399 | */ |
||
| 400 | public function checkVarDir(OutputInterface $output) |
||
| 457 | |||
| 458 | /** |
||
| 459 | * Loads and initializes the Magento application |
||
| 460 | * |
||
| 461 | * @param bool $soft |
||
| 462 | * |
||
| 463 | * @return bool false if magento root folder is not set, true otherwise |
||
| 464 | */ |
||
| 465 | public function initMagento($soft = false) |
||
| 480 | |||
| 481 | /** |
||
| 482 | * @return string |
||
| 483 | */ |
||
| 484 | public function getHelp() |
||
| 488 | |||
| 489 | public function getLongVersion() |
||
| 493 | |||
| 494 | /** |
||
| 495 | * @return boolean |
||
| 496 | */ |
||
| 497 | public function isMagentoEnterprise() |
||
| 501 | |||
| 502 | /** |
||
| 503 | * @return string |
||
| 504 | */ |
||
| 505 | public function getMagentoRootFolder() |
||
| 509 | |||
| 510 | /** |
||
| 511 | * @param string $magentoRootFolder |
||
| 512 | */ |
||
| 513 | public function setMagentoRootFolder($magentoRootFolder) |
||
| 517 | |||
| 518 | /** |
||
| 519 | * @return int |
||
| 520 | */ |
||
| 521 | public function getMagentoMajorVersion() |
||
| 525 | |||
| 526 | /** |
||
| 527 | * @return ClassLoader |
||
| 528 | */ |
||
| 529 | public function getAutoloader() |
||
| 533 | |||
| 534 | /** |
||
| 535 | * @param ClassLoader $autoloader |
||
| 536 | */ |
||
| 537 | public function setAutoloader(ClassLoader $autoloader) |
||
| 541 | |||
| 542 | /** |
||
| 543 | * Get config array |
||
| 544 | * |
||
| 545 | * Specify one key per parameter to traverse the config. Then returns null |
||
| 546 | * if the path of the key(s) can not be obtained. |
||
| 547 | * |
||
| 548 | * @param string|int $key ... (optional) |
||
| 549 | * |
||
| 550 | * @return array|null |
||
| 551 | */ |
||
| 552 | public function getConfig($key = null) |
||
| 569 | |||
| 570 | /** |
||
| 571 | * @param array $config |
||
| 572 | */ |
||
| 573 | public function setConfig($config) |
||
| 577 | |||
| 578 | /** |
||
| 579 | * @return boolean |
||
| 580 | */ |
||
| 581 | public function isMagerunStopFileFound() |
||
| 585 | |||
| 586 | /** |
||
| 587 | * Runs the current application with possible command aliases |
||
| 588 | * |
||
| 589 | * @param InputInterface $input An Input instance |
||
| 590 | * @param OutputInterface $output An Output instance |
||
| 591 | * |
||
| 592 | * @return integer 0 if everything went fine, or an error code |
||
| 593 | */ |
||
| 594 | public function doRun(InputInterface $input, OutputInterface $output) |
||
| 612 | |||
| 613 | /** |
||
| 614 | * @param InputInterface $input [optional] |
||
| 615 | * @param OutputInterface $output [optional] |
||
| 616 | * |
||
| 617 | * @return int |
||
| 618 | */ |
||
| 619 | public function run(InputInterface $input = null, OutputInterface $output = null) |
||
| 651 | |||
| 652 | /** |
||
| 653 | * @param array $initConfig [optional] |
||
| 654 | * @param InputInterface $input [optional] |
||
| 655 | * @param OutputInterface $output [optional] |
||
| 656 | * |
||
| 657 | * @return void |
||
| 658 | */ |
||
| 659 | public function init(array $initConfig = array(), InputInterface $input = null, OutputInterface $output = null) |
||
| 701 | |||
| 702 | /** |
||
| 703 | * @param array $initConfig [optional] |
||
| 704 | * @param InputInterface $input [optional] |
||
| 705 | * @param OutputInterface $output [optional] |
||
| 706 | */ |
||
| 707 | public function reinit($initConfig = array(), InputInterface $input = null, OutputInterface $output = null) |
||
| 715 | |||
| 716 | /** |
||
| 717 | * @return void |
||
| 718 | */ |
||
| 719 | protected function registerEventSubscribers() |
||
| 728 | |||
| 729 | /** |
||
| 730 | * @param InputInterface $input |
||
| 731 | * @return bool |
||
| 732 | * @deprecated 1.97.27 |
||
| 733 | */ |
||
| 734 | protected function _checkSkipConfigOption(InputInterface $input) |
||
| 743 | |||
| 744 | /** |
||
| 745 | * @param InputInterface $input |
||
| 746 | * @return string |
||
| 747 | */ |
||
| 748 | protected function _checkRootDirOption(InputInterface $input) |
||
| 755 | |||
| 756 | /** |
||
| 757 | * Set root dir (chdir()) of magento directory |
||
| 758 | * |
||
| 759 | * @param string $path to Magento directory |
||
| 760 | */ |
||
| 761 | private function setRootDir($path) |
||
| 773 | |||
| 774 | /** |
||
| 775 | * @param bool $soft |
||
| 776 | * |
||
| 777 | * @return void |
||
| 778 | */ |
||
| 779 | protected function _initMagento1($soft = false) |
||
| 796 | |||
| 797 | /** |
||
| 798 | * @return void |
||
| 799 | */ |
||
| 800 | protected function _initMagento2() |
||
| 804 | |||
| 805 | /** |
||
| 806 | * Show a hint that this is Magento incompatible with Magerun and how to obtain the correct Magerun for it |
||
| 807 | * |
||
| 808 | * @param string $version of Magento, "1" or "2", that is incompatible |
||
| 809 | */ |
||
| 810 | private function outputMagerunCompatibilityNotice($version) |
||
| 845 | |||
| 846 | /** |
||
| 847 | * @return EventDispatcher |
||
| 848 | */ |
||
| 849 | public function getDispatcher() |
||
| 853 | |||
| 854 | /** |
||
| 855 | * @param array $initConfig |
||
| 856 | * @param OutputInterface $output |
||
| 857 | * @return ConfigurationLoader |
||
| 858 | */ |
||
| 859 | public function getConfigurationLoader(array $initConfig, OutputInterface $output) |
||
| 873 | |||
| 874 | /** |
||
| 875 | * @param ConfigurationLoader $configurationLoader |
||
| 876 | * |
||
| 877 | * @return $this |
||
| 878 | */ |
||
| 879 | public function setConfigurationLoader(ConfigurationLoader $configurationLoader) |
||
| 891 | |||
| 892 | /** |
||
| 893 | * @param OutputInterface $output |
||
| 894 | */ |
||
| 895 | protected function _addOutputStyles(OutputInterface $output) |
||
| 900 | } |
||
| 901 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.