service = $service; } public function getActionGrouped(): stdClass { $grouped = $this->service->getGrouped(); $result = (object) []; foreach ($grouped as $type => $itemList) { $rawList = array_map( function ($item) { return (object) [ 'id' => $item->getId(), 'data' => $item->getData(), ]; }, $itemList ); $result->$type = $rawList; } return $result; } }