Completed
Pull Request — master (#322)
by Mathieu
03:43
created

PublishMigrationCommand::publish()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
ccs 6
cts 6
cp 1
cc 1
eloc 5
nc 1
nop 1
crap 1
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']->enabled() as $module) {
40
            $this->publish($module);
41
        }
42
    }
43
44
    /**
45
     * Publish migration for the specified module.
46
     *
47
     * @param \Nwidart\Modules\Module $module
48
     */
49 1
    public function publish($module)
50
    {
51 1
        with(new MigrationPublisher(new Migrator($module)))
52 1
            ->setRepository($this->laravel['modules'])
53 1
            ->setConsole($this)
54 1
            ->publish();
55 1
    }
56
57
    /**
58
     * Get the console command arguments.
59
     *
60
     * @return array
61
     */
62 56
    protected function getArguments()
63
    {
64
        return array(
65 56
            array('module', InputArgument::OPTIONAL, 'The name of module being used.'),
66
        );
67
    }
68
}
69