From 8fe2114816e10bbbf5bc99fd14f32344e0452c32 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Wed, 29 Jul 2020 20:06:59 -0400 Subject: [PATCH] Small fixes for anime detail pages --- .../API/Kitsu/Transformer/AnimeTransformer.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/AnimeClient/API/Kitsu/Transformer/AnimeTransformer.php b/src/AnimeClient/API/Kitsu/Transformer/AnimeTransformer.php index c95202f6..4d3ba420 100644 --- a/src/AnimeClient/API/Kitsu/Transformer/AnimeTransformer.php +++ b/src/AnimeClient/API/Kitsu/Transformer/AnimeTransformer.php @@ -34,6 +34,10 @@ final class AnimeTransformer extends AbstractTransformer { */ public function transform($item): AnimePage { + // TODO: missing GraphQL data: + // * streaming links + // * show type + $base = array_key_exists('findAnimeBySlug', $item['data']) ? $item['data']['findAnimeBySlug'] : $item['data']['findAnimeById']; @@ -65,6 +69,11 @@ final class AnimeTransformer extends AbstractTransformer { uasort($characters['main'], fn($a, $b) => $a['name'] <=> $b['name']); uasort($characters['supporting'], fn($a, $b) => $a['name'] <=> $b['name']); + + if (empty($characters['supporting'])) + { + unset($characters['supporting']); + } } if (count($base['staff']['nodes']) > 0) @@ -94,8 +103,7 @@ final class AnimeTransformer extends AbstractTransformer { ksort($staff); } - // @TODO: Streaming Links - $data = [ + return AnimePage::from([ 'age_rating' => $base['ageRating'], 'age_rating_guide' => $base['ageRatingGuide'], 'characters' => $characters, @@ -116,8 +124,6 @@ final class AnimeTransformer extends AbstractTransformer { 'total_length' => $base['totalLength'], 'trailer_id' => $base['youtubeTrailerVideoId'], 'url' => "https://kitsu.io/anime/{$base['slug']}", - ]; - - return AnimePage::from($data); + ]); } } \ No newline at end of file