MigrateFreshCommand::getDomainName()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 11
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 0
1
<?php
2
3
namespace Salah3id\Domains\Commands;
4
5
use Illuminate\Console\Command;
6
use Salah3id\Domains\Traits\DomainCommandTrait;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputOption;
9
10
class MigrateFreshCommand extends Command
11
{
12
    use DomainCommandTrait;
13
14
    /**
15
     * The console command name.
16
     *
17
     * @var string
18
     */
19
    protected $name = 'domain:migrate-fresh';
20
21
    /**
22
     * The console command description.
23
     *
24
     * @var string
25
     */
26
    protected $description = 'Drop all database tables and re-run all migrations';
27
28
    /**
29
     * Execute the console command.
30
     */
31
    public function handle(): int
32
    {
33
        $domain = $this->argument('domain');
34
35
        if ($domain && !$this->getDomainName()) {
36
            $this->error("Domain [$domain] does not exists.");
37
38
            return E_ERROR;
39
        }
40
41
        $this->call('migrate:fresh');
42
43
        $this->call('domain:migrate', [
44
            'domain' => $this->getDomainName(),
45
            '--database' => $this->option('database'),
46
            '--force' => $this->option('force'),
47
            '--seed' => $this->option('seed'),
48
        ]);
49
50
        return 0;
51
    }
52
53
    /**
54
     * Get the console command arguments.
55
     *
56
     * @return array
57
     */
58
    protected function getArguments()
59
    {
60
        return [
61
            ['domain', InputArgument::OPTIONAL, 'The name of domain will be used.'],
62
        ];
63
    }
64
65
    /**
66
     * Get the console command options.
67
     *
68
     * @return array
69
     */
70
    protected function getOptions()
71
    {
72
        return [
73
            ['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'],
74
            ['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'],
75
            ['seed', null, InputOption::VALUE_NONE, 'Indicates if the seed task should be re-run.'],
76
        ];
77
    }
78
79
    public function getDomainName()
80
    {
81
        $domain = $this->argument('domain');
82
83
        if (!$domain) {
84
            return null;
85
        }
86
87
        $domain = app('domains')->find($domain);
88
89
        return $domain ? $domain->getStudlyName() : null;
90
    }
91
}
92