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

PublishMigrationCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 59
rs 10
c 0
b 0
f 0
ccs 13
cts 13
cp 1
wmc 5
lcom 1
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A publish() 0 7 1
A getArguments() 0 6 1
A handle() 0 14 3
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