@@ -126,7 +126,10 @@ public function fromMethodReflection(\ReflectionMethod $from): Method
126
126
if ($ from ->getReturnType () instanceof \ReflectionNamedType) {
127
127
$ method ->setReturnType ($ from ->getReturnType ()->getName ());
128
128
$ method ->setReturnNullable ($ from ->getReturnType ()->allowsNull ());
129
- } elseif ($ from ->getReturnType () instanceof \ReflectionUnionType) {
129
+ } elseif (
130
+ $ from ->getReturnType () instanceof \ReflectionUnionType
131
+ || $ from ->getReturnType () instanceof \ReflectionIntersectionType
132
+ ) {
130
133
$ method ->setReturnType ((string ) $ from ->getReturnType ());
131
134
}
132
135
return $ method ;
@@ -147,7 +150,10 @@ public function fromFunctionReflection(\ReflectionFunction $from, bool $withBody
147
150
if ($ from ->getReturnType () instanceof \ReflectionNamedType) {
148
151
$ function ->setReturnType ($ from ->getReturnType ()->getName ());
149
152
$ function ->setReturnNullable ($ from ->getReturnType ()->allowsNull ());
150
- } elseif ($ from ->getReturnType () instanceof \ReflectionUnionType) {
153
+ } elseif (
154
+ $ from ->getReturnType () instanceof \ReflectionUnionType
155
+ || $ from ->getReturnType () instanceof \ReflectionIntersectionType
156
+ ) {
151
157
$ function ->setReturnType ((string ) $ from ->getReturnType ());
152
158
}
153
159
$ function ->setBody ($ withBody ? $ this ->loadFunctionBody ($ from ) : '' );
@@ -174,7 +180,10 @@ public function fromParameterReflection(\ReflectionParameter $from): Parameter
174
180
if ($ from ->getType () instanceof \ReflectionNamedType) {
175
181
$ param ->setType ($ from ->getType ()->getName ());
176
182
$ param ->setNullable ($ from ->getType ()->allowsNull ());
177
- } elseif ($ from ->getType () instanceof \ReflectionUnionType) {
183
+ } elseif (
184
+ $ from ->getType () instanceof \ReflectionUnionType
185
+ || $ from ->getType () instanceof \ReflectionIntersectionType
186
+ ) {
178
187
$ param ->setType ((string ) $ from ->getType ());
179
188
}
180
189
if ($ from ->isDefaultValueAvailable ()) {
@@ -228,7 +237,10 @@ public function fromPropertyReflection(\ReflectionProperty $from): Property
228
237
if ($ from ->getType () instanceof \ReflectionNamedType) {
229
238
$ prop ->setType ($ from ->getType ()->getName ());
230
239
$ prop ->setNullable ($ from ->getType ()->allowsNull ());
231
- } elseif ($ from ->getType () instanceof \ReflectionUnionType) {
240
+ } elseif (
241
+ $ from ->getType () instanceof \ReflectionUnionType
242
+ || $ from ->getType () instanceof \ReflectionIntersectionType
243
+ ) {
232
244
$ prop ->setType ((string ) $ from ->getType ());
233
245
}
234
246
$ prop ->setInitialized ($ from ->hasType () && array_key_exists ($ prop ->getName (), $ defaults ));
0 commit comments