Skip to content

Commit be81b26

Browse files
committed
Improve _checkTypehint()
* Add type-declaration to $reason parameter * Avoid double call of ->getClass()
1 parent cedffca commit be81b26

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

src/functions.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -324,12 +324,8 @@ function fatalError($error)
324324
/**
325325
* @internal
326326
*/
327-
function _checkTypehint(callable $callback, $object)
327+
function _checkTypehint(callable $callback, \Throwable $reason)
328328
{
329-
if (!\is_object($object)) {
330-
return true;
331-
}
332-
333329
if (\is_array($callback)) {
334330
$callbackReflection = new \ReflectionMethod($callback[0], $callback[1]);
335331
} elseif (\is_object($callback) && !$callback instanceof \Closure) {
@@ -344,11 +340,11 @@ function _checkTypehint(callable $callback, $object)
344340
return true;
345341
}
346342

347-
$expectedException = $parameters[0];
343+
$expectedClass = $parameters[0]->getClass();
348344

349-
if (!$expectedException->getClass()) {
345+
if (!$expectedClass) {
350346
return true;
351347
}
352348

353-
return $expectedException->getClass()->isInstance($object);
349+
return $expectedClass->isInstance($reason);
354350
}

0 commit comments

Comments
 (0)