/**
* @param \ReflectionMethod $from
* @param Code\Method $method
* @throws \ReflectionException
* @return Code\Method
*/
public static function expandTypeHints(\ReflectionMethod $from, Code\Method $method)
{
$parameters = $method->getParameters();
/** @var Code\Parameter[] $parameters */
foreach ($from->getParameters() as $paramRefl) {
try {
$parameters[$paramRefl->getName()]->setTypeHint($paramRefl->isArray() ? 'array' : ($paramRefl->getClass() ? '\\' . $paramRefl->getClass()->getName() : ''));
} catch (\ReflectionException $e) {
if (preg_match('#Class (.+) does not exist#', $e->getMessage(), $m)) {
$parameters[$paramRefl->getName()]->setTypeHint('\\' . $m[1]);
} else {
throw $e;
}
}
}
$method->setParameters($parameters);
if (!$method->getVisibility()) {
$method->setVisibility('public');
}
return $method;
}