Completed
Push — master ( cfda60...9a8bcf )
by Olivier
05:15
created

DBALLoadCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 6

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
wmc 5
lcom 2
cbo 6
dl 0
loc 49
ccs 20
cts 22
cp 0.9091
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A configure() 0 8 1
A execute() 0 20 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shapin\Datagen\Bridge\Symfony\Bundle\Command;
6
7
use Shapin\Datagen\DBAL\Loader;
8
use Doctrine\DBAL\Connection;
9
use Symfony\Component\Console\Command\Command;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Input\InputOption;
12
use Symfony\Component\Console\Output\OutputInterface;
13
use Symfony\Component\Console\Style\SymfonyStyle;
14
15
class DBALLoadCommand extends Command
16
{
17
    private $connection;
18
    private $loader;
19
20 1
    public function __construct(Connection $connection, Loader $loader)
21
    {
22 1
        $this->connection = $connection;
23 1
        $this->loader = $loader;
24
25 1
        parent::__construct();
26 1
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 1
    protected function configure()
32
    {
33
        $this
34 1
            ->setName('shapin:datagen:dbal:load')
35 1
            ->setDescription('Load the DBAL schema.')
36 1
            ->addOption('groups', 'g', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Which groups should be loaded? (default: all)')
37
        ;
38 1
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 1
    protected function execute(InputInterface $input, OutputInterface $output)
44
    {
45 1
        $io = new SymfonyStyle($input, $output);
46 1
        $io->title('Create database schema with DBAL.');
47
48 1
        $groups = $input->getOption('groups', []);
0 ignored issues
show
Unused Code introduced by
The call to InputInterface::getOption() has too many arguments starting with array().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
49
50 1
        $statements = $this->loader->getSchema($groups)->toSql($this->connection->getDatabasePlatform());
51 1
        foreach ($statements as $statement) {
52
            $this->connection->query($statement);
53
        }
54
55 1
        $io->success('Schema created successfully.');
56
57 1
        foreach ($this->loader->getFixtures($groups) as $fixture) {
58
            $this->connection->insert($fixture[0], $fixture[1], $fixture[2]);
59
        }
60
61 1
        $io->success('Fixtures created successfully.');
62 1
    }
63
}
64