getCategoryReadRepository()->findNotEmptyOrderedByLastActivity(); foreach ($categories as &$category) { $category['last_topics'] = $this ->getTopicReadRepository() ->findByCategoryIdOrderedByLastActivity($category['id'], $topicsPerCategory); } $this->renderView(['categories' => $categories, 'topicsPerCategory' => $topicsPerCategory]); } private function getCategoryReadRepository(): CategoryReadRepository { return new CategoryReadRepository(); } private function getTopicReadRepository(): TopicReadRepository { return new TopicReadRepository(); } }