@@ -104,6 +104,8 @@ public function fromMethodReflection(\ReflectionMethod $from): Method
104104 if ($ from ->getReturnType () instanceof \ReflectionNamedType) {
105105 $ method ->setReturnType ($ from ->getReturnType ()->getName ());
106106 $ method ->setReturnNullable ($ from ->getReturnType ()->allowsNull ());
107+ } elseif ($ from ->getReturnType () instanceof \ReflectionUnionType) {
108+ $ method ->setReturnType ((string ) $ from ->getReturnType ());
107109 }
108110 return $ method ;
109111 }
@@ -123,6 +125,8 @@ public function fromFunctionReflection(\ReflectionFunction $from, bool $withBody
123125 if ($ from ->getReturnType () instanceof \ReflectionNamedType) {
124126 $ function ->setReturnType ($ from ->getReturnType ()->getName ());
125127 $ function ->setReturnNullable ($ from ->getReturnType ()->allowsNull ());
128+ } elseif ($ from ->getReturnType () instanceof \ReflectionUnionType) {
129+ $ function ->setReturnType ((string ) $ from ->getReturnType ());
126130 }
127131 $ function ->setBody ($ withBody ? $ this ->loadFunctionBody ($ from ) : '' );
128132 return $ function ;
@@ -145,8 +149,12 @@ public function fromParameterReflection(\ReflectionParameter $from): Parameter
145149 ? new PromotedParameter ($ from ->name )
146150 : new Parameter ($ from ->name );
147151 $ 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+ }
150158 if ($ from ->isDefaultValueAvailable ()) {
151159 $ param ->setDefaultValue ($ from ->isDefaultValueConstant ()
152160 ? new Literal ($ from ->getDefaultValueConstantName ())
@@ -184,10 +192,14 @@ public function fromPropertyReflection(\ReflectionProperty $from): Property
184192 ? ClassType::VISIBILITY_PRIVATE
185193 : ($ from ->isProtected () ? ClassType::VISIBILITY_PROTECTED : ClassType::VISIBILITY_PUBLIC )
186194 );
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 ));
191203 }
192204 $ prop ->setComment (Helpers::unformatDocComment ((string ) $ from ->getDocComment ()));
193205 $ prop ->setAttributes (self ::getAttributes ($ from ));
0 commit comments