Completed
Pull Request — master (#4)
by Alessandro
04:24
created

AbstractConnectionCommand::initialize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
ccs 0
cts 8
cp 0
rs 9.4285
cc 2
eloc 5
nc 2
nop 2
crap 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Facile\MongoDbBundle\Commands;
6
7
use MongoDB\Database as Connection;
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 AbstractConnectionCommand.
14
 */
15
class AbstractConnectionCommand extends AbstractCommand
16
{
17
    /**
18
     * @var Connection
19
     */
20
    protected $connection;
21
22
    /**
23
     * {@inheritdoc}
24
     */
25
    protected function configure()
26
    {
27
        parent::configure();
28
        $this
29
            ->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'The connection to use for this command')
30
        ;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    protected function initialize(InputInterface $input, OutputInterface $output)
37
    {
38
        parent::initialize($input, $output);
39
        $this->connection = $input->getOption('connection')
40
            ? $this->getContainer()->get('mongo.connection.'.$input->getOption('connection'))
41
            : $this->getContainer()->get('mongo.connection')
42
        ;
43
    }
44
}
45