Completed
Push — master ( a77c04...464b27 )
by Andrey
16:47
created

DatabaseCommand::handle()   B

Complexity

Conditions 6
Paths 38

Size

Total Lines 49

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 49
rs 8.4905
c 0
b 0
f 0
cc 6
nc 38
nop 0
1
<?php
2
3
namespace Itstructure\LaRbac\Commands;
4
5
use Illuminate\Console\Command;
6
use Itstructure\LaRbac\Helpers\Helper;
7
8
/**
9
 * Class DatabaseCommand
10
 *
11
 * @package Itstructure\LaRbac\Commands
12
 *
13
 * @author Andrey Girnik <[email protected]>
14
 */
15
class DatabaseCommand extends Command
16
{
17
    /**
18
     * The name and signature of the console command.
19
     * @var string
20
     */
21
    protected $signature = 'rbac:database '.
22
    '{--force : Overwrite existing views by default. This option can not be used.}'.
23
    '{--only= : Run only specific process. Available values: migrate, seed. This option can not be used.}';
24
25
    /**
26
     * The console command description.
27
     * @var string
28
     */
29
    protected $description = 'Fill database - migrate and seed.';
30
31
    /**
32
     * Execute the console command.
33
     * @return void
34
     */
35
    public function handle()
36
    {
37
        try {
38
            $this->info('Start fill database...');
39
40
            $callArguments = [];
41
42
            if ($this->option('force')) {
43
                $this->warn('Force process.');
44
                $callArguments['--force'] = true;
45
            }
46
47
            if ($this->option('only')) {
48
                switch ($this->option('only')) {
49
                    case 'migrate':
50
                        $this->info('Migration process...');
51
                        $this->call('migrate', $callArguments);
52
                        break;
53
54
                    case 'seed':
55
                        $this->info('Seeding process...');
56
                        $this->call('db:seed', array_merge([
57
                                '--class' => 'LaRbacDatabaseSeeder',
58
                            ], $callArguments)
59
                        );
60
                        break;
61
62
                    default:
63
                        $this->error('Invalid "only" argument value!');
64
                        return;
65
                        break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
66
                }
67
68
            } else {
69
                $this->info('Run all processes: migration and seeding.');
70
                $this->call('migrate', $callArguments);
71
                $this->call('db:seed', array_merge([
72
                        '--class' => 'LaRbacDatabaseSeeder',
73
                    ], $callArguments)
74
                );
75
            }
76
77
            $this->info('Filling database is completed successfully.');
78
79
        } catch (\Exception $e) {
80
            $this->error('Failed!');
81
            $this->error($e->getMessage());
82
        }
83
    }
84
}
85