Completed
Pull Request — master (#758)
by Nicolas
04:06
created

PublishMigrationCommand::handle()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.7898

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 0
dl 0
loc 16
ccs 5
cts 9
cp 0.5556
crap 3.7898
rs 9.7333
c 0
b 0
f 0
1
<?php
2
3
namespace Nwidart\Modules\Commands;
4
5
use Illuminate\Console\Command;
6
use Nwidart\Modules\Migrations\Migrator;
7
use Nwidart\Modules\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 = 'module:publish-migration';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = "Publish a module's migrations to the application";
25
26
    /**
27
     * Execute the console command.
28
     */
29 1
    public function handle()
30
    {
31 1
        if ($name = $this->argument('module')) {
32 1
            $module = $this->laravel['modules']->findOrFail($name);
33
34 1
            $this->publish($module);
35
36 1
            return;
37
        }
38
39
        foreach ($this->laravel['modules']->allEnabled() as $module) {
40
            $this->publish($module);
41
        }
42
43
        $this->info('Migrations successfully published');
44
    }
45
46
    /**
47
     * Publish migration for the specified module.
48
     *
49
     * @param \Nwidart\Modules\Module $module
50
     */
51 1
    public function publish($module)
52
    {
53 1
        with(new MigrationPublisher(new Migrator($module)))
54 1
            ->setRepository($this->laravel['modules'])
55 1
            ->setConsole($this)
56 1
            ->publish();
57 1
    }
58
59
    /**
60
     * Get the console command arguments.
61
     *
62
     * @return array
63
     */
64 99
    protected function getArguments()
65
    {
66
        return [
67 99
            ['module', InputArgument::OPTIONAL, 'The name of module being used.'],
68
        ];
69
    }
70
}
71