Skip to content

Commit 71684fe

Browse files
authored
Merge pull request #5 from moufmouf/fix_breaking_change_in_better_reflection
Adapting change to introduced breaking change in roave/better-reflection
2 parents 13eadf1 + d934355 commit 71684fe

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/ControllerQueryProvider.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ private function getFieldsByAnnotations(string $annotationName): array
9494

9595
$queryList = [];
9696

97+
$typeResolver = new \phpDocumentor\Reflection\TypeResolver();
98+
9799
foreach ($refClass->getMethods() as $refMethod) {
98100
$standardPhpMethod = new \ReflectionMethod(get_class($this->controller), $refMethod->getName());
99101
// First, let's check the "Query" annotation
@@ -108,7 +110,9 @@ private function getFieldsByAnnotations(string $annotationName): array
108110

109111
$args = $this->mapParameters($refMethod, $standardPhpMethod);
110112

111-
$type = $this->mapType($refMethod->getReturnType()->getTypeObject(), $refMethod->getDocBlockReturnTypes(), $standardPhpMethod->getReturnType()->allowsNull());
113+
$phpdocType = $typeResolver->resolve((string) $refMethod->getReturnType());
114+
115+
$type = $this->mapType($phpdocType, $refMethod->getDocBlockReturnTypes(), $standardPhpMethod->getReturnType()->allowsNull());
112116

113117
$queryList[] = new QueryField($methodName, $type, $args, [$this->controller, $methodName], $this->hydrator);
114118
}
@@ -151,10 +155,16 @@ private function isAuthorized(\ReflectionMethod $reflectionMethod) : bool
151155
private function mapParameters(ReflectionMethod $refMethod, \ReflectionMethod $standardRefMethod)
152156
{
153157
$args = [];
158+
159+
$typeResolver = new \phpDocumentor\Reflection\TypeResolver();
160+
154161
foreach ($standardRefMethod->getParameters() as $standardParameter) {
155162
$allowsNull = $standardParameter->allowsNull();
156163
$parameter = $refMethod->getParameter($standardParameter->getName());
157-
$args[$parameter->getName()] = $this->mapType($parameter->getTypeHint(), $parameter->getDocBlockTypes(), $allowsNull);
164+
165+
$phpdocType = $typeResolver->resolve((string) $parameter->getType());
166+
167+
$args[$parameter->getName()] = $this->mapType($phpdocType, $parameter->getDocBlockTypes(), $allowsNull);
158168
}
159169

160170
return $args;

0 commit comments

Comments
 (0)