Skip to content

Commit

Permalink
Provide a simplified way to get the parameter type string for PHP 8.0+
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed May 15, 2020
1 parent cbc3361 commit c948e59
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,18 @@ public function dumpBody()
*/
protected function getTypeAsString(ReflectionParameter $parameter)
{
if (method_exists($parameter, 'getType')) {
/** @var mixed $parameter ReflectionParameter has hasType and getType methods since PHP 7.0. */
if (version_compare(phpversion(), '8.0.0-dev', '<')) {
if ($parameter->isArray()) {
return 'array';
}

return $parameter->hasType() ? strval($parameter->getType()) : null;
}
$class = $parameter->getClass();

if ($parameter->isArray()) {
return 'array';
return $class ? $class->name : null;
}

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

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

0 comments on commit c948e59

Please sign in to comment.