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

AbstractConnectionCommand::initialize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
rs 9.6666
cc 2
eloc 5
nc 2
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Algatux\InfluxDbBundle\Command;
6
7
use InfluxDB\Database;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Input\InputOption;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
/**
13
 * Class for commands which needs the connection option.
14
 */
15
abstract class AbstractConnectionCommand extends AbstractCommand
16
{
17
    /**
18
     * @var Database
19
     */
20
    protected $connection;
21
22
    /**
23
     * {@inheritdoc}
24
     */
25
    protected function configure()
26
    {
27
        parent::configure();
28
29
        $this
30
            ->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'The connection to use for this command')
31
        ;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    protected function initialize(InputInterface $input, OutputInterface $output)
38
    {
39
        parent::initialize($input, $output);
40
41
        $this->connection = $input->getOption('connection')
42
            ? $this->getContainer()->get('algatux_influx_db.connection.'.$input->getOption('connection').'.http')
43
            : $this->getContainer()->get('algatux_influx_db.connection.http')
44
        ;
45
    }
46
}
47