File tree Expand file tree Collapse file tree 2 files changed +48
-2
lines changed Expand file tree Collapse file tree 2 files changed +48
-2
lines changed Original file line number Diff line number Diff line change @@ -51,7 +51,29 @@ function getBuilderMethod($method, $factory)
51
51
"parameters " => $ params ,
52
52
"return " => $ return ,
53
53
];
54
- };
54
+ }
55
+
56
+ function getCastReturnType ($ classname )
57
+ {
58
+ if ($ classname === null ) {
59
+ return null ;
60
+ }
61
+
62
+ $ returnType = $ classname ;
63
+
64
+ try {
65
+ $ class = new \ReflectionClass ($ classname );
66
+ $ method = $ class ->getMethod ('get ' );
67
+
68
+ if ($ method ->hasReturnType ()) {
69
+ $ returnType = $ method ->getReturnType ()->getName ();
70
+ }
71
+
72
+ return $ returnType ;
73
+ } catch (\Exception | \Throwable $ e ) {
74
+ return $ returnType ;
75
+ }
76
+ }
55
77
56
78
function getModelInfo ($ className , $ factory )
57
79
{
@@ -91,6 +113,7 @@ function getModelInfo($className, $factory)
91
113
->map (fn ($ attrs ) => array_merge ($ attrs , [
92
114
'title_case ' => str_replace ('_ ' , '' , \Illuminate \Support \Str::title ($ attrs ['name ' ])),
93
115
'documented ' => $ existingProperties ->contains ($ attrs ['name ' ]),
116
+ 'cast ' => getCastReturnType ($ attrs ['cast ' ])
94
117
]))
95
118
->toArray ();
96
119
Original file line number Diff line number Diff line change @@ -51,7 +51,29 @@ function getBuilderMethod($method, $factory)
51
51
"parameters" => $params,
52
52
"return" => $return,
53
53
];
54
- };
54
+ }
55
+
56
+ function getCastReturnType($classname)
57
+ {
58
+ if ($classname === null) {
59
+ return null;
60
+ }
61
+
62
+ $returnType = $classname;
63
+
64
+ try {
65
+ $class = new \\ReflectionClass($classname);
66
+ $method = $class->getMethod('get');
67
+
68
+ if ($method->hasReturnType()) {
69
+ $returnType = $method->getReturnType()->getName();
70
+ }
71
+
72
+ return $returnType;
73
+ } catch (\\Exception | \\Throwable $e) {
74
+ return $returnType;
75
+ }
76
+ }
55
77
56
78
function getModelInfo($className, $factory)
57
79
{
@@ -91,6 +113,7 @@ function getModelInfo($className, $factory)
91
113
->map(fn($attrs) => array_merge($attrs, [
92
114
'title_case' => str_replace('_', '', \\Illuminate\\Support\\Str::title($attrs['name'])),
93
115
'documented' => $existingProperties->contains($attrs['name']),
116
+ 'cast' => getCastReturnType($attrs['cast'])
94
117
]))
95
118
->toArray();
96
119
You can’t perform that action at this time.
0 commit comments