@@ -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,38 @@ protected function populateStub(string $stub, Model $model)
53
54
return $ stub ;
54
55
}
55
56
57
+ private function buildClassPhpDoc (Model $ model )
58
+ {
59
+ if (!config ('blueprint.generate_phpdocs ' )) {
60
+ return '' ;
61
+ }
62
+
63
+ $ phpDoc = PHP_EOL ;
64
+ $ phpDoc .= '/** ' ;
65
+ $ phpDoc .= PHP_EOL ;
66
+ /** @var Column $column */
67
+ foreach ($ model ->columns () as $ column ) {
68
+ $ phpDoc .= sprintf (' * @property %s $%s ' , $ this ->phpDataType ($ column ->dataType ()), $ column ->name ());
69
+ $ phpDoc .= PHP_EOL ;
70
+ }
71
+
72
+ if ($ model ->usesSoftDeletes ()) {
73
+ $ phpDoc .= ' * @property \Carbon\Carbon $deleted_at ' ;
74
+ $ phpDoc .= PHP_EOL ;
75
+ }
76
+
77
+ if ($ model ->usesTimestamps ()) {
78
+ $ phpDoc .= ' * @property \Carbon\Carbon $created_at ' ;
79
+ $ phpDoc .= PHP_EOL ;
80
+ $ phpDoc .= ' * @property \Carbon\Carbon $updated_at ' ;
81
+ $ phpDoc .= PHP_EOL ;
82
+ }
83
+
84
+ $ phpDoc .= ' */ ' ;
85
+
86
+ return $ phpDoc ;
87
+ }
88
+
56
89
private function buildProperties (Model $ model )
57
90
{
58
91
$ properties = '' ;
@@ -188,4 +221,46 @@ private function addTraits(Model $model, $stub)
188
221
189
222
return $ stub ;
190
223
}
224
+
225
+ private function phpDataType (string $ dataType )
226
+ {
227
+ static $ php_data_types = [
228
+ 'id ' => 'int ' ,
229
+ 'bigincrements ' => 'int ' ,
230
+ 'biginteger ' => 'int ' ,
231
+ 'boolean ' => 'bool ' ,
232
+ 'date ' => '\Carbon\Carbon ' ,
233
+ 'datetime ' => '\Carbon\Carbon ' ,
234
+ 'datetimetz ' => '\Carbon\Carbon ' ,
235
+ 'decimal ' => 'float ' ,
236
+ 'double ' => 'double ' ,
237
+ 'float ' => 'float ' ,
238
+ 'increments ' => 'int ' ,
239
+ 'integer ' => 'int ' ,
240
+ 'mediumincrements ' => 'int ' ,
241
+ 'mediuminteger ' => 'int ' ,
242
+ 'nullabletimestamps ' => '\Carbon\Carbon ' ,
243
+ 'smallincrements ' => 'int ' ,
244
+ 'smallinteger ' => 'int ' ,
245
+ 'softdeletes ' => '\Carbon\Carbon ' ,
246
+ 'softdeletestz ' => '\Carbon\Carbon ' ,
247
+ 'time ' => '\Carbon\Carbon ' ,
248
+ 'timetz ' => '\Carbon\Carbon ' ,
249
+ 'timestamp ' => '\Carbon\Carbon ' ,
250
+ 'timestamptz ' => '\Carbon\Carbon ' ,
251
+ 'timestamps ' => '\Carbon\Carbon ' ,
252
+ 'timestampstz ' => '\Carbon\Carbon ' ,
253
+ 'tinyincrements ' => 'integer ' ,
254
+ 'tinyinteger ' => 'int ' ,
255
+ 'unsignedbiginteger ' => 'int ' ,
256
+ 'unsigneddecimal ' => 'float ' ,
257
+ 'unsignedinteger ' => 'int ' ,
258
+ 'unsignedmediuminteger ' => 'int ' ,
259
+ 'unsignedsmallinteger ' => 'int ' ,
260
+ 'unsignedtinyinteger ' => 'int ' ,
261
+ 'year ' => 'int ' ,
262
+ ];
263
+
264
+ return $ php_data_types [strtolower ($ dataType )] ?? 'string ' ;
265
+ }
191
266
}
0 commit comments