Issues (44)

Commands/DynamicDatabaseConfigSeedCommand.php (5 issues)

1
<?php
2
3
namespace Ikechukwukalu\Dynamicdatabaseconfig\Console\Commands;
4
5
use Ikechukwukalu\Dynamicdatabaseconfig\Trait\DatabaseConfig;
6
use Illuminate\Console\Command;
7
8
class DynamicDatabaseConfigSeedCommand 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...tabaseConfigSeedCommand: $database, $configuration
Loading history...
11
12
    /**
13
     * The name and signature of the console command.
14
     *
15
     * @var string
16
     */
17
    protected $signature = 'dynamic:seed
18
                            {ref : The ref for the database configuration}
19
                            {--seed : Running seeders}
20
                            {--seeder= : Running a single seeder class}';
21
22
    /**
23
     * The console command description.
24
     *
25
     * @var string
26
     */
27
    protected $description = 'Seeding into databases from env';
28
29
    /**
30
     * Execute the console command.
31
     */
32
    public function handle(): void
33
    {
34
        $ref = $this->argument('ref');
35
36
        [$database, $configuration, $name] = $this->getDynamicDatabaseConfiguration($ref);
0 ignored issues
show
It seems like $ref can also be of type array and null; however, parameter $ref of Ikechukwukalu\Dynamicdat...DatabaseConfiguration() 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
        [$database, $configuration, $name] = $this->getDynamicDatabaseConfiguration(/** @scrutinizer ignore-type */ $ref);
Loading history...
37
38
        if (!$database) {
39
            $this->components->error("No database configuration was found");
0 ignored issues
show
Bug Best Practice introduced by
The property components does not exist on Ikechukwukalu\Dynamicdat...tabaseConfigSeedCommand. Did you maybe forget to declare it?
Loading history...
40
            return;
41
        }
42
43
        $this->components->info("Running seeder(s) for {$name} with ref={$ref}");
44
45
        $newConfig = $this->setNewDynamicConfig($database, $configuration);
0 ignored issues
show
$configuration of type null|string is incompatible with the type array expected by parameter $configuration of Ikechukwukalu\Dynamicdat...::setNewDynamicConfig(). ( Ignorable by Annotation )

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

45
        $newConfig = $this->setNewDynamicConfig($database, /** @scrutinizer ignore-type */ $configuration);
Loading history...
46
        $this->addNewConfig($database, $name, $newConfig);
47
        $this->createDatabase($database, $configuration['database']);
48
        $this->execSeederCommands($name);
49
    }
50
51
    private function execSeederCommands(string $name)
0 ignored issues
show
The parameter $name is not used and could be removed. ( Ignorable by Annotation )

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

51
    private function execSeederCommands(/** @scrutinizer ignore-unused */ string $name)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
52
    {
53
        if ($this->option('seed')) {
54
            $this->call('db:seed');
55
            return;
56
        }
57
58
        if ($seeder = $this->option('seeder')) {
59
            $this->call('db:seed', ['--class' => $seeder]);
60
        }
61
    }
62
}
63