diff --git a/api/src/BookRepository/GutendexBookRepository.php b/api/src/BookRepository/GutendexBookRepository.php index 6d1d2544..d93a9aec 100644 --- a/api/src/BookRepository/GutendexBookRepository.php +++ b/api/src/BookRepository/GutendexBookRepository.php @@ -5,14 +5,12 @@ namespace App\BookRepository; use App\Entity\Book; -use Symfony\Component\Serializer\Encoder\DecoderInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; final readonly class GutendexBookRepository implements RestrictedBookRepositoryInterface { public function __construct( private HttpClientInterface $gutendexClient, - private DecoderInterface $decoder, ) { } @@ -31,7 +29,7 @@ public function find(string $url): ?Book $book = new Book(); - $data = $this->decoder->decode($response->getContent(), 'json'); + $data = $response->toArray(); $book->title = $data['title']; $book->author = $data['authors'][0]['name'] ?? null; diff --git a/api/src/BookRepository/OpenLibraryBookRepository.php b/api/src/BookRepository/OpenLibraryBookRepository.php index 29d279e8..3f207137 100644 --- a/api/src/BookRepository/OpenLibraryBookRepository.php +++ b/api/src/BookRepository/OpenLibraryBookRepository.php @@ -5,14 +5,12 @@ namespace App\BookRepository; use App\Entity\Book; -use Symfony\Component\Serializer\Encoder\DecoderInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; final readonly class OpenLibraryBookRepository implements RestrictedBookRepositoryInterface { public function __construct( private HttpClientInterface $openLibraryClient, - private DecoderInterface $decoder, ) { } @@ -31,13 +29,13 @@ public function find(string $url): ?Book $book = new Book(); - $data = $this->decoder->decode($response->getContent(), 'json'); + $data = $response->toArray(); $book->title = $data['title']; $book->author = null; if (isset($data['authors'][0]['key'])) { $authorResponse = $this->openLibraryClient->request('GET', $data['authors'][0]['key'] . '.json', $options); - $author = $this->decoder->decode($authorResponse->getContent(), 'json'); + $author = $authorResponse->toArray(); if (isset($author['name'])) { $book->author = $author['name']; } diff --git a/api/src/Command/BooksImportCommand.php b/api/src/Command/BooksImportCommand.php index 1aa6ac59..62df7e57 100644 --- a/api/src/Command/BooksImportCommand.php +++ b/api/src/Command/BooksImportCommand.php @@ -12,7 +12,6 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\Serializer\Encoder\DecoderInterface; use Symfony\Component\Serializer\Encoder\JsonEncode; use Symfony\Component\Serializer\SerializerInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; @@ -25,7 +24,6 @@ final class BooksImportCommand extends Command { public function __construct( private readonly SerializerInterface $serializer, - private readonly DecoderInterface $decoder, private readonly HttpClientInterface $client, private readonly LoggerInterface $logger, ) { @@ -91,10 +89,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int private function getData(string $uri): array { - return $this->decoder->decode($this->client->request(Request::METHOD_GET, $uri, [ + return $this->client->request(Request::METHOD_GET, $uri, [ 'headers' => [ 'Accept' => 'application/json', ], - ])->getContent(), 'json'); + ])->toArray(); } }