|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PerfectOblivion\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 |
|
|
|
|
|
|
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'))); |
|
73
|
|
|
$suffix = Config::get('actions.suffix'); |
|
74
|
|
|
|
|
75
|
|
|
if (Config::get('actions.override_duplicate_suffix')) { |
|
76
|
|
|
return str_finish($input, $suffix); |
|
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 |
|
|
|
|
|
|
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
|
|
|
|
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
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.