DatabaseDiffCommand::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shapin\Datagen\Bridge\Symfony\Bundle\Command;
6
7
use Doctrine\DBAL\Configuration;
8
use Doctrine\DBAL\Connection;
9
use Doctrine\DBAL\DriverManager;
10
use Doctrine\DBAL\Schema\Comparator;
11
use Shapin\Datagen\Bridge\Symfony\Console\Helper\DoctrineSchemaDiffHelper;
12
use Symfony\Component\Console\Command\Command;
13
use Symfony\Component\Console\Input\InputArgument;
14
use Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Output\OutputInterface;
16
use Symfony\Component\Console\Style\SymfonyStyle;
17
18
class DatabaseDiffCommand extends Command
19
{
20
    private $connection;
21
22 2
    public function __construct(Connection $connection)
23
    {
24 2
        $this->connection = $connection;
25
26 2
        parent::__construct();
27 2
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32 2
    protected function configure()
33
    {
34
        $this
35 2
            ->setName('shapin:datagen:db:diff')
36 2
            ->setDescription('Compare a given schema with the configured one.')
37 2
            ->addArgument('dsn', InputArgument::REQUIRED, 'DSN of the schema to compare.')
38
        ;
39 2
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    protected function execute(InputInterface $input, OutputInterface $output)
45
    {
46
        $io = new SymfonyStyle($input, $output);
0 ignored issues
show
Unused Code introduced by
$io is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
47
48
        $platform = $this->connection->getDatabasePlatform();
49
50
        $remoteConnection = DriverManager::getConnection(['url' => $input->getArgument('dsn'), 'platform' => $platform], new Configuration());
51
52
        $localSchema = $this->connection->getSchemaManager()->createSchema();
53
        $remoteSchema = $remoteConnection->getSchemaManager()->createSchema();
54
55
        $schemaDiff = Comparator::compareSchemas($remoteSchema, $localSchema);
56
57
        $schemaDiffHelper = new DoctrineSchemaDiffHelper($output, $schemaDiff);
58
        $schemaDiffHelper->render();
59
60
        return 0;
61
    }
62
}
63