Completed
Push — master ( 023ae7...9901a6 )
by Fumio
03:37
created

CommandMakeCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 79
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 79
loc 79
ccs 14
cts 14
cp 1
rs 10
wmc 5
lcom 1
cbo 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 6 6 1
A getDefaultNamespace() 4 4 2
A getStub() 4 4 1
A generateFile() 10 10 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 LaravelPlus\Extension\Generators\Console;
4
5
use Jumilla\Generators\Laravel\OneFileGeneratorCommand as BaseCommand;
6
use Jumilla\Generators\FileGenerator;
7
use LaravelPlus\Extension\Addons\Addon;
8
use LaravelPlus\Extension\Generators\GeneratorCommandTrait;
9
10 View Code Duplication
class CommandMakeCommand extends BaseCommand
11
{
12
    use GeneratorCommandTrait;
13
14
    /**
15
     * The console command singature.
16
     *
17
     * @var string
18
     */
19
    protected $signature = 'make:console
20
        {name : The name of the class}
21
        {--addon= : The name of the addon}
22
        {--command=command.name : The terminal command that should be assigned}
23
    ';
24
25
    /**
26
     * The console command description.
27
     *
28
     * @var string
29
     */
30
    protected $description = '[+] Create a new Artisan command';
31
32
    /**
33
     * The type of class being generated.
34
     *
35
     * @var string
36
     */
37
    protected $type = 'Console';
38
39
    /**
40
     * The constructor.
41
     */
42 5
    public function __construct()
43
    {
44 5
        parent::__construct();
45
46 5
        $this->setStubDirectory(__DIR__.'/../stubs');
47 5
    }
48
49
    /**
50
     * Get the default namespace for the class.
51
     *
52
     * @return string
53
     */
54 2
    protected function getDefaultNamespace()
55
    {
56 2
        return $this->getRootNamespace().'\\'.($this->onAddon() ? 'Commands' : 'Console\\Commands');
57
    }
58
59
    /**
60
     * Get the stub file for the generator.
61
     *
62
     * @return string
63
     */
64 2
    protected function getStub()
65
    {
66 2
        return 'command.stub';
67
    }
68
69
    /**
70
     * Generate file.
71
     *
72
     * @param \Jumilla\Generators\FileGenerator $generator
73
     * @param string $path
74
     * @param string $fqcn
75
     *
76
     * @return bool
77
     */
78 2
    protected function generateFile(FileGenerator $generator, $path, $fqcn)
79
    {
80 2
        list($namespace, $class) = $this->splitFullQualifyClassName($fqcn);
81
82 2
        return $generator->file($path)->template($this->getStub(), [
83 2
            'namespace' => $namespace,
84 2
            'class' => $class,
85 2
            'command' => $this->option('command'),
86
        ]);
87
    }
88
}
89