Repository: symfony/symfony
File: src/Symfony/Component/TypeInfo/TypeContext/TypeContextFactory.php (PHP)

Code before:

    public function __construct(
        private readonly ?StringTypeResolver $stringTypeResolver = null,
    ) {
    }

    public function createFromClassName(string $calledClassName, ?string $declaringClassName = null): TypeContext
    {
        $declaringClassName ??= $calledClassName;

        $calledClassPath = explode('\\', $calledClassName);
        $declaringClassPath = explode('\\', $declaringClassName);

        $calledClassNameReflection = self::$reflectionClassCache[$calledClassName] ??= new \ReflectionClass($calledClassName);
        $declaringClassReflection = self::$reflectionClassCache[$declaringClassName] ??= new \ReflectionClass($declaringClassName);

        $calledClassTypeContext = new TypeContext(
            end($calledClassPath),
            end($declaringClassPath),
            trim($calledClassNameReflection->getNamespaceName(), '\\'),
            $this->collectUses($calledClassNameReflection),
        );

        $uses = $this->collectUses($declaringClassReflection);

        // add called class to uses if its namespace differs from the declaring class
        if ($calledClassNameReflection->getNamespaceName() !== $declaringClassReflection->getNamespaceName()) {
            $uses[end($calledClassPath)] = $calledClassName;
        }

        $typeContext = new TypeContext(
            end($calledClassPath),
            end($declaringClassPath),
            trim($declaringClassReflection->getNamespaceName(), '\\'),
            $uses,
        );

        $typeContext = new TypeContext(
            $typeContext->calledClassName,
            $typeContext->declaringClassName,
            $typeContext->namespace,
            $typeContext->uses,
            $this->collectTemplates($calledClassNameReflection, $calledClassTypeContext) + $this->collectTemplates($declaringClassReflection, $typeContext),
        );

        return new TypeContext(
            $typeContext->calledClassName,
            $typeContext->declaringClassName,
            $typeContext->namespace,
            $typeContext->uses,
            $typeContext->templates,

Review comment (suggestion):
This change looks suspicious to me. Resolving a `static` keyword should not involve defining a fake use statement (which will impact other resolutions in the phpdoc if the short class name of that called class is used for something else).
The TypeContextFactory always has a FQCN as input anyway.

I think the proper fix would involve using FQCN as called class name and declaring class name in the TypeContext (and then not calling `normalize` on them) instead of converting them to short class names that require resolution (and thus require creating a fake use statement for them, which would be very complex to do safely to avoid conflict with actual relative names used in the code)

Code after:

    public function __construct(
        private readonly ?StringTypeResolver $stringTypeResolver = null,
    ) {
    }

    public function createFromClassName(string $calledClassName, ?string $declaringClassName = null): TypeContext
    {
        $declaringClassName ??= $calledClassName;

        $calledClassNameReflection = self::$reflectionClassCache[$calledClassName] ??= new \ReflectionClass($calledClassName);
        $declaringClassReflection = self::$reflectionClassCache[$declaringClassName] ??= new \ReflectionClass($declaringClassName);

        $calledClassTypeContext = new TypeContext(
            $calledClassName,
            $declaringClassName,
            trim($calledClassNameReflection->getNamespaceName(), '\\'),
            $this->collectUses($calledClassNameReflection),
        );

        $typeContext = new TypeContext(
            $calledClassName,
            $declaringClassName,
            trim($declaringClassReflection->getNamespaceName(), '\\'),
            $this->collectUses($declaringClassReflection),
        );

        $typeContext = new TypeContext(
            $typeContext->calledClassName,
            $typeContext->declaringClassName,
            $typeContext->namespace,
            $typeContext->uses,
            $this->collectTemplates($calledClassNameReflection, $calledClassTypeContext) + $this->collectTemplates($declaringClassReflection, $typeContext),
        );

        return new TypeContext(
            $typeContext->calledClassName,
            $typeContext->declaringClassName,
            $typeContext->namespace,
            $typeContext->uses,
            $typeContext->templates,
            $this->collectTypeAliases($declaringClassReflection, $typeContext),
        );
    }

    public function createFromReflection(\Reflector $reflection): ?TypeContext
    {
        $declaringClassReflection = match (true) {
            $reflection instanceof \ReflectionClass => $reflection,
            $reflection instanceof \ReflectionMethod => $reflection->getDeclaringClass(),
            $reflection instanceof \ReflectionProperty => $reflection->getDeclaringClass(),