private function applyStripHosts()
    {
        if (false === $this->stripHosts) {
            return;
        }

        foreach ($this->selected as $uniqueName => $package) {
            $sources = [];

            if ($package->getSourceType()) {
                $sources[] = 'source';
            }

            if ($package->getDistType()) {
                $sources[] = 'dist';
            }

            foreach ($sources as $i => $s) {
                $url = 'source' === $s ? $package->getSourceUrl() : $package->getDistUrl();

                // skip distURL applied by ArchiveBuilder
                if ('dist' === $s && null !== $this->archiveEndpoint
                    && substr($url, 0, strlen($this->archiveEndpoint)) === $this->archiveEndpoint
                ) {
                    continue;
                }

                if ($this->matchStripHostsPatterns($url)) {
                    if ('dist' === $s) {
                        // if the type is not set, ArrayDumper ignores the other properties
                        $package->setDistType(null);
                    } else {
                        $package->setSourceType(null);
                    }

                    unset($sources[$i]);

                    if (0 === count($sources)) {
                        $this->output->writeln(sprintf('<error>%s has no source left after applying the strip-hosts filters and will be removed</error>', $package->getUniqueName()));
                        unset($this->selected[$uniqueName]);
                    }
                }
            }
        }
    }