Completed
Push — master ( 15e02a...758c52 )
by Nicolas
05:13
created

PublishMigrationCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 16.66%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 61
ccs 3
cts 18
cp 0.1666
rs 10

3 Methods

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