Issues (590)

src/Console/DropDatabaseCommand.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Bdf\Prime\Console;
4
5
use Bdf\Prime\Connection\ConnectionInterface;
6
use Symfony\Component\Console\Attribute\AsCommand;
7
use Symfony\Component\Console\Input\InputOption;
8
9
/**
10
 *
11
 */
12
#[AsCommand('prime:database:drop', 'Drops the database from the configuration')]
13
class DropDatabaseCommand extends DatabaseCommand
14
{
15
    protected static $defaultName = 'prime:database:drop';
16
17
    /**
18
     * {@inheritdoc}
19
     */
20
    protected function configure(): void
21
    {
22
        parent::configure();
23
24
        $this
25
            ->setDescription('Drops the database from the configuration')
26
            ->addOption('force', 'f', InputOption::VALUE_NONE, 'Force the database deletion.')
27
        ;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    protected function interactWithDatabase(ConnectionInterface $connection, ?string $dbName): void
34
    {
35
        if ($this->io->option('force') || $this->io->confirm("Would you like to drop database <comment>$dbName</comment>?")) {
36
            $connection->schema()->dropDatabase($dbName);
0 ignored issues
show
It seems like $dbName can also be of type null; however, parameter $database of Bdf\Prime\Schema\Manager...terface::dropDatabase() 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

36
            $connection->schema()->dropDatabase(/** @scrutinizer ignore-type */ $dbName);
Loading history...
37
38
            $this->io->line('Database <comment>%s</comment> has been <info>dropped</info> for connection <comment>%s</comment>.', $dbName, $connection->getName());
39
        }
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    protected function interactWithNoDatabase(ConnectionInterface $connection, ?string $dbName): void
46
    {
47
        $this->io->line('Database <comment>%s</comment> for connection <comment>%s</comment> does not exist.', $dbName, $connection->getName());
48
    }
49
}
50