Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 43 | class OwnerStoreController extends AbstractController |
||
| 44 | { |
||
| 45 | /** |
||
| 46 | * @Inject("config") |
||
| 47 | * @var array |
||
| 48 | */ |
||
| 49 | protected $appConfig; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @Inject(PluginRepository::class) |
||
| 53 | * @var PluginRepository |
||
| 54 | */ |
||
| 55 | protected $pluginRepository; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Owner's Store Plugin Installation Screen - Search function |
||
| 59 | * |
||
| 60 | * @Route("/{_admin}/store/plugin/search", name="admin_store_plugin_owners_search") |
||
| 61 | * @Template("Store/plugin_search.twig") |
||
| 62 | * @param Application $app |
||
| 63 | * @param Request $request |
||
| 64 | * @return array |
||
| 65 | */ |
||
| 66 | public function search(Application $app, Request $request) |
||
| 144 | |||
| 145 | /** |
||
| 146 | * Api Install plugin by composer connect with packagist |
||
| 147 | * |
||
| 148 | * @Route("/{_admin}/store/plugin/api/{pluginCode}/{eccubeVersion}/{version}" , name="admin_store_plugin_api_install") |
||
| 149 | * |
||
| 150 | * @param Application $app |
||
| 151 | * @param Request $request |
||
| 152 | * @param string $pluginCode |
||
| 153 | * @return RedirectResponse |
||
| 154 | */ |
||
| 155 | public function apiInstall(Application $app, Request $request, $pluginCode, $eccubeVersion, $version) |
||
| 156 | { |
||
| 157 | // Check plugin code |
||
| 158 | $url = $this->appConfig['owners_store_url'].'?eccube_version='.$eccubeVersion.'&plugin_code='.$pluginCode.'&version='.$version; |
||
| 159 | list($json, $info) = $this->getRequestApi($url, $app); |
||
| 160 | $existFlg = false; |
||
| 161 | $data = json_decode($json, true); |
||
| 162 | if ($data && isset($data['success'])) { |
||
| 163 | $success = $data['success']; |
||
| 164 | if ($success == '1') { |
||
| 165 | foreach ($data['item'] as $item) { |
||
| 166 | if ($item['product_code'] == $pluginCode) { |
||
| 167 | $existFlg = true; |
||
| 168 | break; |
||
| 169 | } |
||
| 170 | } |
||
| 171 | } |
||
| 172 | } |
||
| 173 | if ($existFlg === false) { |
||
| 174 | $app->log(sprintf('%s plugin not found!', $pluginCode)); |
||
| 175 | $app->addError('admin.plugin.not.found', 'admin'); |
||
| 176 | |||
| 177 | return $app->redirect($app->url('admin_store_plugin_owners_search')); |
||
| 178 | } |
||
| 179 | |||
| 180 | try { |
||
| 181 | $execute = sprintf('cd %s &&', $this->appConfig['root_dir']); |
||
| 182 | $execute .= sprintf(' composer require ec-cube/%s', $pluginCode); |
||
| 183 | |||
| 184 | $install = new Process($execute); |
||
| 185 | $install->setTimeout(null); |
||
| 186 | $install->run(); |
||
| 187 | if ($install->isSuccessful()) { |
||
| 188 | $app->addSuccess('admin.plugin.install.complete', 'admin'); |
||
| 189 | $app->log(sprintf('Install %s plugin successful!', $pluginCode)); |
||
| 190 | |||
| 191 | return $app->redirect($app->url('admin_store_plugin')); |
||
| 192 | } |
||
| 193 | $app->addError('admin.plugin.install.fail', 'admin'); |
||
| 194 | } catch (Exception $exception) { |
||
| 195 | $app->addError($exception->getMessage(), 'admin'); |
||
| 196 | $app->log($exception->getCode().' : '.$exception->getMessage()); |
||
| 197 | } |
||
| 198 | $app->log(sprintf('Install %s plugin fail!', $pluginCode)); |
||
| 199 | |||
| 200 | return $app->redirect($app->url('admin_store_plugin_owners_search')); |
||
| 201 | } |
||
| 202 | |||
| 203 | /** |
||
| 204 | * API request processing |
||
| 205 | * |
||
| 206 | * @param string $url |
||
| 207 | * @param Application $app |
||
| 208 | * @return array |
||
| 209 | */ |
||
| 210 | private function getRequestApi($url, $app) |
||
| 236 | |||
| 237 | /** |
||
| 238 | * Get message |
||
| 239 | * |
||
| 240 | * @param $info |
||
| 241 | * @return string |
||
| 242 | */ |
||
| 243 | View Code Duplication | private function getResponseErrorMessage($info) |
|
| 256 | } |
||
| 257 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.