PublishMigrationCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 17
dl 0
loc 60
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A publish() 0 6 1
A handle() 0 17 3
A getArguments() 0 4 1
1
<?php
2
3
namespace Salah3id\Domains\Commands;
4
5
use Illuminate\Console\Command;
6
use Salah3id\Domains\Migrations\Migrator;
7
use Salah3id\Domains\Publishing\MigrationPublisher;
8
use Symfony\Component\Console\Input\InputArgument;
9
10
class PublishMigrationCommand extends Command
11
{
12
    /**
13
     * The console command name.
14
     *
15
     * @var string
16
     */
17
    protected $name = 'domain:publish-migration';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = "Publish a domain's migrations to the application";
25
26
    /**
27
     * Execute the console command.
28
     */
29
    public function handle(): int
30
    {
31
        $this->components->info('publishing domain migrations...');
32
33
        if ($name = $this->argument('domain')) {
34
            $domain = $this->laravel['domains']->findOrFail($name);
35
36
            $this->publish($domain);
37
38
            return 0;
39
        }
40
41
        foreach ($this->laravel['domains']->allEnabled() as $domain) {
42
            $this->publish($domain);
43
        }
44
45
        return 0;
46
    }
47
48
    /**
49
     * Publish migration for the specified domain.
50
     *
51
     * @param \Salah3id\Domains\Domain $domain
52
     */
53
    public function publish($domain)
54
    {
55
        with(new MigrationPublisher(new Migrator($domain, $this->getLaravel())))
56
            ->setRepository($this->laravel['domains'])
57
            ->setConsole($this)
58
            ->publish();
59
    }
60
61
    /**
62
     * Get the console command arguments.
63
     *
64
     * @return array
65
     */
66
    protected function getArguments()
67
    {
68
        return [
69
            ['domain', InputArgument::OPTIONAL, 'The name of domain being used.'],
70
        ];
71
    }
72
}
73