From 65a85616f432c3511991b787b7e5ec10ae2eb79c Mon Sep 17 00:00:00 2001 From: Martin Rademacher Date: Thu, 2 Jul 2020 14:22:53 +1200 Subject: [PATCH 1/2] Use ReflectionParameter::getType() instead of getClass() `iReflectionParameter::getClass()` is deprecated as of PHP 8 and will trigger a warning. --- src/DocBlock/StandardTagFactory.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/DocBlock/StandardTagFactory.php b/src/DocBlock/StandardTagFactory.php index 8fb4aca6..8e412fe7 100644 --- a/src/DocBlock/StandardTagFactory.php +++ b/src/DocBlock/StandardTagFactory.php @@ -254,10 +254,10 @@ private function getArgumentsForParametersFromWiring(array $parameters, array $l { $arguments = []; foreach ($parameters as $parameter) { - $class = $parameter->getClass(); + $type = $parameter->getType(); $typeHint = null; - if ($class !== null) { - $typeHint = $class->getName(); + if ($type instanceof \ReflectionNamedType) { + $typeHint = $type->getName(); } if (isset($locator[$typeHint])) { From 321abc52ae1617bd6f73b22c35fbdf199dc226ab Mon Sep 17 00:00:00 2001 From: Martin Rademacher Date: Fri, 3 Jul 2020 14:42:39 +1200 Subject: [PATCH 2/2] Handle typehint value 'self' --- src/DocBlock/StandardTagFactory.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/DocBlock/StandardTagFactory.php b/src/DocBlock/StandardTagFactory.php index 8e412fe7..e64b587e 100644 --- a/src/DocBlock/StandardTagFactory.php +++ b/src/DocBlock/StandardTagFactory.php @@ -36,6 +36,7 @@ use phpDocumentor\Reflection\FqsenResolver; use phpDocumentor\Reflection\Types\Context as TypeContext; use ReflectionMethod; +use ReflectionNamedType; use ReflectionParameter; use Webmozart\Assert\Assert; use function array_merge; @@ -256,8 +257,14 @@ private function getArgumentsForParametersFromWiring(array $parameters, array $l foreach ($parameters as $parameter) { $type = $parameter->getType(); $typeHint = null; - if ($type instanceof \ReflectionNamedType) { + if ($type instanceof ReflectionNamedType) { $typeHint = $type->getName(); + if ($typeHint === 'self') { + $declaringClass = $parameter->getDeclaringClass(); + if ($declaringClass !== null) { + $typeHint = $declaringClass->getName(); + } + } } if (isset($locator[$typeHint])) {