Skip to content

Commit 887e7fd

Browse files
TysonAndrefelixfbecker
authored andcommitted
fix: deprecation notice for ReflectionType::__toString() in php 7.4 (#33)
Use ReflectionNamedType->getName() for php 7.1+, instead. Continue supporting php 7.0 Fixes #23
1 parent 3e166ad commit 887e7fd

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/Dispatcher.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use phpDocumentor\Reflection\Types;
1111
use ReflectionException;
1212
use ReflectionMethod;
13+
use ReflectionNamedType;
1314

1415
class Dispatcher
1516
{
@@ -124,7 +125,15 @@ public function dispatch($msg)
124125
// Does the parameter have a type hint?
125126
$param = $parameters[$position];
126127
if ($param->hasType()) {
127-
$class = (string)$param->getType();
128+
$paramType = $param->getType();
129+
if ($paramType instanceof ReflectionNamedType) {
130+
// We have object data to map and want the class name.
131+
// This should not include the `?` if the type was nullable.
132+
$class = $paramType->getName();
133+
} else {
134+
// Fallback for php 7.0, which is still supported (and doesn't have nullable).
135+
$class = (string)$paramType;
136+
}
128137
$value = $this->mapper->map($value, new $class());
129138
}
130139
} else if (is_array($value) && isset($docBlock)) {

0 commit comments

Comments
 (0)