def METHOD_NAME(
    cfg: UAConfig,
    ent_cls: Type[UAEntitlement],
    sort_order: SortOrder,
    visited: Dict[str, bool],
    order: List[str],
):
    if ent_cls.name in visited:
        return
    if sort_order == SortOrder.REQUIRED_SERVICES:
        cls_list = ent_cls(cfg).required_services
    else:
        cls_list = ent_cls(cfg).dependent_services
    for cls_dependency in cls_list:
        if ent_cls.name not in visited:
            METHOD_NAME(
                cfg=cfg,
                ent_cls=cls_dependency,
                sort_order=sort_order,
                visited=visited,
                order=order,
            )
    order.append(str(ent_cls.name))
    visited[str(ent_cls.name)] = True