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

Code before:
        string $declaringClassName,
    ): TypeContext {
        $calledClassPath = explode('\\', $calledClassName);
        $declaringClassPath = explode('\\', $declaringClassName);

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

        $typeContext = $this->getIntermediateTypeContext(
            end($calledClassPath),
            $declaringClassReflection,
        );

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

    private function getIntermediateTypeContext(
        string $calledClassShortName,
        \ReflectionClass $declaringClassReflection,
    ): TypeContext {
        $declaringClassName = $declaringClassReflection->getName();

        self::$intermediateTypeContextCache[$declaringClassName][$calledClassShortName] ??= $this->createIntermediateTypeContext(
            $calledClassShortName,
            $declaringClassReflection,
        );

        return self::$intermediateTypeContextCache[$declaringClassName][$calledClassShortName];
    }

    private function createIntermediateTypeContext(
        string $calledClassShortName,
        \ReflectionClass $declaringClassReflection,
    ): TypeContext {
        return new TypeContext(
            $calledClassShortName,
            $declaringClassReflection->getShortName(),
            trim($declaringClassReflection->getNamespaceName(), '\\'),
            $this->collectUses($declaringClassReflection),
        );
    }

    /**
     * @return array<string, string>
     */

Review comment (suggestion):
our CS is to always have function signatures on one line (except for constructor using CPP)
```suggestion
    ): TypeContext
    {
```

Code after:
        $typeContext = $this->createIntermediateTypeContext(end($calledClassPath), $declaringClassReflection);

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

    private function createIntermediateTypeContext(string $calledClassShortName, \ReflectionClass $declaringClassReflection): TypeContext
    {
        $declaringClassName = $declaringClassReflection->getName();

        return $this->intermediateTypeContextCache[$declaringClassName][$calledClassShortName] ??= new TypeContext(
            $calledClassShortName,
            $declaringClassReflection->getShortName(),
            trim($declaringClassReflection->getNamespaceName(), '\\'),
            $this->collectUses($declaringClassReflection),
        );
    }

    /**
     * @return array<string, string>
     */
    private function collectUses(\ReflectionClass $reflection): array
    {
        $fileName = $reflection->getFileName();
        if (!\is_string($fileName) || !is_file($fileName)) {
            return [];
        }

        if (false === $lines = @file($fileName, \FILE_IGNORE_NEW_LINES)) {
            throw new RuntimeException(\sprintf('Unable to read file "%s".', $fileName));
        }

        $uses = [];
        $inUseSection = false;

        foreach ($lines as $line) {
            if (str_starts_with($line, 'use ')) {
                $inUseSection = true;
                $use = explode(' as ', substr($line, 4, -1), 2);

                $alias = 1 === \count($use) ? substr($use[0], false !== ($p = strrpos($use[0], '\\')) ? 1 + $p : 0) : $use[1];
                $uses[$alias] = $use[0];
            } elseif ($inUseSection) {
                break;
            }