Issues (9)

src/Commands/DatabaseCommand.php (1 issue)

Severity
1
<?php
2
3
namespace Itstructure\LaRbac\Commands;
4
5
use Illuminate\Console\Command;
6
7
/**
8
 * Class DatabaseCommand
9
 *
10
 * @package Itstructure\LaRbac\Commands
11
 *
12
 * @author Andrey Girnik <[email protected]>
13
 */
14
class DatabaseCommand extends Command
15
{
16
    /**
17
     * The name and signature of the console command.
18
     * @var string
19
     */
20
    protected $signature = 'rbac:database '.
21
    '{--force : Overwrite existing files by default.}'.
22
    '{--only= : Run only specific process. Available values: migrate, seed.}';
23
24
    /**
25
     * The console command description.
26
     * @var string
27
     */
28
    protected $description = 'Fill database - migrate and seed.';
29
30
    /**
31
     * Execute the console command.
32
     * @return void
33
     */
34
    public function handle()
35
    {
36
        try {
37
            $this->info('Start fill database...');
38
39
            $callArguments = [];
40
41
            if ($this->option('force')) {
42
                $this->warn('Force process.');
43
                $callArguments['--force'] = true;
44
            }
45
46
            if ($this->option('only')) {
47
                switch ($this->option('only')) {
48
                    case 'migrate':
49
                        $this->info('Migration process...');
50
                        $this->call('migrate', $callArguments);
51
                        break;
52
53
                    case 'seed':
54
                        $this->info('Seeding process...');
55
                        $this->call('db:seed', array_merge([
56
                                '--class' => 'LaRbacDatabaseSeeder',
57
                            ], $callArguments)
58
                        );
59
                        break;
60
61
                    default:
62
                        $this->error('Invalid "only" argument value!');
63
                        return;
64
                        break;
0 ignored issues
show
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...
65
                }
66
67
            } else {
68
                $this->info('Run all processes: migration and seeding.');
69
                $this->call('migrate', $callArguments);
70
                $this->call('db:seed', array_merge([
71
                        '--class' => 'LaRbacDatabaseSeeder',
72
                    ], $callArguments)
73
                );
74
            }
75
76
            $this->info('Filling database is completed successfully.');
77
78
        } catch (\Exception $e) {
79
            $this->error('Failed!');
80
            $this->error($e->getMessage());
81
        }
82
    }
83
}
84