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

DumpCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 21.82 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

3 Methods

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

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()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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 56
    protected function getArguments()
57
    {
58
        return array(
59 56
            array('module', InputArgument::OPTIONAL, 'Module name.'),
60
        );
61
    }
62
}
63