private function printModulesByState(IO $io, ModuleList $modules, array $states)
    {
        $printStates = count($states) > 1;

        foreach ($states as $state) {
            $filteredModules = array_filter($modules->toArray(), function (Module $module) use ($state) {
                return $state === $module->getState();
            });

            if (0 === count($filteredModules)) {
                continue;
            }

            if ($printStates) {
                $this->printModuleState($io, $state);
            }

            if (ModuleState::NOT_LOADABLE === $state) {
                $this->printNotLoadableModules($io, $filteredModules, $printStates);
            } else {
                $styleTag = ModuleState::ENABLED === $state ? null : 'bad';
                $this->printModuleTable($io, $filteredModules, $styleTag, $printStates);
            }

            if ($printStates) {
                $io->writeLine('');
            }
        }
    }