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

AbstractConnectionCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 1
cbo 3
dl 0
loc 30
ccs 0
cts 15
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 7 1
A initialize() 0 8 2
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