Passed
Push — dependabot/npm_and_yarn/string... ( b56eb5...bc569b )
by
unknown
45:46 queued 33s
created

Seed::handle()   A

Complexity

Conditions 6
Paths 4

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
cc 6
eloc 9
nc 4
nop 0
dl 0
loc 17
ccs 0
cts 10
cp 0
crap 42
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')) {
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();
32
33
        $this->info($seederClass.' has run successfully.');
34
    }
35
}
36