public function signature(ReflectionFunctionAbstract $function)
{
$isMatch = preg_match_all(static::PARAMETER_PATTERN, $function, $matches, PREG_SET_ORDER);
if (!$isMatch) {
return array();
}
$parameters = $function->getParameters();
$signature = array();
$index = -1;
foreach ($matches as $match) {
$parameter = $parameters[++$index];
$typehint = $match[2];
if ('self ' === $typehint) {
$typehint = '\\' . $parameter->getDeclaringClass()->getName() . ' ';
} elseif ('' !== $typehint && 'array ' !== $typehint && (!$this->isCallableTypeHintSupported || 'callable ' !== $typehint) && (!$this->isIterableTypeHintSupported || 'iterable ' !== $typehint)) {
if (!$this->isScalarTypeHintSupported) {
$typehint = '\\' . $typehint;
// @codeCoverageIgnore
} elseif ('integer ' === $typehint && $parameter->getType()->isBuiltin()) {
$typehint = 'int ';
} elseif ('boolean ' === $typehint && $parameter->getType()->isBuiltin()) {
$typehint = 'bool ';
} elseif ('float ' !== $typehint && 'string ' !== $typehint) {
$typehint = '\\' . $typehint;
}
}
if ($this->isExportReferenceSupported) {
$byReference = $match[4];
} else {
$byReference = $parameter->isPassedByReference() ? '&' : '';
// @codeCoverageIgnore
}
if ($this->isVariadicParameterSupported && $parameter->isVariadic()) {
$variadic = '...';
$optional = false;
} else {
$variadic = '';
$optional = 'optional' === $match[1];
}
if (isset($match[6])) {
if (' = NULL' === $match[6]) {
$defaultValue = ' = null';
} else {
$defaultValue = ' = ' . var_export($parameter->getDefaultValue(), true);
}
} elseif ($optional || $match[3]) {
$defaultValue = ' = null';
} else {
$defaultValue = '';
}
$signature[$match[5]] = array($typehint, $byReference, $variadic, $defaultValue);
}
return $signature;
}