Issues (44)

Commands/EnvDatabaseConfigMigrateCommand.php (8 issues)

1
<?php
2
3
namespace Ikechukwukalu\Dynamicdatabaseconfig\Console\Commands;
4
5
use Illuminate\Console\Command;
6
use Ikechukwukalu\Dynamicdatabaseconfig\Trait\DatabaseConfig;
7
8
class EnvDatabaseConfigMigrateCommand extends Command
9
{
10
    use DatabaseConfig;
0 ignored issues
show
The trait Ikechukwukalu\Dynamicdat...ig\Trait\DatabaseConfig requires some properties which are not provided by Ikechukwukalu\Dynamicdat...aseConfigMigrateCommand: $database, $configuration
Loading history...
11
12
    /**
13
     * The name and signature of the console command.
14
     *
15
     * @var string
16
     */
17
    protected $signature = 'env:migrate
18
                            {database : The type of database}
19
                            {name : The name of the new database connection}
20
                            {postfix : The postfix for the database configuration}
21
                            {--P|--path= : The path where the database migration files are kept}
22
                            {--seed : Running seeders}
23
                            {--seeder= : Running a single seeder class}
24
                            {--refresh : Refreshing all migration}
25
                            {--rollback : Reverting migrations}
26
                            {--fresh : Re-run all migrations afresh}';
27
28
    /**
29
     * The console command description.
30
     *
31
     * @var string
32
     */
33
    protected $description = 'Migrate databases from env';
34
35
    /**
36
     * Execute the console command.
37
     */
38
    public function handle(): void
39
    {
40
        $path = config('dynamicdatabaseconfig.default_path');
41
        $database = $this->argument('database');
42
        $name = $this->argument('name');
43
        $postFix = $this->argument('postfix');
44
45
        if ($this->option('path')) {
46
            $path = $this->option('path');
47
        }
48
49
        $this->components->info("Running migrations for {$name} and path={$path}");
0 ignored issues
show
Bug Best Practice introduced by
The property components does not exist on Ikechukwukalu\Dynamicdat...aseConfigMigrateCommand. Did you maybe forget to declare it?
Loading history...
50
51
        $newConfig = $this->setNewEnvConfig($database, $postFix);
0 ignored issues
show
It seems like $postFix can also be of type array and null; however, parameter $postFix of Ikechukwukalu\Dynamicdat...mand::setNewEnvConfig() 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

51
        $newConfig = $this->setNewEnvConfig($database, /** @scrutinizer ignore-type */ $postFix);
Loading history...
It seems like $database can also be of type array and null; however, parameter $database of Ikechukwukalu\Dynamicdat...mand::setNewEnvConfig() 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

51
        $newConfig = $this->setNewEnvConfig(/** @scrutinizer ignore-type */ $database, $postFix);
Loading history...
52
        $this->addNewConfig($database, $name, $newConfig);
0 ignored issues
show
It seems like $name can also be of type array and null; however, parameter $name of Ikechukwukalu\Dynamicdat...Command::addNewConfig() 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

52
        $this->addNewConfig($database, /** @scrutinizer ignore-type */ $name, $newConfig);
Loading history...
It seems like $database can also be of type array and null; however, parameter $database of Ikechukwukalu\Dynamicdat...Command::addNewConfig() 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

52
        $this->addNewConfig(/** @scrutinizer ignore-type */ $database, $name, $newConfig);
Loading history...
53
        $this->createDatabase($database, $newConfig['database']);
0 ignored issues
show
It seems like $database can also be of type array and null; however, parameter $database of Ikechukwukalu\Dynamicdat...mmand::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

53
        $this->createDatabase(/** @scrutinizer ignore-type */ $database, $newConfig['database']);
Loading history...
54
        $this->execMigrationCommands($name, $path);
0 ignored issues
show
It seems like $name can also be of type array and null; however, parameter $name of Ikechukwukalu\Dynamicdat...execMigrationCommands() 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

54
        $this->execMigrationCommands(/** @scrutinizer ignore-type */ $name, $path);
Loading history...
55
    }
56
57
    private function execMigrationCommands(string $name, null|string $path = '')
58
    {
59
        if ($this->option('rollback')) {
60
            $this->call('migrate:rollback', ['--database' => $name, '--path' => $path]);
61
            return;
62
        }
63
64
        if ($this->option('refresh')) {
65
            $this->call('migrate:refresh', ['--database' => $name, '--path' => $path]);
66
        } elseif ($this->option('fresh')) {
67
            $this->call('migrate:fresh', ['--database' => $name, '--path' => $path]);
68
        } else {
69
            $this->call('migrate', ['--database' => $name, '--path' => $path]);
70
        }
71
72
        if ($this->option('seed')) {
73
            $this->call('db:seed');
74
            return;
75
        }
76
77
        if ($seeder = $this->option('seeder')) {
78
            $this->call('db:seed', ['--class' => $seeder]);
79
        }
80
    }
81
}
82