| Conditions | 20 |
| Paths | 28 |
| Total Lines | 139 |
| Code Lines | 85 |
| 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 |
||
| 93 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 94 | { |
||
| 95 | $this->app = $this->getSilexApplication(); |
||
| 96 | $this->app->initialize(); |
||
| 97 | $this->app->boot(); |
||
| 98 | |||
| 99 | $mode = $input->getArgument('mode'); |
||
| 100 | |||
| 101 | // プラグイン作成 |
||
| 102 | if ($mode == 'generate') { |
||
| 103 | $PluginGenerator = new PluginGenerator($this->app); |
||
| 104 | $PluginGenerator->init($this->getHelper('question'), $input, $output); |
||
| 105 | $PluginGenerator->run(); |
||
| 106 | |||
| 107 | return; |
||
| 108 | } |
||
| 109 | // プラグインEntity用作成 |
||
| 110 | if ($mode == 'entity') { |
||
| 111 | $output->writeln(''); |
||
| 112 | $Question = new Question('<comment>[entity]How to generate entities from db schema or yml? [d => db, y => yml] : </comment>', ''); |
||
| 113 | $QuestionHelper = $this->getHelper('question'); |
||
| 114 | $value = $QuestionHelper->ask($input, $output, $Question); |
||
| 115 | $value = substr(strtolower(trim($value)), 0, 1); |
||
| 116 | if ($value == 'd') { |
||
| 117 | $PluginEntityGenerator = new EntityFromDbGenerator($this->app); |
||
| 118 | $PluginEntityGenerator->init($QuestionHelper, $input, $output); |
||
| 119 | $PluginEntityGenerator->run(); |
||
| 120 | } elseif ($value == 'y') { |
||
| 121 | $PluginEntityGenerator = new EntityFromYamlGenerator($this->app); |
||
| 122 | $PluginEntityGenerator->init($QuestionHelper, $input, $output); |
||
| 123 | $PluginEntityGenerator->run(); |
||
| 124 | } else { |
||
| 125 | // 入力値正しくない |
||
| 126 | $output->writeln('Input value is incorrect, please choose [d] for database schema or [y] for yml file.'); |
||
| 127 | } |
||
| 128 | |||
| 129 | return; |
||
| 130 | } |
||
| 131 | $path = $input->getOption('path'); |
||
| 132 | $code = $input->getOption('code'); |
||
| 133 | $uninstallForce = $input->getOption('uninstall-force'); |
||
| 134 | $service = $this->app['eccube.service.plugin']; |
||
| 135 | |||
| 136 | if ($mode == 'install') { |
||
| 137 | // アーカイブからインストール |
||
| 138 | if ($path) { |
||
| 139 | if ($service->install($path)) { |
||
| 140 | $output->writeln('success'); |
||
| 141 | |||
| 142 | return; |
||
| 143 | } |
||
| 144 | } |
||
| 145 | // 設置済ファイルからインストール |
||
| 146 | if ($code) { |
||
| 147 | $pluginDir = $service->calcPluginDir($code); |
||
| 148 | $service->checkPluginArchiveContent($pluginDir); |
||
| 149 | $config = $service->readYml($pluginDir.'/config.yml'); |
||
| 150 | $event = $service->readYml($pluginDir.'/event.yml'); |
||
| 151 | $service->checkSamePlugin($config['code']); |
||
| 152 | $service->registerPlugin($config, $event); |
||
| 153 | |||
| 154 | $output->writeln('success'); |
||
| 155 | |||
| 156 | return; |
||
| 157 | } |
||
| 158 | |||
| 159 | $output->writeln('path or code is required.'); |
||
| 160 | |||
| 161 | return; |
||
| 162 | } |
||
| 163 | if ($mode == 'update') { |
||
| 164 | if (empty($code)) { |
||
| 165 | $output->writeln('code is required.'); |
||
| 166 | |||
| 167 | return; |
||
| 168 | } |
||
| 169 | if (empty($path)) { |
||
| 170 | $output->writeln('path is required.'); |
||
| 171 | |||
| 172 | return; |
||
| 173 | } |
||
| 174 | $plugin = $this->getPluginFromCode($code); |
||
| 175 | if ($service->update($plugin, $path)) { |
||
| 176 | $output->writeln('success'); |
||
| 177 | |||
| 178 | return; |
||
| 179 | } |
||
| 180 | } |
||
| 181 | |||
| 182 | if ($mode == 'uninstall') { |
||
| 183 | if (empty($code)) { |
||
| 184 | $output->writeln('code is required.'); |
||
| 185 | |||
| 186 | return; |
||
| 187 | } |
||
| 188 | |||
| 189 | $plugin = $this->getPluginFromCode($code); |
||
| 190 | |||
| 191 | // ディレクトリも含め全て削除. |
||
| 192 | if ($uninstallForce) { |
||
| 193 | if ($service->uninstall($plugin)) { |
||
| 194 | $output->writeln('success'); |
||
| 195 | |||
| 196 | return; |
||
| 197 | } |
||
| 198 | |||
| 199 | return; |
||
| 200 | } |
||
| 201 | |||
| 202 | // ディレクトリは残し, プラグインを削除. |
||
| 203 | $pluginDir = $service->calcPluginDir($code); |
||
| 204 | $config = $service->readYml($pluginDir.'/config.yml'); |
||
| 205 | $service->callPluginManagerMethod($config, 'disable'); |
||
| 206 | $service->callPluginManagerMethod($config, 'uninstall'); |
||
| 207 | $service->unregisterPlugin($plugin); |
||
| 208 | |||
| 209 | $output->writeln('success'); |
||
| 210 | |||
| 211 | return; |
||
| 212 | } |
||
| 213 | |||
| 214 | if (in_array($mode, array('enable', 'disable'), true)) { |
||
| 215 | if (empty($code)) { |
||
| 216 | $output->writeln('code is required.'); |
||
| 217 | |||
| 218 | return; |
||
| 219 | } |
||
| 220 | |||
| 221 | $plugin = $this->getPluginFromCode($code); |
||
| 222 | if ($service->$mode($plugin)) { |
||
| 223 | $output->writeln('success'); |
||
| 224 | |||
| 225 | return; |
||
| 226 | } |
||
| 227 | } |
||
| 228 | |||
| 229 | $output->writeln(' mode is not correct, try help for more options'); |
||
| 230 | $output->writeln(' plugin:develop --help '); |
||
| 231 | } |
||
| 232 | |||
| 234 |