@@ -269,9 +269,15 @@ function _checkTypehint(callable $callback, \Throwable $reason): bool
269
269
foreach ($ types as $ type ) {
270
270
271
271
if ($ type instanceof \ReflectionIntersectionType) {
272
- $ matches = matchesAllTypes ($ reason , $ type ->getTypes ());
272
+ foreach ($ type ->getTypes () as $ typeToMatch ) {
273
+ if (!($ matches = ($ typeToMatch ->isBuiltin () && \gettype ($ reason ) === $ typeToMatch ->getName ())
274
+ || (new \ReflectionClass ($ typeToMatch ->getName ()))->isInstance ($ reason ))) {
275
+ break ;
276
+ }
277
+ }
273
278
} else {
274
- $ matches = matchesType ($ reason , $ type );
279
+ $ matches = ($ type ->isBuiltin () && \gettype ($ reason ) === $ type ->getName ())
280
+ || (new \ReflectionClass ($ type ->getName ()))->isInstance ($ reason );
275
281
}
276
282
277
283
// If we look for a single match (union), we can return early on match
@@ -291,26 +297,3 @@ function _checkTypehint(callable $callback, \Throwable $reason): bool
291
297
// If we look for a full match (intersection) and did not return early, we matched all types and are true
292
298
return $ isTypeUnion ? false : true ;
293
299
}
294
-
295
- /**
296
- * @internal
297
- */
298
- function matchesType ($ reason , $ type ): bool
299
- {
300
- return ($ type ->isBuiltin () && \gettype ($ reason ) === $ type ->getName ())
301
- || (new \ReflectionClass ($ type ->getName ()))->isInstance ($ reason );
302
- }
303
-
304
- /**
305
- * @internal
306
- */
307
- function matchesAllTypes ($ reason , $ types ): bool
308
- {
309
- foreach ($ types as $ typeToMatch ) {
310
- if (!matchesType ($ reason , $ typeToMatch )) {
311
- return false ;
312
- }
313
- }
314
-
315
- return true ;
316
- }
0 commit comments