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

DumpCommand::fire()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
ccs 0
cts 9
cp 0
rs 9.4285
cc 3
eloc 7
nc 3
nop 0
crap 12
1
<?php
2
3
namespace Nwidart\Modules\Commands;
4
5
use Illuminate\Console\Command;
6
use Symfony\Component\Console\Input\InputArgument;
7
8
class DumpCommand extends Command
9
{
10
    /**
11
     * The console command name.
12
     *
13
     * @var string
14
     */
15
    protected $name = 'module:dump';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Dump-autoload the specified module or for all module.';
23
24
    /**
25
     * Execute the console command.
26
     *
27
     * @return mixed
28
     */
29
    public function fire()
30
    {
31
        $this->info('Generating optimized autoload modules.');
32
33
        if ($module = $this->argument('module')) {
34
            $this->dump($module);
35
        } else {
36
            foreach ($this->laravel['modules']->all() as $module) {
37
                $this->dump($module->getStudlyName());
38
            }
39
        }
40
    }
41
42
    public function dump($module)
43
    {
44
        $module = $this->laravel['modules']->findOrFail($module);
45
46
        $this->line("<comment>Running for module</comment>: {$module}");
47
48
        chdir($module->getPath());
49
50
        passthru('composer dump -o -n -q');
51
    }
52
53
    /**
54
     * Get the console command arguments.
55
     *
56
     * @return array
57
     */
58 16
    protected function getArguments()
59
    {
60
        return array(
61 16
            array('module', InputArgument::OPTIONAL, 'Module name.'),
62 16
        );
63
    }
64
}
65