@@ -42,6 +42,7 @@ protected function populateStub(string $stub, Model $model)
4242 {
4343 $ stub = str_replace ('DummyNamespace ' , $ model ->fullyQualifiedNamespace (), $ stub );
4444 $ stub = str_replace ('DummyClass ' , $ model ->name (), $ stub );
45+ $ stub = str_replace ('/** DummyPHPDocClass **/ ' , $ this ->buildClassPhpDoc ($ model ), $ stub );
4546
4647 $ body = $ this ->buildProperties ($ model );
4748 $ body .= PHP_EOL . PHP_EOL ;
@@ -53,6 +54,38 @@ protected function populateStub(string $stub, Model $model)
5354 return $ stub ;
5455 }
5556
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+
5689 private function buildProperties (Model $ model )
5790 {
5891 $ properties = '' ;
@@ -188,4 +221,46 @@ private function addTraits(Model $model, $stub)
188221
189222 return $ stub ;
190223 }
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+ }
191266}
0 commit comments