Passed
Push — 2.1 ( e72b46...572524 )
by Sébastien
23:54 queued 17:51
created

CreateDatabaseCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
wmc 3
eloc 9
dl 0
loc 33
ccs 5
cts 10
cp 0.5
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A interactWithDatabase() 0 3 1
A interactWithNoDatabase() 0 5 1
A configure() 0 6 1
1
<?php
2
3
namespace Bdf\Prime\Console;
4
5
use Bdf\Prime\Connection\ConnectionInterface;
6
use Symfony\Component\Console\Attribute\AsCommand;
7
8
/**
9
 *
10
 */
11
#[AsCommand('prime:database:create', 'Creates the database from the configuration')]
12
class CreateDatabaseCommand extends DatabaseCommand
13
{
14
    protected static $defaultName = 'prime:database:create';
15
16
    /**
17
     * {@inheritdoc}
18
     */
19 1
    protected function configure(): void
20
    {
21 1
        parent::configure();
22
23 1
        $this
24 1
            ->setDescription('Creates the database from the configuration')
25 1
        ;
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    protected function interactWithDatabase(ConnectionInterface $connection, ?string $dbName): void
32
    {
33
        $this->io->line('Database <comment>%s</comment> for connection <comment>%s</comment> already exists.', $dbName, $connection->getName());
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    protected function interactWithNoDatabase(ConnectionInterface $connection, ?string $dbName): void
40
    {
41
        $connection->schema()->createDatabase($dbName);
0 ignored issues
show
Bug introduced by
It seems like $dbName can also be of type null; however, parameter $database of Bdf\Prime\Schema\Manager...rface::createDatabase() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

41
        $connection->schema()->createDatabase(/** @scrutinizer ignore-type */ $dbName);
Loading history...
42
43
        $this->io->line('Database <comment>%s</comment> has been <info>created</info> for connection <comment>%s</comment>.', $dbName, $connection->getName());
44
    }
45
}
46