Skip to content

Commit 924fd09

Browse files
committed
Provide a simplified way to get the parameter type string for PHP 8.0+
split: c948e59995736954ae98f83c40f360ad651118da
1 parent f714510 commit 924fd09

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

DependencyInjection/FunctionWrapper.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,18 @@ public function dumpBody()
7474
*/
7575
protected function getTypeAsString(ReflectionParameter $parameter)
7676
{
77-
if (method_exists($parameter, 'getType')) {
78-
/** @var mixed $parameter ReflectionParameter has hasType and getType methods since PHP 7.0. */
77+
if (version_compare(phpversion(), '8.0.0-dev', '<')) {
78+
if ($parameter->isArray()) {
79+
return 'array';
80+
}
7981

80-
return $parameter->hasType() ? strval($parameter->getType()) : null;
81-
}
82+
$class = $parameter->getClass();
8283

83-
if ($parameter->isArray()) {
84-
return 'array';
84+
return $class ? $class->name : null;
8585
}
8686

87-
$class = $parameter->getClass();
87+
/** @var mixed $parameter ReflectionParameter has hasType and getType methods since PHP 7.0. */
8888

89-
return $class ? $class->name : null;
89+
return $parameter->hasType() ? strval($parameter->getType()) : null;
9090
}
9191
}

0 commit comments

Comments
 (0)