ResponderMakeCommand   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 117
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 3
dl 0
loc 117
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 6 3
A getStub() 0 4 1
A getDefaultNamespace() 0 6 1
A getMethodName() 0 4 1
A getNameInput() 0 11 2
A buildClass() 0 6 1
A replaceMethod() 0 10 1
1
<?php
2
3
namespace BrightComponents\Responder\Commands;
4
5
use Illuminate\Support\Facades\Config;
6
use Illuminate\Console\GeneratorCommand;
7
8
class ResponderMakeCommand extends GeneratorCommand
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'adr:responder {name}';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Create new responder';
23
24
    /**
25
     * The type of class being generated.
26
     *
27
     * @var string
28
     */
29
    protected $type = 'Responder';
30
31
    /**
32
     * Execute the console command.
33
     */
34
    public function handle()
35
    {
36
        if (false === parent::handle() && ! $this->option('force')) {
37
            return;
38
        }
39
    }
40
41
    /**
42
     * Get the stub file for the generator.
43
     *
44
     * @return string
45
     */
46
    protected function getStub()
47
    {
48
        return __DIR__.'/stubs/responder.stub';
49
    }
50
51
    /**
52
     * Get the default namespace for the class.
53
     *
54
     * @param  string  $rootNamespace
55
     *
56
     * @return string
57
     */
58
    protected function getDefaultNamespace($rootNamespace)
59
    {
60
        $responderNamespace = Config::get('responder.namespace', 'Http\\Responders');
61
62
        return $rootNamespace.'\\'.$responderNamespace;
63
    }
64
65
    /**
66
     * Get the method name for the class.
67
     *
68
     * @return string
69
     */
70
    protected function getMethodName()
71
    {
72
        return Config::get('responder.method', 'respond');
73
    }
74
75
    /**
76
     * Get the desired class name from the input.
77
     *
78
     * @return string
79
     */
80
    protected function getNameInput()
81
    {
82
        $input = $input = studly_case(trim($this->argument('name')));
83
        $suffix = Config::get('responder.suffix');
84
85
        if (Config::get('responder.override_duplicate_suffix')) {
86
            return str_finish($input, $suffix);
87
        }
88
89
        return $input.$suffix;
90
    }
91
92
    /**
93
     * Build the class with the given name.
94
     *
95
     * @param  string  $name
96
     *
97
     * @return string
98
     */
99
    protected function buildClass($name)
100
    {
101
        $stub = $this->files->get($this->getStub());
102
103
        return $this->replaceNamespace($stub, $name)->replaceMethod($stub)->replaceClass($stub, $name);
104
    }
105
106
    /**
107
     * Replace the method name in the given stub.
108
     *
109
     * @param  string  $stub
110
     * @param  string  $name
0 ignored issues
show
Bug introduced by
There is no parameter named $name. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
111
     *
112
     * @return $this
113
     */
114
    protected function replaceMethod(&$stub)
115
    {
116
        $stub = str_replace(
117
            ['DummyMethod'],
118
            [$this->getMethodName()],
119
            $stub
120
        );
121
122
        return $this;
123
    }
124
}
125