chapters as $chapterData) { $chapter = $this->mangaRepository->findChapterById($chapterData->id); if (!$chapter) { throw new ChapterNotFoundException($chapterData->id); } $updatedChapter = $chapter; if ($chapterData->title !== null) { $updatedChapter = $updatedChapter->updateTitle($chapterData->title); } if ($chapterData->volume !== null) { $updatedChapter = $updatedChapter->updateVolume($chapterData->volume); } $this->mangaRepository->updateChapter($updatedChapter); } } }