HummingBirdAnimeClient/src/API/MAL/Transformer/AnimeListTransformer.php

86 lines
1.8 KiB
PHP
Raw Normal View History

2017-01-12 15:41:20 -05:00
<?php declare(strict_types=1);
/**
2017-02-15 16:13:32 -05:00
* Hummingbird Anime List Client
2017-01-12 15:41:20 -05:00
*
* An API client for Kitsu and MyAnimeList to manage anime and manga watch lists
*
* PHP version 7
*
2017-02-15 16:13:32 -05:00
* @package HummingbirdAnimeClient
2017-01-12 15:41:20 -05:00
* @author Timothy J. Warren <tim@timshomepage.net>
2018-01-15 14:43:15 -05:00
* @copyright 2015 - 2018 Timothy J. Warren
2017-01-12 15:41:20 -05:00
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.0
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
2017-01-12 15:41:20 -05:00
*/
2017-02-04 15:18:34 -05:00
namespace Aviat\AnimeClient\API\MAL\Transformer;
2017-01-12 15:41:20 -05:00
use Aviat\AnimeClient\API\Mapping\AnimeWatchingStatus;
use Aviat\AnimeClient\Types\{AnimeFormItem, AnimeFormItemData};
2017-01-12 15:41:20 -05:00
use Aviat\Ion\Transformer\AbstractTransformer;
/**
* Transformer for updating MAL List
*/
final class AnimeListTransformer extends AbstractTransformer {
/**
* Identity transformation
*
* @param array $item
* @return array
*/
2017-01-12 15:41:20 -05:00
public function transform($item)
{
return $item;
2017-01-12 15:41:20 -05:00
}
2017-02-04 15:18:34 -05:00
/**
* Transform Kitsu episode data to MAL episode data
*
* @param array $item
* @return AnimeFormItem
2017-02-04 15:18:34 -05:00
*/
public function untransform(array $item): AnimeFormItem
{
$map = new AnimeFormItem([
2017-02-04 15:18:34 -05:00
'id' => $item['mal_id'],
'data' => new AnimeFormItemData([]),
]);
foreach($item['data'] as $key => $value)
{
switch($key)
{
case 'progress':
$map['data']['episode'] = $value;
break;
case 'notes':
$map['data']['comments'] = $value;
break;
case 'rating':
$map['data']['score'] = $value * 2;
break;
2017-02-13 13:33:01 -05:00
case 'reconsuming':
$map['data']['enable_rewatching'] = (bool) $value;
break;
case 'reconsumeCount':
$map['data']['times_rewatched'] = $value;
2017-02-13 13:33:01 -05:00
break;
case 'status':
$map['data']['status'] = AnimeWatchingStatus::KITSU_TO_MAL[$value];
break;
default:
break;
}
}
2017-02-04 15:18:34 -05:00
return $map;
}
2017-01-12 15:41:20 -05:00
}