ListItem   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 23 1
A delete() 0 17 1
A get() 0 4 1
A update() 0 21 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\{FormBody, Request};
20
use Aviat\AnimeClient\API\{
21
	AbstractListItem,
22
	XML
23
};
24
use Aviat\Ion\Di\ContainerAware;
25
26
/**
27
 * CRUD operations for MAL list items
28
 */
29
class ListItem {
30
	use ContainerAware;
31
	use MALTrait;
32
33
	public function create(array $data): Request
34
	{
35
		$id = $data['id'];
36
		$createData = [
37
			'id' => $id,
38
			'data' => XML::toXML([
39
				'entry' => $data['data']
40
			])
41
		];
42
43
		$config = $this->container->get('config');
44
45
		return $this->requestBuilder->newRequest('POST', "animelist/add/{$id}.xml")
46
			->setFormFields($createData)
47
			->setBasicAuth($config->get(['mal','username']), $config->get(['mal', 'password']))
48
			->getFullRequest();
49
50
		/* $response = $this->getResponse('POST', "animelist/add/{$id}.xml", [
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
51
			'body' => $this->fixBody((new FormBody)->addFields($createData))
52
		]);
53
54
		return $response->getBody() === 'Created'; */
55
	}
56
57
	public function delete(string $id): Request
58
	{
59
		$config = $this->container->get('config');
60
61
		return $this->requestBuilder->newRequest('DELETE', "animelist/delete/{$id}.xml")
62
			->setFormFields([
63
				'id' => $id
64
			])
65
			->setBasicAuth($config->get(['mal','username']), $config->get(['mal', 'password']))
66
			->getFullRequest();
67
68
		/*$response = $this->getResponse('DELETE', "animelist/delete/{$id}.xml", [
0 ignored issues
show
Unused Code Comprehensibility introduced by
61% 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
			'body' => $this->fixBody((new FormBody)->addField('id', $id))
70
		]);
71
72
		return $response->getBody() === 'Deleted';*/
73
	}
74
75
	public function get(string $id): array
0 ignored issues
show
Unused Code introduced by
The parameter $id 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...
76
	{
77
		return [];
78
	}
79
80
	public function update(string $id, array $data): Request
81
	{
82
		$config = $this->container->get('config');
83
84
		$xml = XML::toXML(['entry' => $data]);
85
		$body = (new FormBody)
0 ignored issues
show
Unused Code introduced by
$body 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...
86
			->addField('id', $id)
87
			->addField('data', $xml);
88
89
		return $this->requestBuilder->newRequest('POST', "animelist/update/{$id}.xml")
90
			->setFormFields([
91
				'id' => $id,
92
				'data' => $xml
93
			])
94
			->setBasicAuth($config->get(['mal','username']), $config->get(['mal', 'password']))
95
			->getFullRequest();
96
97
		/* return $this->getResponse('POST', "animelist/update/{$id}.xml", [
0 ignored issues
show
Unused Code Comprehensibility introduced by
66% 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...
98
			'body' => $this->fixBody($body)
99
		]); */
100
	}
101
}