Completed
Push — master ( 714373...31da10 )
by Alessandro
10:21 queued 10:16
created

DropDatabaseCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 11
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Algatux\InfluxDbBundle\Command;
6
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
/**
12
 * Drops database from command line.
13
 */
14
final class DropDatabaseCommand extends AbstractConnectionCommand
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    protected function configure()
20
    {
21
        parent::configure();
22
23
        $this
24
            ->setName('algatux:influx:database:drop')
25
            ->setDescription('Drops the configured database')
26
            ->addOption('if-exists', null, InputOption::VALUE_NONE, 'Don\'t trigger an error, when the database doesn\'t exist')
27
            ->addOption('force', null, InputOption::VALUE_NONE, 'Set this parameter to execute this action')
28
        ;
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    protected function execute(InputInterface $input, OutputInterface $output)
35
    {
36
        if (!$input->getOption('force')) {
37
            $this->io->error(sprintf(<<<'EOF'
38
ATTENTION: This operation should not be executed in a production environment.
39
Would drop the database named "%s".
40
Please run the operation with --force to execute.
41
All data will be lost!
42
EOF
43
            , $this->connection->getName()));
44
45
            return 1;
46
        }
47
48 View Code Duplication
        if (!$this->connection->exists() && !$input->getOption('if-exists')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
49
            $this->io->error('Database "'.$this->connection->getName().'" does not exist.');
50
51
            return 1;
52
        }
53
54 View Code Duplication
        if (!$this->connection->exists()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
55
            $this->io->comment('Database <comment>'.$this->connection->getName().'</comment> does not exist. Skipped.');
56
57
            return 0;
58
        }
59
60
        $this->connection->drop();
61
        $this->io->success('Dropped database "'.$this->connection->getName().'".');
62
63
        return 0;
64
    }
65
}
66