mangaRepository->findByExternalId(new ExternalId($command->externalId)); if ($manga === null) { throw new \RuntimeException('Manga not found'); } $offset = 0; $limit = 500; $hasMore = true; while ($hasMore) { $feed = $this->mangadexClient->getMangaFeed( $command->externalId, $offset, $limit ); foreach ($feed['data'] as $chapterData) { $chapter = new Chapter( new ChapterId((string) Uuid::uuid4()), $manga->getId()->getValue(), (float) $chapterData['attributes']['chapter'], $chapterData['attributes']['title'], isset($chapterData['attributes']['volume']) ? (int) $chapterData['attributes']['volume'] : null, true, false, new \DateTimeImmutable() ); $this->mangaRepository->saveChapter($chapter); } $offset += $limit; $hasMore = count($feed['data']) === $limit; } } }