Completed
Pull Request — master (#666)
by reallyli
02:28
created

DumpCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 21.82 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 12
loc 55
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 12 12 3
A dump() 0 10 1
A getArguments() 0 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 View Code Duplication
    public function handle()
28
    {
29
        $this->info('Generating optimized autoload modules.');
30
31
        if ($module = $this->argument('module')) {
32
            $this->dump($module);
33
        } else {
34
            foreach ($this->laravel['modules']->all() as $module) {
35
                $this->dump($module->getStudlyName());
36
            }
37
        }
38
    }
39
40
    public function dump($module)
41
    {
42
        $module = $this->laravel['modules']->findOrFail($module);
43
44
        $this->line("<comment>Running for module</comment>: {$module}");
45
46
        chdir($module->getPath());
47
48
        passthru('composer dump -o -n -q');
49
    }
50
51
    /**
52
     * Get the console command arguments.
53
     *
54
     * @return array
55
     */
56
    protected function getArguments()
57
    {
58
        return [
59
            ['module', InputArgument::OPTIONAL, 'Module name.'],
60
        ];
61
    }
62
}
63