Completed
Pull Request — master (#4)
by Alessandro
03:48
created

AbstractCommand::initialize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.0116

Importance

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