private function getPrimaryNamespace(PackageInterface $package)
    {
        $primaryNs = null;

        foreach ($package->getAutoload() as $type => $pathMap) {
            if ($type !== 'psr-4') {
                continue;
            }

            if (count($pathMap) === 1) {
                $primaryNs = key($pathMap);
                break;
            }

            $matches = preg_grep('#^(\./)?src/?$#', $pathMap);
            if ($matches) {
                $primaryNs = key($matches);
                break;
            }

            if (false !== ($key = array_search('', $pathMap, true))
                || false !== ($key = array_search('.', $pathMap, true))
            ) {
                $primaryNs = $key;
            }

            break;
        }

        if (!$primaryNs) {
            throw new RuntimeException(sprintf("Unable to get primary namespace for package %s.", $package->getName()));
        }

        return $primaryNs;
    }