Passed
Push — master ( b66278...af918b )
by Mauro
01:50
created

DestroySchemaCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 100 %

Importance

Changes 0
Metric Value
dl 35
loc 35
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

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

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
 * This file is part of the InMemoryList package.
4
 *
5
 * (c) Mauro Cassani<https://github.com/mauretto78>
6
 *
7
 *  For the full copyright and license information, please view the LICENSE
8
 *  file that was distributed with this source code.
9
 */
10
11
namespace InMemoryList\Command;
12
13
use Symfony\Component\Console\Input\InputInterface;
14
use Symfony\Component\Console\Output\OutputInterface;
15
16 View Code Duplication
class DestroySchemaCommand 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...
17
{
18
    /**
19
     * CreateSchemaCommand constructor.
20
     *
21
     * @param array $parameters
22
     */
23
    public function __construct(array $parameters)
24
    {
25
        parent::__construct(
26
            'iml_cache_destroy_schema',
27
            'pdo',
28
            $parameters
29
        );
30
    }
31
32
    protected function configure()
33
    {
34
        $this
35
            ->setName('iml:cache:schema:destroy')
36
            ->setDescription('Destroys database schema.')
37
            ->setHelp('This command destroys the database schema (only with PDO driver).')
38
        ;
39
    }
40
41
    protected function execute(InputInterface $input, OutputInterface $output)
42
    {
43
        $cache = $this->createClient($this->driver, $this->parameters);
44
45
        try {
46
            $cache->getRepository()->destroySchema();
0 ignored issues
show
Bug introduced by
The method destroySchema() does not exist on InMemoryList\Domain\Mode...ListRepositoryInterface. It seems like you code against a sub-type of InMemoryList\Domain\Mode...ListRepositoryInterface such as InMemoryList\Infrastruct...rsistance\PdoRepository. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

46
            $cache->getRepository()->/** @scrutinizer ignore-call */ destroySchema();
Loading history...
47
48
            $output->writeln('<fg=red>['.$this->driver.'] Schema was successful destroyed.</>');
49
        } catch (\Exception $e) {
50
            $output->writeln('<fg=red>['.$this->driver.'] Error in schema destruction: '.$e->getMessage().' .</>');
51
        }
52
    }
53
}
54