4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\DependencyInjection\LazyProxy;
15 * @author Nicolas Grekas <p@tchwork.com>
22 * @return string|null The FQCN or builtin name of the type hint, or null when the type hint references an invalid self|parent context
24 public static function getTypeHint(\ReflectionFunctionAbstract $r, \ReflectionParameter $p = null, $noBuiltin = false)
26 if ($p instanceof \ReflectionParameter) {
27 if (method_exists($p, 'getType')) {
28 $type = $p->getType();
29 } elseif (preg_match('/^(?:[^ ]++ ){4}([a-zA-Z_\x7F-\xFF][^ ]++)/', $p, $type)) {
30 $name = $type = $type[1];
32 if ('callable' === $name || 'array' === $name) {
33 return $noBuiltin ? null : $name;
37 $type = method_exists($r, 'getReturnType') ? $r->getReturnType() : null;
42 if (!\is_string($type)) {
43 $name = $type instanceof \ReflectionNamedType ? $type->getName() : $type->__toString();
45 if ($type->isBuiltin()) {
46 return $noBuiltin ? null : $name;
49 $lcName = strtolower($name);
50 $prefix = $noBuiltin ? '' : '\\';
52 if ('self' !== $lcName && 'parent' !== $lcName) {
55 if (!$r instanceof \ReflectionMethod) {
58 if ('self' === $lcName) {
59 return $prefix.$r->getDeclaringClass()->name;
61 if ($parent = $r->getDeclaringClass()->getParentClass()) {
62 return $prefix.$parent->name;