Conditions | 8 |
Paths | 120 |
Total Lines | 91 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
86 | protected function execute(InputInterface $input, OutputInterface $output) |
||
87 | { |
||
88 | $initialized = false; |
||
89 | try { |
||
90 | $this->detectMagento($output); |
||
91 | $initialized = $this->initMagento(); |
||
92 | } catch (Exception $e) { |
||
93 | // do nothing |
||
94 | } |
||
95 | |||
96 | $config = new Configuration(); |
||
97 | |||
98 | $php5Parser = new Parser\Php5(new Lexer\Emulative()); |
||
99 | $php7Parser = new Parser\Php7(new Lexer\Emulative()); |
||
100 | |||
101 | $parser = new Parser\Multiple([$php5Parser, $php7Parser]); |
||
102 | $cleaner = new CodeCleaner($parser); |
||
103 | $config->setCodeCleaner($cleaner); |
||
104 | |||
105 | $consoleOutput = new ShellOutput(); |
||
106 | |||
107 | $commandConfig = $this->getCommandConfig(); |
||
108 | $commandsToAdd = []; |
||
109 | foreach ($commandConfig['commands'] as $command) { |
||
110 | $commandsToAdd[] = new $command(); |
||
111 | } |
||
112 | |||
113 | $config->addCommands($commandsToAdd); |
||
114 | |||
115 | $shell = new Shell($config); |
||
116 | $shell->setScopeVariables([ |
||
117 | 'di' => $this->getObjectManager(), |
||
118 | 'magentoVersion' => $this->getObjectManager()->get(ProductMetadataInterface::class), |
||
119 | 'magerun' => $this->getApplication(), |
||
120 | 'magerunInternal' => (object) ['currentModule' => ''], |
||
121 | ]); |
||
122 | |||
123 | if ($initialized) { |
||
124 | $ok = Charset::convertInteger(Charset::UNICODE_CHECKMARK_CHAR); |
||
125 | |||
126 | $areaToLoad = $input->getOption('area'); |
||
127 | |||
128 | if ($areaToLoad) { |
||
129 | $this->loadArea($areaToLoad); |
||
130 | } |
||
131 | |||
132 | $edition = $this->productMeta->getEdition(); |
||
133 | $magentoVersion = $this->productMeta->getVersion(); |
||
134 | |||
135 | $statusMessage = sprintf( |
||
136 | '<fg=black;bg=green>Magento %s %s initialized %s</fg=black;bg=green>', |
||
137 | $magentoVersion, |
||
138 | $edition, |
||
139 | $ok |
||
140 | ); |
||
141 | |||
142 | $consoleOutput->writeln($statusMessage); |
||
143 | |||
144 | if ($areaToLoad) { |
||
145 | $areaMessage = sprintf( |
||
146 | '<fg=black;bg=white>Area: %s</fg=black;bg=white>', |
||
147 | $this->appState->getAreaCode() |
||
148 | ); |
||
149 | $consoleOutput->writeln($areaMessage); |
||
150 | } |
||
151 | } else { |
||
152 | $consoleOutput->writeln('<fg=black;bg=yellow>Magento is not initialized.</fg=black;bg=yellow>'); |
||
153 | } |
||
154 | |||
155 | $help = <<<'help' |
||
156 | At the prompt, type <comment>help</comment> for some help. |
||
157 | |||
158 | To exit the shell, type <comment>^D</comment>. |
||
159 | help; |
||
160 | |||
161 | $consoleOutput->writeln($help); |
||
162 | |||
163 | $cmd = $input->getArgument('cmd'); |
||
164 | |||
165 | if ($cmd === '-') { |
||
166 | $cmd = 'php://stdin'; |
||
167 | $cmd = @\file_get_contents($cmd); |
||
168 | } |
||
169 | |||
170 | if (!empty($cmd)) { |
||
171 | $code = preg_split('/[\n;]+/', $cmd); |
||
172 | $shell->addInput($code); |
||
173 | } |
||
174 | |||
175 | $shell->run($input, $consoleOutput); |
||
176 | } |
||
177 | |||
197 |