PluginUninstallCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 5
dl 38
loc 38
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 7 7 1
A execute() 14 14 3

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 Jitamin.
5
 *
6
 * Copyright (C) Jitamin Team
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Jitamin\Console;
13
14
use Jitamin\Foundation\Plugin\Installer;
15
use Jitamin\Foundation\Plugin\PluginInstallerException;
16
use LogicException;
17
use Symfony\Component\Console\Input\InputArgument;
18
use Symfony\Component\Console\Input\InputInterface;
19
use Symfony\Component\Console\Output\OutputInterface;
20
21
/**
22
 * Plugin uninstall command class.
23
 */
24 View Code Duplication
class PluginUninstallCommand extends BaseCommand
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...
25
{
26
    /**
27
     * Configure the console command.
28
     *
29
     * @return void
30
     */
31
    protected function configure()
32
    {
33
        $this
34
            ->setName('plugin:uninstall')
35
            ->setDescription('Remove a plugin')
36
            ->addArgument('pluginId', InputArgument::REQUIRED, 'Plugin directory name');
37
    }
38
39
    /**
40
     * Execute the console command.
41
     *
42
     * @param InputInterface  $output
43
     * @param OutputInterface $output
44
     *
45
     * @return void
46
     */
47
    protected function execute(InputInterface $input, OutputInterface $output)
48
    {
49
        if (!Installer::isConfigured()) {
50
            throw new LogicException('Jitamin is not configured to install plugins itself');
51
        }
52
53
        try {
54
            $installer = new Installer($this->container);
55
            $installer->uninstall($input->getArgument('pluginId'));
56
            $output->writeln('<info>Plugin removed successfully</info>');
57
        } catch (PluginInstallerException $e) {
58
            $output->writeln('<error>'.$e->getMessage().'</error>');
59
        }
60
    }
61
}
62