Skip to content

Commit 19d5229

Browse files
committed
chore: inline matchesType and matchesAllTypes
1 parent 3731d19 commit 19d5229

File tree

1 file changed

+8
-25
lines changed

1 file changed

+8
-25
lines changed

src/functions.php

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,15 @@ function _checkTypehint(callable $callback, \Throwable $reason): bool
269269
foreach ($types as $type) {
270270

271271
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+
}
273278
} else {
274-
$matches = matchesType($reason, $type);
279+
$matches = ($type->isBuiltin() && \gettype($reason) === $type->getName())
280+
|| (new \ReflectionClass($type->getName()))->isInstance($reason);
275281
}
276282

277283
// 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
291297
// If we look for a full match (intersection) and did not return early, we matched all types and are true
292298
return $isTypeUnion ? false : true;
293299
}
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

Comments
 (0)