From 6e9d4572b069d39ff6690cf06d1fcaf4ab96e4d5 Mon Sep 17 00:00:00 2001 From: Greg Bowler Date: Tue, 4 Jul 2023 12:32:13 +0100 Subject: [PATCH] tweak: skip methods without a return type --- src/Container.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Container.php b/src/Container.php index 3379eeb..b84d6f2 100644 --- a/src/Container.php +++ b/src/Container.php @@ -46,8 +46,12 @@ public function setLoader(string $className, callable $callback):void { public function addLoaderClass(object $object):void { $refClass = new ReflectionClass($object); foreach($refClass->getMethods(ReflectionMethod::IS_PUBLIC) as $refPublicMethod) { + $type = $refPublicMethod->getReturnType(); + if(!$type) { + continue; + } /** @phpstan-ignore-next-line Why can't PHPStan see getName() ? */ - $className = $refPublicMethod->getReturnType()->getName(); + $className = $type->getName(); $callback = $refPublicMethod->getClosure($object); $this->setLoader(