| Conditions | 16 |
| Paths | 24 |
| Total Lines | 100 |
| Code Lines | 61 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 64 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 65 | { |
||
| 66 | $this->app->initialize(); |
||
| 67 | $this->app->boot(); |
||
| 68 | |||
| 69 | $mode = $input->getArgument('mode'); |
||
| 70 | $path = $input->getOption('path'); |
||
| 71 | $code = $input->getOption('code'); |
||
| 72 | $uninstallForce = $input->getOption('uninstall-force'); |
||
| 73 | |||
| 74 | $service = $this->app['eccube.service.plugin']; |
||
| 75 | |||
| 76 | if ($mode == 'install') { |
||
| 77 | // アーカイブからインストール |
||
| 78 | if ($path) { |
||
| 79 | if ($service->install($path)) { |
||
| 80 | $output->writeln('success'); |
||
| 81 | |||
| 82 | return; |
||
| 83 | } |
||
| 84 | } |
||
| 85 | // 設置済ファイルからインストール |
||
| 86 | if ($code) { |
||
| 87 | $pluginDir = $service->calcPluginDir($code); |
||
| 88 | $service->checkPluginArchiveContent($pluginDir); |
||
| 89 | $config = $service->readYml($pluginDir.'/config.yml'); |
||
| 90 | $event = $service->readYml($pluginDir.'/event.yml'); |
||
| 91 | $service->checkSamePlugin($config['code']); |
||
| 92 | $service->registerPlugin($config, $event); |
||
| 93 | |||
| 94 | $output->writeln('success'); |
||
| 95 | |||
| 96 | return; |
||
| 97 | } |
||
| 98 | |||
| 99 | $output->writeln('path or code is required.'); |
||
| 100 | |||
| 101 | return; |
||
| 102 | } |
||
| 103 | if ($mode == 'update') { |
||
| 104 | if (empty($code)) { |
||
| 105 | $output->writeln('code is required.'); |
||
| 106 | return; |
||
| 107 | } |
||
| 108 | if (empty($path)) { |
||
| 109 | $output->writeln('path is required.'); |
||
| 110 | return; |
||
| 111 | } |
||
| 112 | $plugin = $this->getPluginFromCode($code); |
||
| 113 | if ($service->update($plugin, $path)) { |
||
| 114 | $output->writeln('success'); |
||
| 115 | return; |
||
| 116 | } |
||
| 117 | } |
||
| 118 | |||
| 119 | if ($mode == 'uninstall') { |
||
| 120 | if (empty($code)) { |
||
| 121 | $output->writeln('code is required.'); |
||
| 122 | return; |
||
| 123 | } |
||
| 124 | |||
| 125 | $plugin = $this->getPluginFromCode($code); |
||
| 126 | |||
| 127 | // ディレクトリも含め全て削除. |
||
| 128 | if ($uninstallForce) { |
||
| 129 | |||
| 130 | if ($service->uninstall($plugin)) { |
||
| 131 | $output->writeln('success'); |
||
| 132 | return; |
||
| 133 | } |
||
| 134 | |||
| 135 | return; |
||
| 136 | } |
||
| 137 | |||
| 138 | // ディレクトリは残し, プラグインを削除. |
||
| 139 | $pluginDir = $service->calcPluginDir($code); |
||
| 140 | $config = $service->readYml($pluginDir.'/config.yml'); |
||
| 141 | $service->callPluginManagerMethod($config, 'disable'); |
||
| 142 | $service->callPluginManagerMethod($config, 'uninstall'); |
||
| 143 | $service->unregisterPlugin($plugin); |
||
| 144 | |||
| 145 | $output->writeln('success'); |
||
| 146 | return; |
||
| 147 | |||
| 148 | } |
||
| 149 | |||
| 150 | if (in_array($mode, array('enable', 'disable'), true)) { |
||
| 151 | if (empty($code)) { |
||
| 152 | $output->writeln('code is required.'); |
||
| 153 | return; |
||
| 154 | } |
||
| 155 | |||
| 156 | $plugin = $this->getPluginFromCode($code); |
||
| 157 | if ($service->$mode($plugin)) { |
||
| 158 | $output->writeln('success'); |
||
| 159 | return; |
||
| 160 | } |
||
| 161 | } |
||
| 162 | $output->writeln('undefined mode.'); |
||
| 163 | } |
||
| 164 | } |
||
| 165 |