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

AbstractCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 90.91%

Importance

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

2 Methods

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