Passed
Push — ft/appmove ( db87fd...97613e )
by Philippe
45:05 queued 26:47
created

Seed::handle()   A

Complexity

Conditions 6
Paths 4

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 9
nc 4
nop 0
dl 0
loc 17
rs 9.2222
c 0
b 0
f 0
1
<?php
2
3
namespace Thinktomorrow\Chief\App\Console;
4
5
use Thinktomorrow\Chief\Pages\Page;
6
use Thinktomorrow\Chief\Authorization\AuthorizationDefaults;
7
use Illuminate\Database\Eloquent\Factory as ModelFactory;
8
use Illuminate\Support\Facades\Artisan;
9
10
class Seed extends BaseCommand
11
{
12
    protected $signature = 'chief:seed 
13
                            {seeder=DatabaseSeeder : the classname of the seeder. }
14
                            {--force}';
15
    protected $description = 'This will run the seeders to inject new data into your project database.';
16
17
    public function handle()
18
    {
19
        if (app()->environment() != 'local' && !$this->option('force')) {
0 ignored issues
show
introduced by
The method environment() does not exist on Illuminate\Container\Container. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

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

19
        if (app()->/** @scrutinizer ignore-call */ environment() != 'local' && !$this->option('force')) {
Loading history...
20
            throw new \Exception('You can only run the seeder in the local environment since this will inject a ton of default data');
21
        }
22
23
        if (app()->environment() != 'local' && $this->option('force')) {
24
            if (!$this->confirm('You are about to inject default seeding data in the '.app()->environment().' database! Are you sure?')) {
25
                $this->info('You are welcome. I have just saved your job.');
26
                return;
27
            }
28
        }
29
30
        $seederClass = $this->argument('seeder');
31
        app($seederClass)->run();
0 ignored issues
show
Bug introduced by
It seems like $seederClass can also be of type string[]; however, parameter $abstract of app() does only seem to accept null|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

31
        app(/** @scrutinizer ignore-type */ $seederClass)->run();
Loading history...
Bug introduced by
The method run() does not exist on Illuminate\Contracts\Foundation\Application. ( Ignorable by Annotation )

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

31
        app($seederClass)->/** @scrutinizer ignore-call */ run();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
32
33
        $this->info($seederClass.' has run successfully.');
0 ignored issues
show
Bug introduced by
Are you sure $seederClass of type null|string|string[] can be used in concatenation? ( Ignorable by Annotation )

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

33
        $this->info(/** @scrutinizer ignore-type */ $seederClass.' has run successfully.');
Loading history...
34
    }
35
}
36