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

CreateDatabaseCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 10
rs 9.4285
cc 1
eloc 6
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
 * Creates database from command line.
13
 */
14
final class CreateDatabaseCommand extends AbstractConnectionCommand
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    protected function configure()
20
    {
21
        parent::configure();
22
23
        $this
24
            ->setName('algatux:influx:database:create')
25
            ->setDescription('Creates the configured database')
26
            ->addOption('if-not-exists', null, InputOption::VALUE_NONE, 'Don\'t trigger an error, when the database already exists')
27
        ;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    protected function execute(InputInterface $input, OutputInterface $output)
34
    {
35 View Code Duplication
        if ($this->connection->exists() && !$input->getOption('if-not-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...
36
            $this->io->error('Database "'.$this->connection->getName().'" already exists.');
37
38
            return 1;
39
        }
40
41 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...
42
            $this->io->comment('Database <comment>'.$this->connection->getName().'</comment> already exists. Skipped.');
43
44
            return 0;
45
        }
46
47
        $this->connection->create(null, false);
48
        $this->io->success('Created database "'.$this->connection->getName().'".');
49
50
        return 0;
51
    }
52
}
53