@@ -126,7 +126,10 @@ public function fromMethodReflection(\ReflectionMethod $from): Method
126126 if ($ from ->getReturnType () instanceof \ReflectionNamedType) {
127127 $ method ->setReturnType ($ from ->getReturnType ()->getName ());
128128 $ method ->setReturnNullable ($ from ->getReturnType ()->allowsNull ());
129- } elseif ($ from ->getReturnType () instanceof \ReflectionUnionType) {
129+ } elseif (
130+ $ from ->getReturnType () instanceof \ReflectionUnionType
131+ || $ from ->getReturnType () instanceof \ReflectionIntersectionType
132+ ) {
130133 $ method ->setReturnType ((string ) $ from ->getReturnType ());
131134 }
132135 return $ method ;
@@ -147,7 +150,10 @@ public function fromFunctionReflection(\ReflectionFunction $from, bool $withBody
147150 if ($ from ->getReturnType () instanceof \ReflectionNamedType) {
148151 $ function ->setReturnType ($ from ->getReturnType ()->getName ());
149152 $ function ->setReturnNullable ($ from ->getReturnType ()->allowsNull ());
150- } elseif ($ from ->getReturnType () instanceof \ReflectionUnionType) {
153+ } elseif (
154+ $ from ->getReturnType () instanceof \ReflectionUnionType
155+ || $ from ->getReturnType () instanceof \ReflectionIntersectionType
156+ ) {
151157 $ function ->setReturnType ((string ) $ from ->getReturnType ());
152158 }
153159 $ function ->setBody ($ withBody ? $ this ->loadFunctionBody ($ from ) : '' );
@@ -174,7 +180,10 @@ public function fromParameterReflection(\ReflectionParameter $from): Parameter
174180 if ($ from ->getType () instanceof \ReflectionNamedType) {
175181 $ param ->setType ($ from ->getType ()->getName ());
176182 $ param ->setNullable ($ from ->getType ()->allowsNull ());
177- } elseif ($ from ->getType () instanceof \ReflectionUnionType) {
183+ } elseif (
184+ $ from ->getType () instanceof \ReflectionUnionType
185+ || $ from ->getType () instanceof \ReflectionIntersectionType
186+ ) {
178187 $ param ->setType ((string ) $ from ->getType ());
179188 }
180189 if ($ from ->isDefaultValueAvailable ()) {
@@ -228,7 +237,10 @@ public function fromPropertyReflection(\ReflectionProperty $from): Property
228237 if ($ from ->getType () instanceof \ReflectionNamedType) {
229238 $ prop ->setType ($ from ->getType ()->getName ());
230239 $ prop ->setNullable ($ from ->getType ()->allowsNull ());
231- } elseif ($ from ->getType () instanceof \ReflectionUnionType) {
240+ } elseif (
241+ $ from ->getType () instanceof \ReflectionUnionType
242+ || $ from ->getType () instanceof \ReflectionIntersectionType
243+ ) {
232244 $ prop ->setType ((string ) $ from ->getType ());
233245 }
234246 $ prop ->setInitialized ($ from ->hasType () && array_key_exists ($ prop ->getName (), $ defaults ));
0 commit comments