protected function resolveGroupAndWhen($collections)
    {
        if (count(RouteCollector::getGroups())) {
            $collections = $this->resolveGroupCollections($collections);
        }

        if (isset($collections['WHEN'])) {
            $collections = $this->resolveWhenCollections($collections['WHEN']);
        }

        if (count($groups = RouteCollector::getGroups())) {
            $collections = $this->resolveGroupCollections($groups);
        }

        return $collections;
    }