private function extractPackage(
        string $vendorPath,
        SymbolInterface $symbol
    ): ?string {
        static $packagesPerSymbol = [];

        $name = $symbol->getName();

        if (!array_key_exists($name, $packagesPerSymbol)) {
            $reflection = $this->getClassReflection($name);
            $file       = str_replace('\\', '/', $reflection->getFileName());

            // This happens for symbols in the current package.
            if (strpos($file, $vendorPath) !== 0) {
                return null;
            }

            $structure = explode(
                '/',
                preg_replace(
                    sprintf(
                        '/^%s/',
                        preg_quote($vendorPath . '/', '/')
                    ),
                    '',
                    $file
                ),
                3
            );

            // This happens when other code extends Composer root code, like:
            // composer/ClassLoader.php
            if (count($structure) < 3) {
                $packagesPerSymbol[$name] = null;
            }

            [$vendor, $package] = $structure;

            $packagesPerSymbol[$name] = sprintf('%s/%s', $vendor, $package);
        }

        return $packagesPerSymbol[$name] ?? null;
    }