ActionMakeCommand   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getStub() 0 4 1
A getMethodName() 0 4 1
A getDefaultNamespace() 0 4 1
A getNameInput() 0 11 2
A buildClass() 0 6 1
A replaceMethod() 0 10 1
1
<?php
2
3
namespace BrightComponents\Actions\Commands;
4
5
use Illuminate\Support\Facades\Config;
6
use Illuminate\Console\GeneratorCommand;
7
8
class ActionMakeCommand extends GeneratorCommand
9
{
10
    /**
11
     * The console command name.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'adr:action {name}';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Create a new action';
23
24
    /**
25
     * The type of class being generated.
26
     *
27
     * @var string
28
     */
29
    protected $type = 'Action';
30
31
    /**
32
     * Get the stub file for the generator.
33
     *
34
     * @return string
35
     */
36
    protected function getStub()
37
    {
38
        return __DIR__.'/stubs/action.stub';
39
    }
40
41
    /**
42
     * Get the default namespace for the class.
43
     *
44
     * @param  string  $rootNamespace
0 ignored issues
show
Bug introduced by
There is no parameter named $rootNamespace. 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...
45
     *
46
     * @return string
47
     */
48
    protected function getMethodName()
49
    {
50
        return Config::get('actions.method', '__invoke');
51
    }
52
53
    /**
54
     * Get the default namespace for the class.
55
     *
56
     * @param  string  $rootNamespace
57
     *
58
     * @return string
59
     */
60
    protected function getDefaultNamespace($rootNamespace)
61
    {
62
        return $rootNamespace.'\\'.Config::get('actions.namespace', '');
63
    }
64
65
    /**
66
     * Get the desired class name from the input.
67
     *
68
     * @return string
69
     */
70
    protected function getNameInput()
71
    {
72
        $input = $input = studly_case(trim($this->argument('name')));
0 ignored issues
show
Deprecated Code introduced by
The function studly_case() has been deprecated with message: Str::studly() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
73
        $suffix = Config::get('actions.suffix');
74
75
        if (Config::get('actions.override_duplicate_suffix')) {
76
            return str_finish($input, $suffix);
0 ignored issues
show
Deprecated Code introduced by
The function str_finish() has been deprecated with message: Str::finish() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
77
        }
78
79
        return $input.$suffix;
80
    }
81
82
    /**
83
     * Build the class with the given name.
84
     *
85
     * @param  string  $name
86
     *
87
     * @return string
88
     */
89
    protected function buildClass($name)
90
    {
91
        $stub = $this->files->get($this->getStub());
92
93
        return $this->replaceNamespace($stub, $name)->replaceMethod($stub)->replaceClass($stub, $name);
94
    }
95
96
    /**
97
     * Replace the method name in the given stub.
98
     *
99
     * @param  string  $stub
100
     * @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...
101
     *
102
     * @return $this
103
     */
104
    protected function replaceMethod(&$stub)
105
    {
106
        $stub = str_replace(
107
            ['DummyMethod'],
108
            [$this->getMethodName()],
109
            $stub
110
        );
111
112
        return $this;
113
    }
114
}
115