From 426e3b5a8279f6e15b0955689652821ee2226c6f Mon Sep 17 00:00:00 2001 From: Maxim Vanhove Date: Wed, 13 Apr 2022 13:13:36 +0200 Subject: [PATCH] Replace deprecated getClass function with getType --- src/Argument/ArgumentResolverTrait.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Argument/ArgumentResolverTrait.php b/src/Argument/ArgumentResolverTrait.php index a371f82..5ff90e8 100644 --- a/src/Argument/ArgumentResolverTrait.php +++ b/src/Argument/ArgumentResolverTrait.php @@ -51,14 +51,23 @@ public function reflectArguments(ReflectionFunctionAbstract $method, array $args { $arguments = array_map(function (ReflectionParameter $param) use ($method, $args) { $name = $param->getName(); - $class = $param->getClass(); + $type = $param->getType(); if (array_key_exists($name, $args)) { return $args[$name]; } - if (! is_null($class)) { - return $class->getName(); + if ($type) { + if (PHP_VERSION_ID >= 70100) { + $typeName = $type->getName(); + } else { + $typeName = (string) $type; + } + + // in PHP 8, nullable arguments have "?" prefix + $typeHint = ltrim($typeName, '?'); + + return $typeHint; } if ($param->isDefaultValueAvailable()) {