File tree 1 file changed +22
-1
lines changed
1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -386,7 +386,9 @@ protected function getPropertiesFromMethods($model)
386
386
//Magic get<name>Attribute
387
387
$ name = Str::snake (substr ($ method , 3 , -9 ));
388
388
if (!empty ($ name )) {
389
- $ this ->setProperty ($ name , null , true , null );
389
+ $ reflection = new \ReflectionMethod ($ model , $ method );
390
+ $ type = $ this ->getReturnTypeFromDocBlock ($ reflection );
391
+ $ this ->setProperty ($ name , $ type , true , null );
390
392
}
391
393
} elseif (Str::startsWith ($ method , 'set ' ) && Str::endsWith (
392
394
$ method ,
@@ -669,4 +671,23 @@ protected function hasCamelCaseModelProperties()
669
671
{
670
672
return $ this ->laravel ['config ' ]->get ('ide-helper.model_camel_case_properties ' , false );
671
673
}
674
+
675
+ /**
676
+ * Get method return type based on it DocBlock comment
677
+ *
678
+ * @param \ReflectionMethod $reflection
679
+ *
680
+ * @return null|string
681
+ */
682
+ protected function getReturnTypeFromDocBlock (\ReflectionMethod $ reflection )
683
+ {
684
+ $ type = null ;
685
+ $ phpdoc = new DocBlock ($ reflection );
686
+
687
+ if ($ phpdoc ->hasTag ('return ' )) {
688
+ $ type = $ phpdoc ->getTagsByName ('return ' )[0 ]->getContent ();
689
+ }
690
+
691
+ return $ type ;
692
+ }
672
693
}
You can’t perform that action at this time.
0 commit comments