Small code consistency update

This commit is contained in:
Timothy Warren 2018-10-29 15:48:54 -04:00
parent be2f7708ad
commit 3842df13db
3 changed files with 80 additions and 19 deletions

View File

@ -373,8 +373,6 @@ final class Model {
} }
return $this->animeTransformer->transform($baseData); return $this->animeTransformer->transform($baseData);
// $transformed['included'] = JsonAPI::organizeIncluded($baseData['included']);
// return $transformed;
} }
/** /**
@ -614,9 +612,7 @@ final class Model {
return new MangaPage([]); return new MangaPage([]);
} }
$transformed = $this->mangaTransformer->transform($baseData); return $this->mangaTransformer->transform($baseData);
$transformed['included'] = JsonAPI::organizeIncluded($baseData['included']);
return $transformed;
} }
/** /**

View File

@ -16,6 +16,7 @@
namespace Aviat\AnimeClient\API\Kitsu\Transformer; namespace Aviat\AnimeClient\API\Kitsu\Transformer;
use Aviat\AnimeClient\API\JsonAPI;
use Aviat\AnimeClient\Types\MangaPage; use Aviat\AnimeClient\Types\MangaPage;
use Aviat\Ion\Transformer\AbstractTransformer; use Aviat\Ion\Transformer\AbstractTransformer;
@ -35,31 +36,33 @@ final class MangaTransformer extends AbstractTransformer {
{ {
$genres = []; $genres = [];
foreach($item['included'] as $included) $item['included'] = JsonAPI::organizeIncluded($item['included']);
{
if ($included['type'] === 'categories')
{
$genres[] = $included['attributes']['title'];
}
}
if (array_key_exists('categories', $item['included']))
{
foreach ($item['included']['categories'] as $cat)
{
$genres[] = $cat['attributes']['title'];
}
sort($genres); sort($genres);
}
$title = $item['canonicalTitle']; $title = $item['canonicalTitle'];
$rawTitles = array_values($item['titles']); $rawTitles = array_values($item['titles']);
$titles = array_unique(array_diff($rawTitles, [$title])); $titles = array_unique(array_diff($rawTitles, [$title]));
return new MangaPage([ return new MangaPage([
'chapter_count' => $this->count($item['chapterCount']),
'cover_image' => $item['posterImage']['small'],
'genres' => $genres,
'id' => $item['id'], 'id' => $item['id'],
'included' => $item['included'],
'manga_type' => $item['mangaType'],
'synopsis' => $item['synopsis'],
'title' => $title, 'title' => $title,
'titles' => $titles, 'titles' => $titles,
'cover_image' => $item['posterImage']['small'],
'manga_type' => $item['mangaType'],
'chapter_count' => $this->count($item['chapterCount']),
'volume_count' => $this->count($item['volumeCount']),
'synopsis' => $item['synopsis'],
'url' => "https://kitsu.io/manga/{$item['slug']}", 'url' => "https://kitsu.io/manga/{$item['slug']}",
'genres' => $genres, 'volume_count' => $this->count($item['volumeCount']),
]); ]);
} }

View File

@ -5,6 +5,68 @@
array ( array (
), ),
'id' => '20286', 'id' => '20286',
'included' =>
array (
'genres' =>
array (
3 =>
array (
'attributes' =>
array (
'name' => 'Comedy',
'slug' => 'comedy',
'description' => NULL,
),
),
24 =>
array (
'attributes' =>
array (
'name' => 'School',
'slug' => 'school',
'description' => NULL,
),
),
16 =>
array (
'attributes' =>
array (
'name' => 'Slice of Life',
'slug' => 'slice-of-life',
'description' => '',
),
),
14 =>
array (
'attributes' =>
array (
'name' => 'Romance',
'slug' => 'romance',
'description' => '',
),
),
18 =>
array (
'attributes' =>
array (
'name' => 'Thriller',
'slug' => 'thriller',
'description' => NULL,
),
),
),
'mappings' =>
array (
48014 =>
array (
'attributes' =>
array (
'externalSite' => 'myanimelist/manga',
'externalId' => '26769',
),
),
),
),
'manga_type' => 'manga', 'manga_type' => 'manga',
'synopsis' => 'Usa, a high-school student aspiring to begin a bachelor lifestyle, moves into a new apartment only to discover that he not only shares a room with a perverted roommate that has an obsession for underaged girls, but also that another girl, Ritsu, a love-at-first-sight, is living in the same building as well! 'synopsis' => 'Usa, a high-school student aspiring to begin a bachelor lifestyle, moves into a new apartment only to discover that he not only shares a room with a perverted roommate that has an obsession for underaged girls, but also that another girl, Ritsu, a love-at-first-sight, is living in the same building as well!
(Source: Kirei Cake)', (Source: Kirei Cake)',