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\Kitsu; |
20
|
|
|
use Aviat\Ion\StringWrapper; |
21
|
|
|
use Aviat\Ion\Transformer\AbstractTransformer; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Data transformation class for zippered Hummingbird manga |
25
|
|
|
*/ |
26
|
|
|
class MangaListTransformer extends AbstractTransformer { |
27
|
|
|
|
28
|
|
|
use StringWrapper; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Remap zipped anime data to a more logical form |
32
|
|
|
* |
33
|
|
|
* @param array $item manga entry item |
34
|
|
|
* @return array |
35
|
|
|
*/ |
36
|
|
|
public function transform($item) |
37
|
|
|
{ |
38
|
|
|
/*?><pre><?= print_r($item, TRUE) ?></pre><?php*/ |
39
|
|
|
$manga =& $item['manga']; |
40
|
|
|
|
41
|
|
|
$rating = (is_numeric($item['attributes']['rating'])) |
42
|
|
|
? intval(2 * $item['attributes']['rating']) |
43
|
|
|
: '-'; |
44
|
|
|
|
45
|
|
|
$total_chapters = ($manga['attributes']['chapterCount'] > 0) |
46
|
|
|
? $manga['attributes']['chapterCount'] |
47
|
|
|
: '-'; |
48
|
|
|
|
49
|
|
|
$total_volumes = ($manga['attributes']['volumeCount'] > 0) |
50
|
|
|
? $manga['attributes']['volumeCount'] |
51
|
|
|
: '-'; |
52
|
|
|
|
53
|
|
|
$map = [ |
54
|
|
|
'id' => $item['id'], |
55
|
|
|
'chapters' => [ |
56
|
|
|
'read' => $item['attributes']['progress'], |
57
|
|
|
'total' => $total_chapters |
58
|
|
|
], |
59
|
|
|
'volumes' => [ |
60
|
|
|
'read' => '-', //$item['attributes']['volumes_read'], |
|
|
|
|
61
|
|
|
'total' => $total_volumes |
62
|
|
|
], |
63
|
|
|
'manga' => [ |
64
|
|
|
'titles' => Kitsu::filterTitles($manga['attributes']), |
65
|
|
|
'alternate_title' => NULL, |
66
|
|
|
'slug' => $manga['attributes']['slug'], |
67
|
|
|
'url' => 'https://kitsu.io/manga/' . $manga['attributes']['slug'], |
68
|
|
|
'type' => $manga['attributes']['mangaType'], |
69
|
|
|
'image' => $manga['attributes']['posterImage']['small'], |
70
|
|
|
'genres' => [], //$manga['genres'], |
71
|
|
|
], |
72
|
|
|
'reading_status' => $item['attributes']['status'], |
73
|
|
|
'notes' => $item['attributes']['notes'], |
74
|
|
|
'rereading' => (bool)$item['attributes']['reconsuming'], |
75
|
|
|
'reread' => $item['attributes']['reconsumeCount'], |
76
|
|
|
'user_rating' => $rating, |
77
|
|
|
]; |
78
|
|
|
|
79
|
|
|
return $map; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Untransform data to update the api |
84
|
|
|
* |
85
|
|
|
* @param array $item |
86
|
|
|
* @return array |
87
|
|
|
*/ |
88
|
|
|
public function untransform($item) |
89
|
|
|
{ |
90
|
|
|
$rereading = (array_key_exists('rereading', $item)) && (bool)$item['rereading']; |
91
|
|
|
|
92
|
|
|
$map = [ |
93
|
|
|
'id' => $item['id'], |
94
|
|
|
'data' => [ |
95
|
|
|
'status' => $item['status'], |
96
|
|
|
'progress' => (int)$item['chapters_read'], |
97
|
|
|
'reconsuming' => $rereading, |
98
|
|
|
'reconsumeCount' => (int)$item['reread_count'], |
99
|
|
|
'notes' => $item['notes'], |
100
|
|
|
'rating' => $item['new_rating'] / 2 |
101
|
|
|
], |
102
|
|
|
]; |
103
|
|
|
|
104
|
|
|
return $map; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
// End of MangaListTransformer.php |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.