Completed
Pull Request — master (#2)
by Randall
04:53
created

PublishMigrationCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 13
c 1
b 0
f 0
dl 0
loc 31
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 13 3
A publish() 0 6 1
1
<?php
2
3
namespace Rawilk\LaravelModules\Commands\Other;
4
5
use Illuminate\Console\Command;
6
use Rawilk\LaravelModules\Migrations\Migrator;
7
use Rawilk\LaravelModules\Module;
8
use Rawilk\LaravelModules\Publishing\MigrationPublisher;
9
10
class PublishMigrationCommand extends Command
11
{
12
    /** @var string */
13
    protected $signature = 'module:publish-migration
14
                            {module? : The name of the module to publish migrations for}';
15
16
    /** @var string */
17
    protected $description = 'Publish the migrations for a module.';
18
19
    public function handle(): void
20
    {
21
        if ($name = $this->argument('module')) {
22
            $module = $this->laravel['modules']->findOrFail($name);
23
24
            $this->publish($module);
25
26
            return;
27
        }
28
29
        /** @var \Rawilk\LaravelModules\Module $module */
30
        foreach ($this->laravel['modules']->allEnabled() as $module) {
31
            $this->publish($module);
32
        }
33
    }
34
35
    private function publish(Module $module): void
36
    {
37
        with(new MigrationPublisher(new Migrator($module, $this->getLaravel())))
38
            ->setRepository($this->laravel['modules'])
39
            ->setConsole($this)
40
            ->publish();
41
    }
42
}
43