|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Caffeinated\Modules\Console\Generators; |
|
4
|
|
|
|
|
5
|
|
|
class MakeMigrationCommand extends MakeCommand |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* The name and signature of the console command. |
|
9
|
|
|
* |
|
10
|
|
|
* @var string |
|
11
|
|
|
*/ |
|
12
|
|
|
protected $signature = 'make:module:migration |
|
13
|
|
|
{slug : The slug of the module.} |
|
14
|
|
|
{name : The name of the migration.} |
|
15
|
|
|
{--create= : The table to be created.} |
|
16
|
|
|
{--table= : The table to migrate.}'; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* The console command description. |
|
20
|
|
|
* |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $description = 'Create a new module migration file'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* String to store the command type. |
|
27
|
|
|
* |
|
28
|
|
|
* @var string |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $type = 'Migration'; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Module folders to be created. |
|
34
|
|
|
* |
|
35
|
|
|
* @var array |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $listFolders = [ |
|
38
|
|
|
'Database/Migrations/', |
|
39
|
|
|
]; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Module files to be created. |
|
43
|
|
|
* |
|
44
|
|
|
* @var array |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $listFiles = [ |
|
47
|
|
|
'{{filename}}.php', |
|
48
|
|
|
]; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Module signature option. |
|
52
|
|
|
* |
|
53
|
|
|
* @var array |
|
54
|
|
|
*/ |
|
55
|
|
|
protected $signOption = [ |
|
56
|
|
|
'create', |
|
57
|
|
|
'table', |
|
58
|
|
|
]; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Module stubs used to populate defined files. |
|
62
|
|
|
* |
|
63
|
|
|
* @var array |
|
64
|
|
|
*/ |
|
65
|
|
|
protected $listStubs = [ |
|
66
|
|
|
'default' => [ |
|
67
|
|
|
'migration.stub', |
|
68
|
|
|
], |
|
69
|
|
|
|
|
70
|
|
|
'create' => [ |
|
71
|
|
|
'migration_create.stub', |
|
72
|
|
|
], |
|
73
|
|
|
|
|
74
|
|
|
'table' => [ |
|
75
|
|
|
'migration_table.stub', |
|
76
|
|
|
], |
|
77
|
|
|
]; |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Resolve Container after getting file path. |
|
81
|
|
|
* |
|
82
|
|
|
* @param string $FilePath |
|
|
|
|
|
|
83
|
|
|
* |
|
84
|
|
|
* @return array |
|
85
|
|
|
*/ |
|
86
|
|
|
protected function resolveByPath($filePath) |
|
87
|
|
|
{ |
|
88
|
|
|
$this->container['filename'] = $this->makeFileName($filePath); |
|
89
|
|
|
$this->container['classname'] = basename($filePath); |
|
90
|
|
|
$this->container['tablename'] = 'dummy'; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Resolve Container after getting input option. |
|
95
|
|
|
* |
|
96
|
|
|
* @param string $option |
|
97
|
|
|
* |
|
98
|
|
|
* @return array |
|
99
|
|
|
*/ |
|
100
|
|
|
protected function resolveByOption($option) |
|
101
|
|
|
{ |
|
102
|
|
|
$this->container['tablename'] = $option; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Make FileName. |
|
107
|
|
|
* |
|
108
|
|
|
* @param string $filePath |
|
109
|
|
|
* |
|
110
|
|
|
* @return string |
|
111
|
|
|
*/ |
|
112
|
|
|
protected function makeFileName($filePath) |
|
113
|
|
|
{ |
|
114
|
|
|
return date('Y_m_d_His').'_'.strtolower(snake_case(basename($filePath))); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Replace placeholder text with correct values. |
|
119
|
|
|
* |
|
120
|
|
|
* @return string |
|
121
|
|
|
*/ |
|
122
|
|
|
protected function formatContent($content) |
|
123
|
|
|
{ |
|
124
|
|
|
return str_replace( |
|
125
|
|
|
[ |
|
126
|
|
|
'{{filename}}', |
|
127
|
|
|
'{{classname}}', |
|
128
|
|
|
'{{tablename}}', |
|
129
|
|
|
], |
|
130
|
|
|
[ |
|
131
|
|
|
$this->container['filename'], |
|
132
|
|
|
$this->container['classname'], |
|
133
|
|
|
$this->container['tablename'], |
|
134
|
|
|
], |
|
135
|
|
|
$content |
|
136
|
|
|
); |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
|
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.