mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-25 19:48:49 +02:00
migration symfony 5 4 (#300)
* symfony 5.4 (diff dev) * symfony 5.4 (working) * symfony 5.4 (update autoload) * symfony 5.4 (remove swiftmailer mailer implementation) * symfony 5.4 (php doc and split Global accessor class) ### Impacted packages: composer require php:">=7.2.5 <8.0.0" symfony/console:5.4.* symfony/dotenv:5.4.* symfony/framework-bundle:5.4.* symfony/twig-bundle:5.4.* symfony/yaml:5.4.* --update-with-dependencies composer require symfony/stopwatch:5.4.* symfony/web-profiler-bundle:5.4.* --dev --update-with-dependencies
This commit is contained in:
@@ -21,42 +21,43 @@ class ProxyHelper
|
||||
/**
|
||||
* @return string|null The FQCN or builtin name of the type hint, or null when the type hint references an invalid self|parent context
|
||||
*/
|
||||
public static function getTypeHint(\ReflectionFunctionAbstract $r, \ReflectionParameter $p = null, $noBuiltin = false)
|
||||
public static function getTypeHint(\ReflectionFunctionAbstract $r, \ReflectionParameter $p = null, bool $noBuiltin = false): ?string
|
||||
{
|
||||
if ($p instanceof \ReflectionParameter) {
|
||||
if (method_exists($p, 'getType')) {
|
||||
$type = $p->getType();
|
||||
} elseif (preg_match('/^(?:[^ ]++ ){4}([a-zA-Z_\x7F-\xFF][^ ]++)/', $p, $type)) {
|
||||
$name = $type = $type[1];
|
||||
|
||||
if ('callable' === $name || 'array' === $name) {
|
||||
return $noBuiltin ? null : $name;
|
||||
}
|
||||
}
|
||||
$type = $p->getType();
|
||||
} else {
|
||||
$type = method_exists($r, 'getReturnType') ? $r->getReturnType() : null;
|
||||
$type = $r->getReturnType();
|
||||
}
|
||||
if (!$type) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$types = [];
|
||||
$glue = '|';
|
||||
if ($type instanceof \ReflectionUnionType) {
|
||||
$reflectionTypes = $type->getTypes();
|
||||
} elseif ($type instanceof \ReflectionIntersectionType) {
|
||||
$reflectionTypes = $type->getTypes();
|
||||
$glue = '&';
|
||||
} elseif ($type instanceof \ReflectionNamedType) {
|
||||
$reflectionTypes = [$type];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ($type instanceof \ReflectionUnionType ? $type->getTypes() : [$type] as $type) {
|
||||
$name = $type instanceof \ReflectionNamedType ? $type->getName() : (string) $type;
|
||||
|
||||
if (!\is_string($type) && $type->isBuiltin()) {
|
||||
foreach ($reflectionTypes as $type) {
|
||||
if ($type->isBuiltin()) {
|
||||
if (!$noBuiltin) {
|
||||
$types[] = $name;
|
||||
$types[] = $type->getName();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
$lcName = strtolower($name);
|
||||
$lcName = strtolower($type->getName());
|
||||
$prefix = $noBuiltin ? '' : '\\';
|
||||
|
||||
if ('self' !== $lcName && 'parent' !== $lcName) {
|
||||
$types[] = '' !== $prefix ? $prefix.$name : $name;
|
||||
$types[] = $prefix.$type->getName();
|
||||
continue;
|
||||
}
|
||||
if (!$r instanceof \ReflectionMethod) {
|
||||
@@ -69,6 +70,8 @@ class ProxyHelper
|
||||
}
|
||||
}
|
||||
|
||||
return $types ? implode('|', $types) : null;
|
||||
sort($types);
|
||||
|
||||
return $types ? implode($glue, $types) : null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user