|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Caffeinated\Modules\Console\Generators; |
|
4
|
|
|
|
|
5
|
|
|
class MakeControllerCommand extends MakeCommand |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* The name and signature of the console command. |
|
9
|
|
|
* |
|
10
|
|
|
* @var string |
|
11
|
|
|
*/ |
|
12
|
|
|
protected $signature = 'make:module:controller |
|
13
|
|
|
{slug : The slug of the module} |
|
14
|
|
|
{name : The name of the controller class} |
|
15
|
|
|
{--resource : Generate a module resource controller class}'; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* The console command description. |
|
19
|
|
|
* |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $description = 'Create a new module controller class'; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* String to store the command type. |
|
26
|
|
|
* |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $type = 'Controller'; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Module folders to be created. |
|
33
|
|
|
* |
|
34
|
|
|
* @var array |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $listFolders = [ |
|
37
|
|
|
'Http/Controllers/', |
|
38
|
|
|
]; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Module files to be created. |
|
42
|
|
|
* |
|
43
|
|
|
* @var array |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $listFiles = [ |
|
46
|
|
|
'{{filename}}.php', |
|
47
|
|
|
]; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Module signature option. |
|
51
|
|
|
* |
|
52
|
|
|
* @var array |
|
53
|
|
|
*/ |
|
54
|
|
|
protected $signOption = [ |
|
55
|
|
|
'resource', |
|
56
|
|
|
]; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Module stubs used to populate defined files. |
|
60
|
|
|
* |
|
61
|
|
|
* @var array |
|
62
|
|
|
*/ |
|
63
|
|
|
protected $listStubs = [ |
|
64
|
|
|
'default' => [ |
|
65
|
|
|
'controller.stub', |
|
66
|
|
|
], |
|
67
|
|
|
|
|
68
|
|
|
'resource' => [ |
|
69
|
|
|
'controller_resource.stub', |
|
70
|
|
|
], |
|
71
|
|
|
]; |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Resolve Container after getting file path. |
|
75
|
|
|
* |
|
76
|
|
|
* @param string $FilePath |
|
|
|
|
|
|
77
|
|
|
* |
|
78
|
|
|
* @return array |
|
79
|
|
|
*/ |
|
80
|
|
|
protected function resolveByPath($filePath) |
|
81
|
|
|
{ |
|
82
|
|
|
$this->container['filename'] = $this->makeFileName($filePath); |
|
83
|
|
|
$this->container['namespace'] = $this->getNamespace($filePath); |
|
84
|
|
|
$this->container['path'] = $this->getBaseNamespace(); |
|
85
|
|
|
$this->container['classname'] = basename($filePath); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Replace placeholder text with correct values. |
|
90
|
|
|
* |
|
91
|
|
|
* @return string |
|
92
|
|
|
*/ |
|
93
|
|
|
protected function formatContent($content) |
|
94
|
|
|
{ |
|
95
|
|
|
return str_replace( |
|
96
|
|
|
[ |
|
97
|
|
|
'{{filename}}', |
|
98
|
|
|
'{{path}}', |
|
99
|
|
|
'{{namespace}}', |
|
100
|
|
|
'{{classname}}', |
|
101
|
|
|
], |
|
102
|
|
|
[ |
|
103
|
|
|
$this->container['filename'], |
|
104
|
|
|
$this->container['path'], |
|
105
|
|
|
$this->container['namespace'], |
|
106
|
|
|
$this->container['classname'], |
|
107
|
|
|
], |
|
108
|
|
|
$content |
|
109
|
|
|
); |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$irelandis not defined by the methodfinale(...).The most likely cause is that the parameter was changed, but the annotation was not.