@@ -42,6 +42,7 @@ protected function populateStub(string $stub, Model $model)
42
42
{
43
43
$ stub = str_replace ('DummyNamespace ' , $ model ->fullyQualifiedNamespace (), $ stub );
44
44
$ stub = str_replace ('DummyClass ' , $ model ->name (), $ stub );
45
+ $ stub = str_replace ('/** DummyPHPDocClass **/ ' , $ this ->buildClassPhpDoc ($ model ), $ stub );
45
46
46
47
$ body = $ this ->buildProperties ($ model );
47
48
$ body .= PHP_EOL . PHP_EOL ;
@@ -53,6 +54,19 @@ protected function populateStub(string $stub, Model $model)
53
54
return $ stub ;
54
55
}
55
56
57
+ private function buildClassPhpDoc (Model $ model )
58
+ {
59
+ $ phpDoc = '/** ' . PHP_EOL ;
60
+ /** @var Column $column */
61
+ foreach ($ model ->columns () as $ column ) {
62
+ $ phpDoc .= sprintf (' * @property %s $%s ' , $ this ->phpDataType ($ column ->dataType ()), $ column ->name ());
63
+ $ phpDoc .= PHP_EOL ;
64
+ }
65
+ $ phpDoc .= ' */ ' ;
66
+
67
+ return $ phpDoc ;
68
+ }
69
+
56
70
private function buildProperties (Model $ model )
57
71
{
58
72
$ properties = '' ;
@@ -188,4 +202,46 @@ private function addTraits(Model $model, $stub)
188
202
189
203
return $ stub ;
190
204
}
205
+
206
+ private function phpDataType (string $ dataType )
207
+ {
208
+ static $ php_data_types = [
209
+ 'id ' => 'int ' ,
210
+ 'bigincrements ' => 'int ' ,
211
+ 'biginteger ' => 'int ' ,
212
+ 'boolean ' => 'bool ' ,
213
+ 'date ' => '\Carbon\Carbon ' ,
214
+ 'datetime ' => '\Carbon\Carbon ' ,
215
+ 'datetimetz ' => '\Carbon\Carbon ' ,
216
+ 'decimal ' => 'float ' ,
217
+ 'double ' => 'double ' ,
218
+ 'float ' => 'float ' ,
219
+ 'increments ' => 'int ' ,
220
+ 'integer ' => 'int ' ,
221
+ 'mediumincrements ' => 'int ' ,
222
+ 'mediuminteger ' => 'int ' ,
223
+ 'nullabletimestamps ' => '\Carbon\Carbon ' ,
224
+ 'smallincrements ' => 'int ' ,
225
+ 'smallinteger ' => 'int ' ,
226
+ 'softdeletes ' => '\Carbon\Carbon ' ,
227
+ 'softdeletestz ' => '\Carbon\Carbon ' ,
228
+ 'time ' => '\Carbon\Carbon ' ,
229
+ 'timetz ' => '\Carbon\Carbon ' ,
230
+ 'timestamp ' => '\Carbon\Carbon ' ,
231
+ 'timestamptz ' => '\Carbon\Carbon ' ,
232
+ 'timestamps ' => '\Carbon\Carbon ' ,
233
+ 'timestampstz ' => '\Carbon\Carbon ' ,
234
+ 'tinyincrements ' => 'integer ' ,
235
+ 'tinyinteger ' => 'int ' ,
236
+ 'unsignedbiginteger ' => 'int ' ,
237
+ 'unsigneddecimal ' => 'float ' ,
238
+ 'unsignedinteger ' => 'int ' ,
239
+ 'unsignedmediuminteger ' => 'int ' ,
240
+ 'unsignedsmallinteger ' => 'int ' ,
241
+ 'unsignedtinyinteger ' => 'int ' ,
242
+ 'year ' => 'int ' ,
243
+ ];
244
+
245
+ return $ php_data_types [strtolower ($ dataType )] ?? 'string ' ;
246
+ }
191
247
}
0 commit comments