protected function filter($packageNames, $filters)
    {
        if (empty($filters)) {
            return $packageNames;
        }

        $packages = [];
        foreach ($packageNames as $packageName) {
            if (count($package = $this->repository->findPackages($packageName)) > 0) {
                foreach ($filters as $filter) {
                    $package = array_filter($package, $filter);
                }
                if ($package = current($package)) {
                    $packages[$packageName] = $package;
                }
            }
        }

        return array_map(
            function ($package) {
                /** @var PackageInterface $package */
                return $package->getName();
            },
            $packages
        );
    }