Completed
Branch master (205409)
by Timothy
02:36
created

AnimeTransformer   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 1
lcom 0
cbo 5

1 Method

Rating   Name   Duplication   Size   Complexity  
B transform() 0 25 1
1
<?php declare(strict_types=1);
2
/**
3
 * Anime List Client
4
 *
5
 * An API client for Kitsu and MyAnimeList to manage anime and manga watch lists
6
 *
7
 * PHP version 7
8
 *
9
 * @package     AnimeListClient
10
 * @author      Timothy J. Warren <[email protected]>
11
 * @copyright   2015 - 2017  Timothy J. Warren
12
 * @license     http://www.opensource.org/licenses/mit-license.html  MIT License
13
 * @version     4.0
14
 * @link        https://github.com/timw4mail/HummingBirdAnimeClient
15
 */
16
17
namespace Aviat\AnimeClient\API\Kitsu\Transformer;
18
19
use Aviat\AnimeClient\API\{JsonAPI, Kitsu};
20
use Aviat\Ion\Transformer\AbstractTransformer;
21
22
/**
23
 * Transformer for anime description page
24
 */
25
class AnimeTransformer extends AbstractTransformer {
26
27
	/**
28
	 * Convert raw api response to a more
29
	 * logical and workable structure
30
	 *
31
	 * @param  array  $item API library item
32
	 * @return array
33
	 */
34
	public function transform($item)
35
	{
36
		$item['included'] = JsonAPI::organizeIncludes($item['included']);
37
		$item['genres'] = array_column($item['included']['genres'], 'name') ?? [];
38
		sort($item['genres']);
39
		
40
		$titles = Kitsu::filterTitles($item);
41
42
		return [
43
			'slug' => $item['slug'],
44
			'title' => $titles[0],
45
			'titles' => $titles,
46
			'status' => Kitsu::getAiringStatus($item['startDate'], $item['endDate']),
47
			'cover_image' => $item['posterImage']['small'],
48
			'show_type' => $this->string($item['showType'])->upperCaseFirst()->__toString(),
49
			'episode_count' => $item['episodeCount'],
50
			'episode_length' => $item['episodeLength'],
51
			'synopsis' => $item['synopsis'],
52
			'age_rating' => $item['ageRating'],
53
			'age_rating_guide' => $item['ageRatingGuide'],
54
			'url' => "https://kitsu.io/anime/{$item['slug']}",
55
			'genres' => $item['genres'],
56
			'streaming_links' => Kitsu::parseStreamingLinks($item['included'])
57
		];
58
	}
59
}