Failed Conditions
Pull Request — 4.0 (#3723)
by Kiyotaka
07:29
created

PluginUpdateCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
dl 34
loc 34
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 6 6 1
A execute() 20 20 2

How to fix   Duplicated Code   

Duplicated Code

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
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Eccube\Command;
15
16
use Eccube\Entity\Plugin;
17
use Symfony\Component\Console\Command\Command;
18
use Symfony\Component\Console\Input\InputArgument;
19
use Symfony\Component\Console\Input\InputInterface;
20
use Symfony\Component\Console\Output\OutputInterface;
21
use Symfony\Component\Console\Style\SymfonyStyle;
22
23 View Code Duplication
class PluginUpdateCommand extends Command
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
{
25
    protected static $defaultName = 'eccube:plugin:update';
26
27
    use PluginCommandTrait;
28
29
    protected function configure()
30
    {
31
        $this
32
            ->addArgument('code', InputArgument::REQUIRED, 'Plugin code')
33
            ->setDescription('Execute plugin update process.');
34
    }
35
36
    protected function execute(InputInterface $input, OutputInterface $output)
37
    {
38
        $io = new SymfonyStyle($input, $output);
39
40
        $code = $input->getArgument('code');
41
42
        /** @var Plugin $Plugin */
43
        $Plugin = $this->pluginRepository->findByCode($code);
44
45
        if (!$Plugin) {
46
            $io->error("No such plugin `${code}`.");
47
            return 1;
48
        }
49
50
        $config = $this->pluginService->readConfig($this->pluginService->calcPluginDir($code));
51
        $this->pluginService->updatePlugin($Plugin, $config);
52
        $this->clearCache($io);
53
54
        $io->success('Updated.');
55
    }
56
}
57