getValid($user_id); $output = []; foreach ($menus as $menu) { $output []= $this->buildItem($menu); } return implode(PHP_EOL, $output); } protected function buildItem(mixed $item): string { if (isset($item->submenus)) { return $this->buildDropdown($item); } return "urls->base}/{$item->url}\">{$item->title}"; } protected function buildDropdown(mixed $item): string { $output []= ''; return implode(PHP_EOL, $output); } public function getValid(int $user_id): array { return $this->menuRepository->fetchByUser($user_id); } }