Issues (287)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Controller/Anime.php (6 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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\Controller;
18
19
use Aviat\AnimeClient\Controller as BaseController;
20
use Aviat\AnimeClient\API\Kitsu;
21
use Aviat\AnimeClient\API\Kitsu\Enum\AnimeWatchingStatus;
22
use Aviat\AnimeClient\API\Kitsu\Transformer\AnimeListTransformer;
23
use Aviat\Ion\Di\ContainerInterface;
24
use Aviat\Ion\Json;
25
use Aviat\Ion\StringWrapper;
26
27
/**
28
 * Controller for Anime-related pages
29
 */
30
class Anime extends BaseController {
31
32
	use StringWrapper;
33
34
	/**
35
	 * The anime list model
36
	 * @var object $model
37
	 */
38
	protected $model;
39
40
	/**
41
	 * Data to be sent to all routes in this controller
42
	 * @var array $base_data
43
	 */
44
	protected $base_data;
45
46
	/**
47
	 * Data cache
48
	 * @var Aviat\Ion\Cache\CacheInterface
49
	 */
50
	protected $cache;
51
52
	/**
53
	 * Constructor
54
	 *
55
	 * @param ContainerInterface $container
56
	 */
57 View Code Duplication
	public function __construct(ContainerInterface $container)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
58
	{
59
		parent::__construct($container);
60
61
		$this->model = $container->get('anime-model');
62
63
		$this->base_data = array_merge($this->base_data, [
64
			'menu_name' => 'anime_list',
65
			'url_type' => 'anime',
66
			'other_type' => 'manga',
67
			'config' => $this->config,
68
		]);
69
70
		$this->cache = $container->get('cache');
71
	}
72
73
	/**
74
	 * Show a portion, or all of the anime list
75
	 *
76
	 * @param string|int $type - The section of the list
77
	 * @param string $view - List or cover view
0 ignored issues
show
Should the type for parameter $view not be null|string?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
78
	 * @return void
79
	 */
80
	public function index($type = AnimeWatchingStatus::WATCHING, string $view = NULL)
81
	{
82
		$type_title_map = [
83
			'all' => 'All',
84
			AnimeWatchingStatus::WATCHING => 'Currently Watching',
85
			AnimeWatchingStatus::PLAN_TO_WATCH => 'Plan to Watch',
86
			AnimeWatchingStatus::ON_HOLD => 'On Hold',
87
			AnimeWatchingStatus::DROPPED => 'Dropped',
88
			AnimeWatchingStatus::COMPLETED => 'Completed'
89
		];
90
91
		$model_map = [
92
			'watching' => AnimeWatchingStatus::WATCHING,
93
			'plan_to_watch' => AnimeWatchingStatus::PLAN_TO_WATCH,
94
			'on_hold' => AnimeWatchingStatus::ON_HOLD,
95
			'all' => 'all',
96
			'dropped' => AnimeWatchingStatus::DROPPED,
97
			'completed' => AnimeWatchingStatus::COMPLETED
98
		];
99
100
		$title = (array_key_exists($type, $type_title_map))
101
			? $this->config->get('whose_list') .
102
				"'s Anime List &middot; {$type_title_map[$type]}"
103
			: '';
104
105
		$view_map = [
106
			'' => 'cover',
107
			'list' => 'list'
108
		];
109
110
		$data = ($type !== 'all')
111
			? $this->model->getList($model_map[$type])
112
			: $this->model->get_all_lists();
113
114
		$this->outputHTML('anime/' . $view_map[$view], [
115
			'title' => $title,
116
			'sections' => $data
117
		]);
118
	}
119
120
	/**
121
	 * Form to add an anime
122
	 *
123
	 * @return void
124
	 */
125
	public function add_form()
126
	{
127
		$statuses = [
128
			AnimeWatchingStatus::WATCHING => 'Currently Watching',
129
			AnimeWatchingStatus::PLAN_TO_WATCH => 'Plan to Watch',
130
			AnimeWatchingStatus::ON_HOLD => 'On Hold',
131
			AnimeWatchingStatus::DROPPED => 'Dropped',
132
			AnimeWatchingStatus::COMPLETED => 'Completed'
133
		];
134
135
		$this->set_session_redirect();
136
		$this->outputHTML('anime/add', [
137
			'title' => $this->config->get('whose_list') .
138
				"'s Anime List &middot; Add",
139
			'action_url' => $this->urlGenerator->url('anime/add'),
140
			'status_list' => $statuses
141
		]);
142
	}
143
144
	/**
145
	 * Add an anime to the list
146
	 *
147
	 * @return void
148
	 */
149 View Code Duplication
	public function add()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
150
	{
151
		$data = $this->request->getParsedBody();
152
		if ( ! array_key_exists('id', $data))
153
		{
154
			$this->redirect("anime/add", 303);
155
		}
156
157
		$result = $this->model->createLibraryItem($data);
158
159
		if ($result)
160
		{
161
			$this->set_flash_message('Added new anime to list', 'success');
162
			$this->cache->clear();
163
		}
164
		else
165
		{
166
			$this->set_flash_message('Failed to add new anime to list', 'error');
167
		}
168
169
		$this->session_redirect();
170
	}
171
172
	/**
173
	 * Form to edit details about a series
174
	 *
175
	 * @param int $id
176
	 * @param string $status
177
	 * @return void
178
	 */
179
	public function edit($id, $status = "all")
180
	{
181
		$item = $this->model->getLibraryItem($id, $status);
182
		$raw_status_list = AnimeWatchingStatus::getConstList();
183
184
		$statuses = [];
185
186
		foreach ($raw_status_list as $status_item)
187
		{
188
			$statuses[$status_item] = (string) $this->string($status_item)
189
				->underscored()
190
				->humanize()
191
				->titleize();
192
		}
193
194
		$this->set_session_redirect();
195
196
		$this->outputHTML('anime/edit', [
197
			'title' => $this->config->get('whose_list') .
198
				"'s Anime List &middot; Edit",
199
			'item' => $item,
200
			'statuses' => Kitsu::getStatusToSelectMap(),
201
			'action' => $this->container->get('url-generator')
202
				->url('/anime/update_form'),
203
		]);
204
	}
205
206
	/**
207
	 * Search for anime
208
	 *
209
	 * @return void
210
	 */
211
	public function search()
212
	{
213
		$queryParams = $this->request->getQueryParams();
214
		$query = $queryParams['query'];
215
		$this->outputJSON($this->model->search($query));
216
	}
217
218
	/**
219
	 * Update an anime item via a form submission
220
	 *
221
	 * @return void
222
	 */
223 View Code Duplication
	public function form_update()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
224
	{
225
		$data = $this->request->getParsedBody();
226
227
		// Do some minor data manipulation for
228
		// large form-based updates
229
		$transformer = new AnimeListTransformer();
230
		$post_data = $transformer->untransform($data);
231
		$full_result = $this->model->updateLibraryItem($post_data);
232
233
		if ($full_result['statusCode'] === 200)
234
		{
235
			$this->set_flash_message("Successfully updated.", 'success');
236
			$this->cache->clear();
237
		}
238
		else
239
		{
240
			$this->set_flash_message('Failed to update anime.', 'error');
241
		}
242
243
		$this->session_redirect();
244
	}
245
246
	/**
247
	 * Update an anime item
248
	 *
249
	 * @return void
250
	 */
251 View Code Duplication
	public function update()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
252
	{
253
		if ($this->request->getHeader('content-type')[0] === 'application/json')
254
		{
255
			$data = JSON::decode((string)$this->request->getBody());
256
		}
257
		else
258
		{
259
			$data = $this->request->getParsedBody();
260
		}
261
262
		$response = $this->model->updateLibraryItem($data, $data);
263
264
		$this->cache->clear();
265
		$this->outputJSON($response['body'], $response['statusCode']);
266
	}
267
268
	/**
269
	 * Remove an anime from the list
270
	 *
271
	 * @return void
272
	 */
273 View Code Duplication
	public function delete()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
274
	{
275
		$body = $this->request->getParsedBody();
276
		$response = $this->model->deleteLibraryItem($body['id'], $body['mal_id']);
277
278
		if ((bool)$response === TRUE)
279
		{
280
			$this->set_flash_message("Successfully deleted anime.", 'success');
281
			$this->cache->clear();
282
		}
283
		else
284
		{
285
			$this->set_flash_message('Failed to delete anime.', 'error');
286
		}
287
288
		$this->session_redirect();
289
	}
290
291
	/**
292
	 * View details of an anime
293
	 *
294
	 * @param string $anime_id
295
	 * @return void
296
	 */
297
	public function details($anime_id)
298
	{
299
		$data = $this->model->getAnime($anime_id);
300
301
		$this->outputHTML('anime/details', [
302
			'title' => 'Anime &middot ' . $data['titles'][0],
303
			'data' => $data,
304
		]);
305
	}
306
307
}
308
// End of AnimeController.php