Completed
Push — master ( 51f21c...7f191b )
by Fumio
02:14
created

sources/Console/DatabaseSeedCommand.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Jumilla\Versionia\Laravel\Console;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Console\ConfirmableTrait;
7
use Jumilla\Versionia\Laravel\Migrator;
8
9
class DatabaseSeedCommand extends Command
10
{
11
    use DatabaseCommandTrait;
12
    use ConfirmableTrait;
13
14
    /**
15
     * The name and signature of the console command.
16
     *
17
     * @var string
18
     */
19
    protected $signature = 'database:seed
20
        {name? : the name of seed.}
21
        {--force : Force the operation to run when in production.}
22
    ';
23
24
    /**
25
     * The console command description.
26
     *
27
     * @var string
28
     */
29
    protected $description = 'Insert seed to database';
30
31
    /**
32
     * Execute the console command.
33
     *
34
     * @param \Jumilla\Versionia\Laravel\Migrator $migrator
35
     *
36
     * @return mixed
37
     */
38 7
    public function handle(Migrator $migrator)
39
    {
40 7
        if (!$this->confirmToProceed()) {
41 1
            return;
42
        }
43
44 6
        $seed = $this->argument('name') ?: $migrator->defaultSeed();
45
46 6
        if (!$seed) {
47 1
            $this->error('Default seed is not defined.');
48
49 1
            return;
50
        }
51
52 5
        $class = $migrator->seedClass($seed);
0 ignored issues
show
It seems like $seed defined by $this->argument('name') ...migrator->defaultSeed() on line 44 can also be of type array; however, Jumilla\Versionia\Laravel\Migrator::seedClass() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
53
54 5
        if (!$class) {
55 2
            $this->error("Seed '$seed' is not defined.");
56
57 2
            return;
58
        }
59
60 3
        $this->infoSeedRun($seed, $class);
0 ignored issues
show
It seems like $seed defined by $this->argument('name') ...migrator->defaultSeed() on line 44 can also be of type array; however, Jumilla\Versionia\Larave...andTrait::infoSeedRun() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
61
62 3
        $seeder = new $class();
63
64 3
        $seeder->setCommand($this)->run();
65 3
    }
66
}
67