Completed
Branch develop (205409)
by Timothy
07:06
created

AnimeListTransformer::untransform()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 26
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 11
nc 8
nop 1
dl 0
loc 26
rs 8.5806
c 0
b 0
f 0
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\MAL\Transformer;
18
19
use Aviat\AnimeClient\API\Kitsu\Enum\AnimeWatchingStatus;
20
use Aviat\Ion\Transformer\AbstractTransformer;
21
22
/**
23
 * Transformer for updating MAL List
24
 */
25
class AnimeListTransformer extends AbstractTransformer {
26
	
27
	const statusMap = [
0 ignored issues
show
Coding Style introduced by
This class constant is not uppercase (expected STATUSMAP).
Loading history...
28
		AnimeWatchingStatus::WATCHING => '1',
29
		AnimeWatchingStatus::COMPLETED => '2',
30
		AnimeWatchingStatus::ON_HOLD => '3',
31
		AnimeWatchingStatus::DROPPED => '4',
32
		AnimeWatchingStatus::PLAN_TO_WATCH => '6'
33
	];
34
35
	public function transform($item)
36
	{
37
		$rewatching = (array_key_exists('rewatching', $item) && $item['rewatching']);
38
39
		return [
40
			'id' => $item['mal_id'],
41
			'data' => [
42
				'status' => self::statusMap[$item['watching_status']],
43
				'rating' => $item['user_rating'],
44
				'rewatch_value' => (int) $rewatching,
45
				'times_rewatched' => $item['rewatched'],
46
				'comments' => $item['notes'],
47
				'episode' => $item['episodes_watched']
48
			]
49
		];
50
	}
51
	
52
	/**
53
	 * Transform Kitsu episode data to MAL episode data
54
	 *
55
	 * @param array $item
56
	 * @return array 
57
	 */
58
	public function untransform(array $item): array
59
	{
60
		$rewatching = (array_key_exists('reconsuming', $item['data']) && $item['data']['reconsuming']);
0 ignored issues
show
Unused Code introduced by
$rewatching is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
61
		
62
		$map = [
63
			'id' => $item['mal_id'],
64
			'data' => [
65
				'episode' => $item['data']['progress'],
66
				// 'enable_rewatching' => $rewatching,
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

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.

Loading history...
67
				// 'times_rewatched' => $item['data']['reconsumeCount'],
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% of this comment could be valid code. Did you maybe forget this after debugging?

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.

Loading history...
68
				// 'comments' => $item['data']['notes'],
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% of this comment could be valid code. Did you maybe forget this after debugging?

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.

Loading history...
69
			]
70
		];
71
		
72
		if (array_key_exists('rating', $item['data']))
73
		{
74
			$map['data']['score'] = $item['data']['rating'] * 2;
75
		}
76
		
77
		if (array_key_exists('status', $item['data']))
78
		{
79
			$map['data']['status'] = self::statusMap[$item['data']['status']];
80
		}
81
		
82
		return $map;
83
	}
84
}