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