From 47688f30ea32cc12115c14161c596b0d1e4ce635 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 4 Nov 2020 00:13:28 +0100 Subject: [PATCH] DependencyChecker: fixed compatibility with PHP 8 [Closes #247] --- src/DI/DependencyChecker.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/DI/DependencyChecker.php b/src/DI/DependencyChecker.php index c96409053..7e0aef0e0 100644 --- a/src/DI/DependencyChecker.php +++ b/src/DI/DependencyChecker.php @@ -132,14 +132,15 @@ class_uses($name), } foreach ($class->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { if ($method->getDeclaringClass() == $class) { // intentionally == + $type = $method->getReturnType(); $hash[] = [ $name, $method->name, $method->getDocComment(), self::hashParameters($method), - $method->hasReturnType() - ? [$method->getReturnType()->getName(), $method->getReturnType()->allowsNull()] - : null, + PHP_VERSION_ID < 80000 + ? ($type ? [$type->getName(), $type->allowsNull()] : null) + : (string) $type, ]; } } @@ -158,14 +159,15 @@ class_uses($name), $method = new \ReflectionFunction($name); $uses = null; } + $type = $method->getReturnType(); $hash[] = [ $name, $uses, $method->getDocComment(), self::hashParameters($method), - $method->hasReturnType() - ? [$method->getReturnType()->getName(), $method->getReturnType()->allowsNull()] - : null, + PHP_VERSION_ID < 80000 + ? ($type ? [$type->getName(), $type->allowsNull()] : null) + : (string) $type, ]; } @@ -179,8 +181,9 @@ private static function hashParameters(\ReflectionFunctionAbstract $method): arr foreach ($method->getParameters() as $param) { $res[] = [ $param->name, - Reflection::getParameterType($param), - $param->allowsNull(), + PHP_VERSION_ID < 80000 + ? [Reflection::getParameterType($param), $param->allowsNull()] + : (string) $param->getType(), $param->isVariadic(), $param->isDefaultValueAvailable() ? [Reflection::getParameterDefaultValue($param)]