Model   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 63
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 4

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A createListItem() 0 11 1
A getFullList() 0 16 1
A getListItem() 0 4 1
A updateListItem() 0 5 1
A deleteListItem() 0 4 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\MAL;
18
19
use Amp\Artax\Request;
20
use Aviat\AnimeClient\API\MAL as M;
21
use Aviat\AnimeClient\API\MAL\ListItem;
22
use Aviat\AnimeClient\API\MAL\Transformer\AnimeListTransformer;
23
use Aviat\AnimeClient\API\XML;
24
use Aviat\Ion\Di\ContainerAware;
25
26
/**
27
 * MyAnimeList API Model
28
 */
29
class Model {
30
	use ContainerAware;
31
	use MALTrait;
32
33
	/**
34
	 * @var AnimeListTransformer
35
	 */
36
	protected $animeListTransformer;
37
38
	/**
39
	 * KitsuModel constructor.
40
	 */
41
	public function __construct(ListItem $listItem)
42
	{
43
		$this->animeListTransformer = new AnimeListTransformer();
44
		$this->listItem = $listItem;
0 ignored issues
show
Bug introduced by
The property listItem does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
45
	}
46
47
	public function createListItem(array $data): Request
48
	{
49
		$createData = [
50
			'id' => $data['id'],
51
			'data' => [
52
				'status' => M::KITSU_MAL_WATCHING_STATUS_MAP[$data['status']]
53
			]
54
		];
55
56
		return $this->listItem->create($createData);
57
	}
58
59
	public function getFullList(): array
60
	{
61
		$config = $this->container->get('config');
62
		$userName = $config->get(['mal', 'username']);
63
		$list = $this->getRequest('https://myanimelist.net/malappinfo.php', [
64
			'headers' => [
65
				'Accept' => 'text/xml'
66
			],
67
			'query' => [
68
				'u' => $userName,
69
				'status' => 'all'
70
			]
71
		]);
72
73
		return $list;//['anime'];
74
	}
75
76
	public function getListItem(string $listId): array
0 ignored issues
show
Unused Code introduced by
The parameter $listId is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
77
	{
78
		return [];
79
	}
80
81
	public function updateListItem(array $data): Request
82
	{
83
		$updateData = $this->animeListTransformer->untransform($data);
84
		return $this->listItem->update($updateData['id'], $updateData['data']);
85
	}
86
87
	public function deleteListItem(string $id): Request
88
	{
89
		return $this->listItem->delete($id);
90
	}
91
}