@@ -104,6 +104,8 @@ public function fromMethodReflection(\ReflectionMethod $from): Method
104
104
if ($ from ->getReturnType () instanceof \ReflectionNamedType) {
105
105
$ method ->setReturnType ($ from ->getReturnType ()->getName ());
106
106
$ method ->setReturnNullable ($ from ->getReturnType ()->allowsNull ());
107
+ } elseif ($ from ->getReturnType () instanceof \ReflectionUnionType) {
108
+ $ method ->setReturnType ((string ) $ from ->getReturnType ());
107
109
}
108
110
return $ method ;
109
111
}
@@ -123,6 +125,8 @@ public function fromFunctionReflection(\ReflectionFunction $from, bool $withBody
123
125
if ($ from ->getReturnType () instanceof \ReflectionNamedType) {
124
126
$ function ->setReturnType ($ from ->getReturnType ()->getName ());
125
127
$ function ->setReturnNullable ($ from ->getReturnType ()->allowsNull ());
128
+ } elseif ($ from ->getReturnType () instanceof \ReflectionUnionType) {
129
+ $ function ->setReturnType ((string ) $ from ->getReturnType ());
126
130
}
127
131
$ function ->setBody ($ withBody ? $ this ->loadFunctionBody ($ from ) : '' );
128
132
return $ function ;
@@ -145,8 +149,12 @@ public function fromParameterReflection(\ReflectionParameter $from): Parameter
145
149
? new PromotedParameter ($ from ->name )
146
150
: new Parameter ($ from ->name );
147
151
$ param ->setReference ($ from ->isPassedByReference ());
148
- $ param ->setType ($ from ->getType () instanceof \ReflectionNamedType ? $ from ->getType ()->getName () : null );
149
- $ param ->setNullable ($ from ->hasType () && $ from ->getType ()->allowsNull ());
152
+ if ($ from ->getType () instanceof \ReflectionNamedType) {
153
+ $ param ->setType ($ from ->getType ()->getName ());
154
+ $ param ->setNullable ($ from ->getType ()->allowsNull ());
155
+ } elseif ($ from ->getType () instanceof \ReflectionUnionType) {
156
+ $ param ->setType ((string ) $ from ->getType ());
157
+ }
150
158
if ($ from ->isDefaultValueAvailable ()) {
151
159
$ param ->setDefaultValue ($ from ->isDefaultValueConstant ()
152
160
? new Literal ($ from ->getDefaultValueConstantName ())
@@ -184,10 +192,14 @@ public function fromPropertyReflection(\ReflectionProperty $from): Property
184
192
? ClassType::VISIBILITY_PRIVATE
185
193
: ($ from ->isProtected () ? ClassType::VISIBILITY_PROTECTED : ClassType::VISIBILITY_PUBLIC )
186
194
);
187
- if (PHP_VERSION_ID >= 70400 && ($ from ->getType () instanceof \ReflectionNamedType)) {
188
- $ prop ->setType ($ from ->getType ()->getName ());
189
- $ prop ->setNullable ($ from ->getType ()->allowsNull ());
190
- $ prop ->setInitialized (array_key_exists ($ prop ->getName (), $ defaults ));
195
+ if (PHP_VERSION_ID >= 70400 ) {
196
+ if ($ from ->getType () instanceof \ReflectionNamedType) {
197
+ $ prop ->setType ($ from ->getType ()->getName ());
198
+ $ prop ->setNullable ($ from ->getType ()->allowsNull ());
199
+ } elseif ($ from ->getType () instanceof \ReflectionUnionType) {
200
+ $ prop ->setType ((string ) $ from ->getType ());
201
+ }
202
+ $ prop ->setInitialized ($ from ->hasType () && array_key_exists ($ prop ->getName (), $ defaults ));
191
203
}
192
204
$ prop ->setComment (Helpers::unformatDocComment ((string ) $ from ->getDocComment ()));
193
205
$ prop ->setAttributes (self ::getAttributes ($ from ));
0 commit comments