Browse Source

Miscellaneous style updates

Timothy J. Warren 4 months ago
parent
commit
fa2d79c77e

+ 0
- 21
src/API/AbstractListItem.php View File

@@ -1,21 +0,0 @@
1
-<?php declare(strict_types=1);
2
-/**
3
- * Hummingbird 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     HummingbirdAnimeClient
10
- * @author      Timothy J. Warren <tim@timshomepage.net>
11
- * @copyright   2015 - 2018  Timothy J. Warren
12
- * @license     http://www.opensource.org/licenses/mit-license.html  MIT License
13
- * @version     4.0
14
- * @link        https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
15
- */
16
-
17
-namespace Aviat\AnimeClient\API;
18
-
19
-abstract class AbstractListItem implements ListItemInterface {
20
-
21
-}

+ 6
- 4
src/API/Kitsu/ListItem.php View File

@@ -21,15 +21,17 @@ use const Aviat\AnimeClient\SESSION_SEGMENT;
21 21
 use function Amp\Promise\wait;
22 22
 
23 23
 use Amp\Artax\Request;
24
-use Aviat\AnimeClient\API\{AbstractListItem, HummingbirdClient};
24
+use Aviat\AnimeClient\API\{
25
+	HummingbirdClient,
26
+	ListItemInterface
27
+};
25 28
 use Aviat\Ion\Di\ContainerAware;
26 29
 use Aviat\Ion\Json;
27
-use RuntimeException;
28 30
 
29 31
 /**
30 32
  * CRUD operations for Kitsu list items
31 33
  */
32
-class ListItem extends AbstractListItem {
34
+class ListItem implements ListItemInterface {
33 35
 	use ContainerAware;
34 36
 	use KitsuTrait;
35 37
 
@@ -41,7 +43,7 @@ class ListItem extends AbstractListItem {
41 43
 			->get('session')
42 44
 			->getSegment(SESSION_SEGMENT);
43 45
 
44
-		if ( ! is_null($sessionSegment->get('auth_token')))
46
+		if ($sessionSegment->get('auth_token') !== NULL)
45 47
 		{
46 48
 			$token = $sessionSegment->get('auth_token');
47 49
 			return "bearer {$token}";

+ 1
- 1
src/API/Kitsu/Model.php View File

@@ -169,7 +169,7 @@ class Model {
169 169
 	 */
170 170
 	public function getUserIdByUsername(string $username = NULL): string
171 171
 	{
172
-		if (is_null($username))
172
+		if ($username === NULL)
173 173
 		{
174 174
 			$username = $this->getUsername();
175 175
 		}

+ 0
- 1
src/API/MAL/ListItem.php View File

@@ -18,7 +18,6 @@ namespace Aviat\AnimeClient\API\MAL;
18 18
 
19 19
 use Amp\Artax\{FormBody, Request};
20 20
 use Aviat\AnimeClient\API\{
21
-	AbstractListItem,
22 21
 	XML
23 22
 };
24 23
 use Aviat\Ion\Di\ContainerAware;

+ 1
- 2
src/API/MAL/MALRequestBuilder.php View File

@@ -18,8 +18,7 @@ namespace Aviat\AnimeClient\API\MAL;
18 18
 
19 19
 use Aviat\AnimeClient\API\{
20 20
 	APIRequestBuilder,
21
-	MAL as M,
22
-	XML
21
+	MAL as M
23 22
 };
24 23
 
25 24
 class MALRequestBuilder extends APIRequestBuilder {

+ 1
- 1
src/API/MAL/MALTrait.php View File

@@ -178,7 +178,7 @@ trait MALTrait {
178 178
 		$response = $this->getResponse('POST', ...$args);
179 179
 		$validResponseCodes = [200, 201];
180 180
 
181
-		if ( ! in_array((int) $response->getStatus(), $validResponseCodes))
181
+		if ( ! \in_array((int) $response->getStatus(), $validResponseCodes, TRUE))
182 182
 		{
183 183
 			if ($logger)
184 184
 			{

+ 1
- 1
src/API/ParallelAPIRequest.php View File

@@ -40,7 +40,7 @@ class ParallelAPIRequest {
40 40
 	 */
41 41
 	public function addRequest($request, $key = NULL): self
42 42
 	{
43
-		if ( ! is_null($key))
43
+		if ($key !== NULL)
44 44
 		{
45 45
 			$this->requests[$key] = $request;
46 46
 			return $this;

+ 7
- 9
src/API/XML.php View File

@@ -174,14 +174,12 @@ class XML {
174 174
 	 */
175 175
 	private static function stripXMLWhitespace(string $xml): string
176 176
 	{
177
-
178 177
 		// Get rid of unimportant text nodes by removing
179 178
 		// whitespace characters from between xml tags,
180 179
 		// except for the xml declaration tag, Which looks
181 180
 		// something like:
182 181
 		/* <?xml version="1.0" encoding="UTF-8"?> */
183
-
184
-		return preg_replace('/([^\?])>\s+</', '$1><', $xml);
182
+		return preg_replace('/([^?])>\s+</', '$1><', $xml);
185 183
 	}
186 184
 
187 185
 	/**
@@ -191,7 +189,7 @@ class XML {
191 189
 	 * @param DOMNodeList $nodeList The current NodeList object
192 190
 	 * @return void
193 191
 	 */
194
-	private static function childNodesToArray(array &$root, DOMNodelist $nodeList)
192
+	private static function childNodesToArray(array &$root, DOMNodelist $nodeList): void
195 193
 	{
196 194
 		$length = $nodeList->length;
197 195
 		for ($i = 0; $i < $length; $i++)
@@ -200,14 +198,14 @@ class XML {
200 198
 			$current =& $root[$el->nodeName];
201 199
 
202 200
 			// It's a top level element!
203
-			if (is_a($el->childNodes->item(0), 'DomText') OR ( ! $el->hasChildNodes()))
201
+			if (( ! $el->hasChildNodes()) || is_a($el->childNodes->item(0), 'DomText'))
204 202
 			{
205 203
 				$current = $el->textContent;
206 204
 				continue;
207 205
 			}
208 206
 
209 207
 			// An empty value at the current root
210
-			if (is_null($current))
208
+			if ($current === NULL)
211 209
 			{
212 210
 				$current = [];
213 211
 				static::childNodesToArray($current, $el->childNodes);
@@ -230,7 +228,7 @@ class XML {
230 228
 				$current = [$current];
231 229
 			}
232 230
 
233
-			array_push($current, []);
231
+			$current[] = [];
234 232
 			$index = count($current) - 1;
235 233
 
236 234
 			static::childNodesToArray($current[$index], $el->childNodes);
@@ -245,7 +243,7 @@ class XML {
245 243
 	 * @param array $data The data for the current node
246 244
 	 * @return void
247 245
 	 */
248
-	private static function arrayPropertiesToXmlNodes(DOMDocument &$dom, DOMNode &$parent, array $data)
246
+	private static function arrayPropertiesToXmlNodes(DOMDocument $dom, DOMNode $parent, array $data): void
249 247
 	{
250 248
 		foreach($data as $key => $props)
251 249
 		{
@@ -260,7 +258,7 @@ class XML {
260 258
 
261 259
 			$node = $dom->createElement($key);
262 260
 
263
-			if (is_array($props))
261
+			if (\is_array($props))
264 262
 			{
265 263
 				static::arrayPropertiesToXmlNodes($dom, $node, $props);
266 264
 			}

+ 6
- 9
src/Controller.php View File

@@ -22,10 +22,6 @@ use Aviat\Ion\Di\{
22 22
 	ContainerAware,
23 23
 	ContainerInterface
24 24
 };
25
-use Aviat\Ion\Di\Exception\{
26
-	ContainerException,
27
-	NotFoundException
28
-};
29 25
 use Aviat\Ion\Exception\DoubleRenderException;
30 26
 use Aviat\Ion\View\{HtmlView, HttpView, JsonView};
31 27
 use InvalidArgumentException;
@@ -92,9 +88,9 @@ class Controller {
92 88
 	/**
93 89
 	 * Constructor
94 90
 	 *
91
+	 * @throws \Aviat\Ion\Di\ContainerException
92
+	 * @throws \Aviat\Ion\Di\NotFoundException
95 93
 	 * @param ContainerInterface $container
96
-	 * @throws ContainerException
97
-	 * @throws NotFoundException
98 94
 	 */
99 95
 	public function __construct(ContainerInterface $container)
100 96
 	{
@@ -135,7 +131,7 @@ class Controller {
135 131
 	 *
136 132
 	 * @return void
137 133
 	 */
138
-	public function redirectToPrevious()
134
+	public function redirectToPrevious(): void
139 135
 	{
140 136
 		$previous = $this->session->getFlash('previous');
141 137
 		$this->redirect($previous, 303);
@@ -144,9 +140,9 @@ class Controller {
144 140
 	/**
145 141
 	 * Set the current url in the session as the target of a future redirect
146 142
 	 *
143
+	 * @throws \Aviat\Ion\Di\ContainerException
144
+	 * @throws \Aviat\Ion\Di\NotFoundException
147 145
 	 * @param string|null $url
148
-	 * @throws ContainerException
149
-	 * @throws NotFoundException
150 146
 	 * @return void
151 147
 	 */
152 148
 	public function setSessionRedirect(string $url = NULL): void
@@ -312,6 +308,7 @@ class Controller {
312 308
 	/**
313 309
 	 * Redirect to the default controller/url from an empty path
314 310
 	 *
311
+	 * @throws InvalidArgumentException
315 312
 	 * @return void
316 313
 	 */
317 314
 	public function redirectToDefaultRoute(): void

+ 40
- 10
src/Controller/Anime.php View File

@@ -41,6 +41,8 @@ class Anime extends BaseController {
41 41
 	 * Constructor
42 42
 	 *
43 43
 	 * @param ContainerInterface $container
44
+	 * @throws \Aviat\Ion\Di\ContainerException
45
+	 * @throws \Aviat\Ion\Di\NotFoundException
44 46
 	 */
45 47
 	public function __construct(ContainerInterface $container)
46 48
 	{
@@ -63,11 +65,14 @@ class Anime extends BaseController {
63 65
 	 *
64 66
 	 * @param string|int $type - The section of the list
65 67
 	 * @param string $view - List or cover view
68
+	 * @throws \Aviat\Ion\Di\ContainerException
69
+	 * @throws \Aviat\Ion\Di\NotFoundException
70
+	 * @throws \InvalidArgumentException
66 71
 	 * @return void
67 72
 	 */
68
-	public function index($type = KitsuWatchingStatus::WATCHING, string $view = NULL)
73
+	public function index($type = KitsuWatchingStatus::WATCHING, string $view = NULL): void
69 74
 	{
70
-		$title = (array_key_exists($type, AnimeWatchingStatus::ROUTE_TO_TITLE))
75
+		$title = array_key_exists($type, AnimeWatchingStatus::ROUTE_TO_TITLE)
71 76
 			? $this->formatTitle(
72 77
 				$this->config->get('whose_list') . "'s Anime List",
73 78
 				AnimeWatchingStatus::ROUTE_TO_TITLE[$type]
@@ -92,9 +97,13 @@ class Anime extends BaseController {
92 97
 	/**
93 98
 	 * Form to add an anime
94 99
 	 *
100
+	 * @throws \Aviat\Ion\Di\ContainerException
101
+	 * @throws \Aviat\Ion\Di\NotFoundException
102
+	 * @throws \Aura\Router\Exception\RouteNotFound
103
+	 * @throws \InvalidArgumentException
95 104
 	 * @return void
96 105
 	 */
97
-	public function addForm()
106
+	public function addForm(): void
98 107
 	{
99 108
 		$this->setSessionRedirect();
100 109
 		$this->outputHTML('anime/add', [
@@ -110,9 +119,11 @@ class Anime extends BaseController {
110 119
 	/**
111 120
 	 * Add an anime to the list
112 121
 	 *
122
+	 * @throws \Aviat\Ion\Di\ContainerException
123
+	 * @throws \Aviat\Ion\Di\NotFoundException
113 124
 	 * @return void
114 125
 	 */
115
-	public function add()
126
+	public function add(): void
116 127
 	{
117 128
 		$data = $this->request->getParsedBody();
118 129
 		if ( ! array_key_exists('id', $data))
@@ -140,9 +151,12 @@ class Anime extends BaseController {
140 151
 	 *
141 152
 	 * @param int $id
142 153
 	 * @param string $status
154
+	 * @throws \Aviat\Ion\Di\ContainerException
155
+	 * @throws \Aviat\Ion\Di\NotFoundException
156
+	 * @throws \InvalidArgumentException
143 157
 	 * @return void
144 158
 	 */
145
-	public function edit($id, $status = "all")
159
+	public function edit($id, $status = 'all'): void
146 160
 	{
147 161
 		$item = $this->model->getLibraryItem($id);
148 162
 		$this->setSessionRedirect();
@@ -165,7 +179,7 @@ class Anime extends BaseController {
165 179
 	 *
166 180
 	 * @return void
167 181
 	 */
168
-	public function search()
182
+	public function search(): void
169 183
 	{
170 184
 		$queryParams = $this->request->getQueryParams();
171 185
 		$query = $queryParams['query'];
@@ -175,9 +189,11 @@ class Anime extends BaseController {
175 189
 	/**
176 190
 	 * Update an anime item via a form submission
177 191
 	 *
192
+	 * @throws \Aviat\Ion\Di\ContainerException
193
+	 * @throws \Aviat\Ion\Di\NotFoundException
178 194
 	 * @return void
179 195
 	 */
180
-	public function formUpdate()
196
+	public function formUpdate(): void
181 197
 	{
182 198
 		$data = $this->request->getParsedBody();
183 199
 
@@ -205,7 +221,7 @@ class Anime extends BaseController {
205 221
 	 *
206 222
 	 * @return void
207 223
 	 */
208
-	public function update()
224
+	public function update(): void
209 225
 	{
210 226
 		if (stripos($this->request->getHeader('content-type')[0], 'application/json') !== FALSE)
211 227
 		{
@@ -225,9 +241,11 @@ class Anime extends BaseController {
225 241
 	/**
226 242
 	 * Remove an anime from the list
227 243
 	 *
244
+	 * @throws \Aviat\Ion\Di\ContainerException
245
+	 * @throws \Aviat\Ion\Di\NotFoundException
228 246
 	 * @return void
229 247
 	 */
230
-	public function delete()
248
+	public function delete(): void
231 249
 	{
232 250
 		$body = $this->request->getParsedBody();
233 251
 		$response = $this->model->deleteLibraryItem($body['id'], $body['mal_id']);
@@ -249,9 +267,12 @@ class Anime extends BaseController {
249 267
 	 * View details of an anime
250 268
 	 *
251 269
 	 * @param string $animeId
270
+	 * @throws \Aviat\Ion\Di\ContainerException
271
+	 * @throws \Aviat\Ion\Di\NotFoundException
272
+	 * @throws \InvalidArgumentException
252 273
 	 * @return void
253 274
 	 */
254
-	public function details(string $animeId)
275
+	public function details(string $animeId): void
255 276
 	{
256 277
 		$show_data = $this->model->getAnime($animeId);
257 278
 		$characters = [];
@@ -287,5 +308,14 @@ class Anime extends BaseController {
287 308
 		]);
288 309
 	}
289 310
 
311
+	/**
312
+	 * Find anime matching the selected genre
313
+	 *
314
+	 * @param string $genre
315
+	 */
316
+	public function genre(string $genre): void
317
+	{
318
+		// @TODO: implement
319
+	}
290 320
 }
291 321
 // End of AnimeController.php

+ 21
- 5
src/Controller/AnimeCollection.php View File

@@ -44,6 +44,8 @@ class AnimeCollection extends BaseController {
44 44
 	 * Constructor
45 45
 	 *
46 46
 	 * @param ContainerInterface $container
47
+	 * @throws \Aviat\Ion\Di\ContainerException
48
+	 * @throws \Aviat\Ion\Di\NotFoundException
47 49
 	 */
48 50
 	public function __construct(ContainerInterface $container)
49 51
 	{
@@ -63,6 +65,7 @@ class AnimeCollection extends BaseController {
63 65
 	/**
64 66
 	 * Search for anime
65 67
 	 *
68
+	 * @throws \Aviat\Ion\Exception\DoubleRenderException
66 69
 	 * @return void
67 70
 	 */
68 71
 	public function search()
@@ -76,6 +79,9 @@ class AnimeCollection extends BaseController {
76 79
 	 * Show the anime collection page
77 80
 	 *
78 81
 	 * @param string $view
82
+	 * @throws \Aviat\Ion\Di\ContainerException
83
+	 * @throws \Aviat\Ion\Di\NotFoundException
84
+	 * @throws \InvalidArgumentException
79 85
 	 * @return void
80 86
 	 */
81 87
 	public function index($view)
@@ -98,13 +104,17 @@ class AnimeCollection extends BaseController {
98 104
 	 * Show the anime collection add/edit form
99 105
 	 *
100 106
 	 * @param integer|null $id
107
+	 * @throws \Aviat\Ion\Di\ContainerException
108
+	 * @throws \Aviat\Ion\Di\NotFoundException
109
+	 * @throws \Aura\Router\Exception\RouteNotFound
110
+	 * @throws \InvalidArgumentException
101 111
 	 * @return void
102 112
 	 */
103 113
 	public function form($id = NULL)
104 114
 	{
105 115
 		$this->setSessionRedirect();
106 116
 
107
-		$action = (is_null($id)) ? "Add" : "Edit";
117
+		$action = $id === NULL ? 'Add' : 'Edit';
108 118
 		$urlAction = strtolower($action);
109 119
 
110 120
 		$this->outputHTML('collection/' . $urlAction, [
@@ -115,13 +125,16 @@ class AnimeCollection extends BaseController {
115 125
 				$action
116 126
 			),
117 127
 			'media_items' => $this->animeCollectionModel->getMediaTypeList(),
118
-			'item' => ($action === "Edit") ? $this->animeCollectionModel->get($id) : []
128
+			'item' => ($action === 'Edit') ? $this->animeCollectionModel->get($id) : []
119 129
 		]);
120 130
 	}
121 131
 
122 132
 	/**
123 133
 	 * Update a collection item
124 134
 	 *
135
+	 * @throws \Aviat\Ion\Di\ContainerException
136
+	 * @throws \Aviat\Ion\Di\NotFoundException
137
+	 * @throws \InvalidArgumentException
125 138
 	 * @return void
126 139
 	 */
127 140
 	public function edit()
@@ -143,6 +156,9 @@ class AnimeCollection extends BaseController {
143 156
 	/**
144 157
 	 * Add a collection item
145 158
 	 *
159
+	 * @throws \Aviat\Ion\Di\ContainerException
160
+	 * @throws \Aviat\Ion\Di\NotFoundException
161
+	 * @throws \InvalidArgumentException
146 162
 	 * @return void
147 163
 	 */
148 164
 	public function add()
@@ -171,13 +187,13 @@ class AnimeCollection extends BaseController {
171 187
 		$data = $this->request->getParsedBody();
172 188
 		if ( ! array_key_exists('hummingbird_id', $data))
173 189
 		{
174
-			$this->redirect("/anime-collection/view", 303);
190
+			$this->redirect('/anime-collection/view', 303);
175 191
 		}
176 192
 
177 193
 		$this->animeCollectionModel->delete($data);
178
-		$this->setFlashMessage("Successfully removed anime from collection.", 'success');
194
+		$this->setFlashMessage('Successfully removed anime from collection.', 'success');
179 195
 
180
-		$this->redirect("/anime-collection/view", 303);
196
+		$this->redirect('/anime-collection/view', 303);
181 197
 	}
182 198
 }
183 199
 // End of CollectionController.php

+ 18
- 10
src/Controller/Character.php View File

@@ -27,7 +27,16 @@ class Character extends BaseController {
27 27
 
28 28
 	use ArrayWrapper;
29 29
 
30
-	public function index(string $slug)
30
+	/**
31
+	 * Show information about a character
32
+	 *
33
+	 * @param string $slug
34
+	 * @throws \Aviat\Ion\Di\ContainerException
35
+	 * @throws \Aviat\Ion\Di\NotFoundException
36
+	 * @throws \InvalidArgumentException
37
+	 * @return void
38
+	 */
39
+	public function index(string $slug): void
31 40
 	{
32 41
 		$model = $this->container->get('kitsu-model');
33 42
 
@@ -88,8 +97,9 @@ class Character extends BaseController {
88 97
 
89 98
 
90 99
 			$person = current($role['relationships']['person']['people'])['attributes'];
100
+			$hasName = array_key_exists($person['name'], $people);
91 101
 
92
-			if ( ! array_key_exists($person['name'], $people))
102
+			if ( ! $hasName)
93 103
 			{
94 104
 				$people[$person['name']] = $i;
95 105
 				$role['relationships']['media']['anime'] = [current($role['relationships']['media']['anime'])];
@@ -99,15 +109,13 @@ class Character extends BaseController {
99 109
 
100 110
 				continue;
101 111
 			}
102
-			else if(array_key_exists($person['name'], $people))
112
+
113
+			if (array_key_exists('anime', $role['relationships']['media']))
103 114
 			{
104
-				if (array_key_exists('anime', $role['relationships']['media']))
105
-				{
106
-					$key = $people[$person['name']];
107
-					$output[$key]['relationships']['media']['anime'][] = current($role['relationships']['media']['anime']);
108
-				}
109
-				continue;
115
+				$key = $people[$person['name']];
116
+				$output[$key]['relationships']['media']['anime'][] = current($role['relationships']['media']['anime']);
110 117
 			}
118
+			continue;
111 119
 		}
112 120
 
113 121
 		return $output;
@@ -122,7 +130,7 @@ class Character extends BaseController {
122 130
 			if (
123 131
 				array_key_exists('attributes', $role) &&
124 132
 				array_key_exists('role', $role['attributes']) &&
125
-				( ! is_null($role['attributes']['role']))
133
+				$role['attributes']['role'] !== NULL
126 134
 			) {
127 135
 				$count++;
128 136
 			}

+ 34
- 5
src/Controller/Index.php View File

@@ -30,6 +30,9 @@ class Index extends BaseController {
30 30
 	/**
31 31
 	 * Purges the API cache
32 32
 	 *
33
+	 * @throws \Aviat\Ion\Di\ContainerException
34
+	 * @throws \Aviat\Ion\Di\NotFoundException
35
+	 * @throws \InvalidArgumentException
33 36
 	 * @return void
34 37
 	 */
35 38
 	public function clearCache()
@@ -37,13 +40,16 @@ class Index extends BaseController {
37 40
 		$this->cache->clear();
38 41
 		$this->outputHTML('blank', [
39 42
 			'title' => 'Cache cleared'
40
-		], NULL, 200);
43
+		]);
41 44
 	}
42 45
 
43 46
 	/**
44 47
 	 * Show the login form
45 48
 	 *
46 49
 	 * @param string $status
50
+	 * @throws \Aviat\Ion\Di\ContainerException
51
+	 * @throws \Aviat\Ion\Di\NotFoundException
52
+	 * @throws \InvalidArgumentException
47 53
 	 * @return void
48 54
 	 */
49 55
 	public function login(string $status = '')
@@ -69,6 +75,10 @@ class Index extends BaseController {
69 75
 	/**
70 76
 	 * Attempt login authentication
71 77
 	 *
78
+	 * @throws \Aviat\Ion\Di\ContainerException
79
+	 * @throws \Aviat\Ion\Di\NotFoundException
80
+	 * @throws \Aura\Router\Exception\RouteNotFound
81
+	 * @throws \InvalidArgumentException
72 82
 	 * @return void
73 83
 	 */
74 84
 	public function loginAction()
@@ -88,6 +98,9 @@ class Index extends BaseController {
88 98
 	/**
89 99
 	 * Deauthorize the current user
90 100
 	 *
101
+	 * @throws \Aviat\Ion\Di\ContainerException
102
+	 * @throws \Aviat\Ion\Di\NotFoundException
103
+	 * @throws \InvalidArgumentException
91 104
 	 * @return void
92 105
 	 */
93 106
 	public function logout()
@@ -101,6 +114,9 @@ class Index extends BaseController {
101 114
 	/**
102 115
 	 * Show the user profile page
103 116
 	 *
117
+	 * @throws \Aviat\Ion\Di\ContainerException
118
+	 * @throws \Aviat\Ion\Di\NotFoundException
119
+	 * @throws \InvalidArgumentException
104 120
 	 * @return void
105 121
 	 */
106 122
 	public function me()
@@ -111,8 +127,8 @@ class Index extends BaseController {
111 127
 		$orgData = JsonAPI::organizeData($data)[0];
112 128
 		$rels = $orgData['relationships'] ?? [];
113 129
 		$favorites = array_key_exists('favorites', $rels) ? $rels['favorites'] : [];
114
-		
115
-		
130
+
131
+
116 132
 		$this->outputHTML('me', [
117 133
 			'title' => 'About ' . $this->config->get('whose_list'),
118 134
 			'data' => $orgData,
@@ -125,9 +141,17 @@ class Index extends BaseController {
125 141
 	/**
126 142
 	 * Get image covers from kitsu
127 143
 	 *
144
+	 * @param string $type The category of image
145
+	 * @param string $file The filename to look for
146
+	 * @throws \Aviat\Ion\Di\ContainerException
147
+	 * @throws \Aviat\Ion\Di\NotFoundException
148
+	 * @throws \InvalidArgumentException
149
+	 * @throws \TypeError
150
+	 * @throws \Error
151
+	 * @throws \Throwable
128 152
 	 * @return void
129 153
 	 */
130
-	public function images($type, $file)
154
+	public function images(string $type, string $file): void
131 155
 	{
132 156
 		$kitsuUrl = 'https://media.kitsu.io/';
133 157
 		list($id, $ext) = explode('.', basename($file));
@@ -164,9 +188,14 @@ class Index extends BaseController {
164 188
 		echo $data;
165 189
 	}
166 190
 
191
+	/**
192
+	 * Reorganize favorites data to be more useful
193
+	 *
194
+	 * @param array $rawfavorites
195
+	 * @return array
196
+	 */
167 197
 	private function organizeFavorites(array $rawfavorites): array
168 198
 	{
169
-		// return $rawfavorites;
170 199
 		$output = [];
171 200
 
172 201
 		unset($rawfavorites['data']);

+ 44
- 10
src/Controller/Manga.php View File

@@ -40,6 +40,8 @@ class Manga extends Controller {
40 40
 	 * Constructor
41 41
 	 *
42 42
 	 * @param ContainerInterface $container
43
+	 * @throws \Aviat\Ion\Di\ContainerException
44
+	 * @throws \Aviat\Ion\Di\NotFoundException
43 45
 	 */
44 46
 	public function __construct(ContainerInterface $container)
45 47
 	{
@@ -59,9 +61,12 @@ class Manga extends Controller {
59 61
 	 *
60 62
 	 * @param string $status
61 63
 	 * @param string $view
64
+	 * @throws \Aviat\Ion\Di\ContainerException
65
+	 * @throws \Aviat\Ion\Di\NotFoundException
66
+	 * @throws \InvalidArgumentException
62 67
 	 * @return void
63 68
 	 */
64
-	public function index($status = "all", $view = "")
69
+	public function index($status = 'all', $view = ''): void
65 70
 	{
66 71
 		$statusTitle = MangaReadingStatus::ROUTE_TO_TITLE[$status];
67 72
 
@@ -88,9 +93,13 @@ class Manga extends Controller {
88 93
 	/**
89 94
 	 * Form to add an manga
90 95
 	 *
96
+	 * @throws \Aviat\Ion\Di\ContainerException
97
+	 * @throws \Aviat\Ion\Di\NotFoundException
98
+	 * @throws \Aura\Router\Exception\RouteNotFound
99
+	 * @throws \InvalidArgumentException
91 100
 	 * @return void
92 101
 	 */
93
-	public function addForm()
102
+	public function addForm(): void
94 103
 	{
95 104
 		$statuses = MangaReadingStatus::KITSU_TO_TITLE;
96 105
 
@@ -108,14 +117,16 @@ class Manga extends Controller {
108 117
 	/**
109 118
 	 * Add an manga to the list
110 119
 	 *
120
+	 * @throws \Aviat\Ion\Di\ContainerException
121
+	 * @throws \Aviat\Ion\Di\NotFoundException
111 122
 	 * @return void
112 123
 	 */
113
-	public function add()
124
+	public function add(): void
114 125
 	{
115 126
 		$data = $this->request->getParsedBody();
116 127
 		if ( ! array_key_exists('id', $data))
117 128
 		{
118
-			$this->redirect("manga/add", 303);
129
+			$this->redirect('manga/add', 303);
119 130
 		}
120 131
 
121 132
 		$result = $this->model->createLibraryItem($data);
@@ -138,9 +149,13 @@ class Manga extends Controller {
138 149
 	 *
139 150
 	 * @param string $id
140 151
 	 * @param string $status
152
+	 * @throws \Aviat\Ion\Di\ContainerException
153
+	 * @throws \Aviat\Ion\Di\NotFoundException
154
+	 * @throws \Aura\Router\Exception\RouteNotFound
155
+	 * @throws \InvalidArgumentException
141 156
 	 * @return void
142 157
 	 */
143
-	public function edit($id, $status = "All")
158
+	public function edit($id, $status = 'All'): void
144 159
 	{
145 160
 		$this->setSessionRedirect();
146 161
 		$item = $this->model->getLibraryItem($id);
@@ -164,7 +179,7 @@ class Manga extends Controller {
164 179
 	 *
165 180
 	 * @return void
166 181
 	 */
167
-	public function search()
182
+	public function search(): void
168 183
 	{
169 184
 		$query_data = $this->request->getQueryParams();
170 185
 		$this->outputJSON($this->model->search($query_data['query']));
@@ -173,9 +188,11 @@ class Manga extends Controller {
173 188
 	/**
174 189
 	 * Update an manga item via a form submission
175 190
 	 *
191
+	 * @throws \Aviat\Ion\Di\ContainerException
192
+	 * @throws \Aviat\Ion\Di\NotFoundException
176 193
 	 * @return void
177 194
 	 */
178
-	public function formUpdate()
195
+	public function formUpdate(): void
179 196
 	{
180 197
 		$data = $this->request->getParsedBody();
181 198
 
@@ -202,9 +219,11 @@ class Manga extends Controller {
202 219
 	/**
203 220
 	 * Update a manga item
204 221
 	 *
222
+	 * @throws \Aviat\Ion\Di\ContainerException
223
+	 * @throws \Aviat\Ion\Di\NotFoundException
205 224
 	 * @return void
206 225
 	 */
207
-	public function update()
226
+	public function update(): void
208 227
 	{
209 228
 		if (stripos($this->request->getHeader('content-type')[0], 'application/json') !== FALSE)
210 229
 		{
@@ -224,9 +243,11 @@ class Manga extends Controller {
224 243
 	/**
225 244
 	 * Remove an manga from the list
226 245
 	 *
246
+	 * @throws \Aviat\Ion\Di\ContainerException
247
+	 * @throws \Aviat\Ion\Di\NotFoundException
227 248
 	 * @return void
228 249
 	 */
229
-	public function delete()
250
+	public function delete(): void
230 251
 	{
231 252
 		$body = $this->request->getParsedBody();
232 253
 		$id = $body['id'];
@@ -250,9 +271,12 @@ class Manga extends Controller {
250 271
 	 * View details of an manga
251 272
 	 *
252 273
 	 * @param string $manga_id
274
+	 * @throws \Aviat\Ion\Di\ContainerException
275
+	 * @throws \Aviat\Ion\Di\NotFoundException
276
+	 * @throws \InvalidArgumentException
253 277
 	 * @return void
254 278
 	 */
255
-	public function details($manga_id)
279
+	public function details($manga_id): void
256 280
 	{
257 281
 		$data = $this->model->getManga($manga_id);
258 282
 		$characters = [];
@@ -286,5 +310,15 @@ class Manga extends Controller {
286 310
 			'data' => $data,
287 311
 		]);
288 312
 	}
313
+
314
+	/**
315
+	 * Find manga matching the selected genre
316
+	 *
317
+	 * @param string $genre
318
+	 */
319
+	public function genre(string $genre): void
320
+	{
321
+		// @TODO: implement
322
+	}
289 323
 }
290 324
 // End of MangaController.php

+ 25
- 9
src/Controller/MangaCollection.php View File

@@ -21,7 +21,6 @@ use Aviat\AnimeClient\Model\{
21 21
 	Manga as MangaModel,
22 22
 	MangaCollection as MangaCollectionModel
23 23
 };
24
-use Aviat\AnimeClient\UrlGenerator;
25 24
 use Aviat\Ion\Di\ContainerInterface;
26 25
 
27 26
 /**
@@ -45,6 +44,9 @@ class MangaCollection extends BaseController {
45 44
 	 * Constructor
46 45
 	 *
47 46
 	 * @param ContainerInterface $container
47
+	 * @throws \Aviat\Ion\Di\ContainerException
48
+	 * @throws \Aviat\Ion\Di\NotFoundException
49
+	 * @throws \InvalidArgumentException
48 50
 	 */
49 51
 	public function __construct(ContainerInterface $container)
50 52
 	{
@@ -64,9 +66,10 @@ class MangaCollection extends BaseController {
64 66
 	/**
65 67
 	 * Search for manga
66 68
 	 *
69
+	 * @throws \Aviat\Ion\Exception\DoubleRenderException
67 70
 	 * @return void
68 71
 	 */
69
-	public function search()
72
+	public function search(): void
70 73
 	{
71 74
 		$queryParams = $this->request->getQueryParams();
72 75
 		$query = $queryParams['query'];
@@ -77,9 +80,12 @@ class MangaCollection extends BaseController {
77 80
 	 * Show the manga collection page
78 81
 	 *
79 82
 	 * @param string $view
83
+	 * @throws \Aviat\Ion\Di\ContainerException
84
+	 * @throws \Aviat\Ion\Di\NotFoundException
85
+	 * @throws \InvalidArgumentException
80 86
 	 * @return void
81 87
 	 */
82
-	public function index($view)
88
+	public function index($view): void
83 89
 	{
84 90
 		$viewMap = [
85 91
 			'' => 'cover',
@@ -99,13 +105,17 @@ class MangaCollection extends BaseController {
99 105
 	 * Show the manga collection add/edit form
100 106
 	 *
101 107
 	 * @param integer|null $id
108
+	 * @throws \Aviat\Ion\Di\ContainerException
109
+	 * @throws \Aviat\Ion\Di\NotFoundException
110
+	 * @throws \Aura\Router\Exception\RouteNotFound
111
+	 * @throws \InvalidArgumentException
102 112
 	 * @return void
103 113
 	 */
104
-	public function form($id = NULL)
114
+	public function form($id = NULL): void
105 115
 	{
106 116
 		$this->setSessionRedirect();
107 117
 
108
-		$action = (is_null($id)) ? "Add" : "Edit";
118
+		$action = $id === NULL ? 'Add' : 'Edit';
109 119
 		$urlAction = strtolower($action);
110 120
 
111 121
 		$this->outputHTML('collection/' . $urlAction, [
@@ -116,13 +126,16 @@ class MangaCollection extends BaseController {
116 126
 				$action
117 127
 			),
118 128
 			'media_items' => $this->mangaCollectionModel->getMediaTypeList(),
119
-			'item' => ($action === "Edit") ? $this->mangaCollectionModel->get($id) : []
129
+			'item' => ($action === 'Edit') ? $this->mangaCollectionModel->get($id) : []
120 130
 		]);
121 131
 	}
122 132
 
123 133
 	/**
124 134
 	 * Update a collection item
125 135
 	 *
136
+	 * @throws \Aviat\Ion\Di\ContainerException
137
+	 * @throws \Aviat\Ion\Di\NotFoundException
138
+	 * @throws \InvalidArgumentException
126 139
 	 * @return void
127 140
 	 */
128 141
 	public function edit()
@@ -144,6 +157,9 @@ class MangaCollection extends BaseController {
144 157
 	/**
145 158
 	 * Add a collection item
146 159
 	 *
160
+	 * @throws \Aviat\Ion\Di\ContainerException
161
+	 * @throws \Aviat\Ion\Di\NotFoundException
162
+	 * @throws \InvalidArgumentException
147 163
 	 * @return void
148 164
 	 */
149 165
 	public function add()
@@ -172,13 +188,13 @@ class MangaCollection extends BaseController {
172 188
 		$data = $this->request->getParsedBody();
173 189
 		if ( ! array_key_exists('hummingbird_id', $data))
174 190
 		{
175
-			$this->redirect("/manga-collection/view", 303);
191
+			$this->redirect('/manga-collection/view', 303);
176 192
 		}
177 193
 
178 194
 		$this->mangaCollectionModel->delete($data);
179
-		$this->setFlashMessage("Successfully removed manga from collection.", 'success');
195
+		$this->setFlashMessage('Successfully removed manga from collection.', 'success');
180 196
 
181
-		$this->redirect("/manga-collection/view", 303);
197
+		$this->redirect('/manga-collection/view', 303);
182 198
 	}
183 199
 }
184 200
 // End of CollectionController.php

+ 9
- 7
src/Model/Manga.php View File

@@ -45,6 +45,8 @@ class Manga extends API
45 45
 	 * Constructor
46 46
 	 *
47 47
 	 * @param ContainerInterface $container
48
+	 * @throws \Aviat\Ion\Di\ContainerException
49
+	 * @throws \Aviat\Ion\Di\NotFoundException
48 50
 	 */
49 51
 	public function __construct(ContainerInterface $container)
50 52
 	{
@@ -61,7 +63,7 @@ class Manga extends API
61 63
 	 * @param string $status
62 64
 	 * @return array
63 65
 	 */
64
-	public function getList($status)
66
+	public function getList($status): array
65 67
 	{
66 68
 		if ($status === 'All')
67 69
 		{
@@ -79,7 +81,7 @@ class Manga extends API
79 81
 	 * @param string $manga_id
80 82
 	 * @return array
81 83
 	 */
82
-	public function getManga($manga_id)
84
+	public function getManga($manga_id): array
83 85
 	{
84 86
 		return $this->kitsuModel->getManga($manga_id);
85 87
 	}
@@ -122,7 +124,7 @@ class Manga extends API
122 124
 			$malData = $data;
123 125
 			$malId = $this->kitsuModel->getMalIdForManga($malData['id']);
124 126
 
125
-			if ( ! is_null($malId))
127
+			if ($malId !== NULL)
126 128
 			{
127 129
 				$malData['id'] = $malId;
128 130
 				$requester->addRequest($this->malModel->createListItem($malData, 'manga'), 'mal');
@@ -155,7 +157,7 @@ class Manga extends API
155 157
 
156 158
 		$results = $requester->makeRequests();
157 159
 		$body = Json::decode($results['kitsu']);
158
-		$statusCode = (array_key_exists('error', $body)) ? 400: 200;
160
+		$statusCode = array_key_exists('error', $body) ? 400: 200;
159 161
 
160 162
 		return [
161 163
 			'body' => Json::decode($results['kitsu']),
@@ -174,7 +176,7 @@ class Manga extends API
174 176
 	{
175 177
 		$requester = new ParallelAPIRequest();
176 178
 
177
-		if ($this->useMALAPI && ! is_null($malId))
179
+		if ($this->useMALAPI && $malId !== NULL)
178 180
 		{
179 181
 			$requester->addRequest($this->malModel->deleteListItem($malId, 'manga'), 'MAL');
180 182
 		}
@@ -192,7 +194,7 @@ class Manga extends API
192 194
 	 * @param string $name
193 195
 	 * @return array
194 196
 	 */
195
-	public function search($name)
197
+	public function search($name): array
196 198
 	{
197 199
 		return $this->kitsuModel->search('manga', $name);
198 200
 	}
@@ -203,7 +205,7 @@ class Manga extends API
203 205
 	 * @param array $data
204 206
 	 * @return array
205 207
 	 */
206
-	private function mapByStatus($data)
208
+	private function mapByStatus(array $data): array
207 209
 	{
208 210
 		$output = [
209 211
 			Title::READING => [],

+ 17
- 8
src/RoutingBase.php View File

@@ -54,6 +54,9 @@ class RoutingBase {
54 54
 	 * Constructor
55 55
 	 *
56 56
 	 * @param ContainerInterface $container
57
+	 * @throws \Aviat\Ion\Di\ContainerException
58
+	 * @throws \Aviat\Ion\Di\NotFoundException
59
+	 * @throws \Aviat\Ion\Exception\ConfigException
57 60
 	 */
58 61
 	public function __construct(ContainerInterface $container)
59 62
 	{
@@ -64,7 +67,7 @@ class RoutingBase {
64 67
 	}
65 68
 
66 69
 	/**
67
-	 * Retreive the appropriate value for the routing key
70
+	 * Retrieve the appropriate value for the routing key
68 71
 	 *
69 72
 	 * @param string $key
70 73
 	 * @return mixed
@@ -79,10 +82,11 @@ class RoutingBase {
79 82
 
80 83
 	/**
81 84
 	 * Get the current url path
82
-	 *
85
+	 * @throws \Aviat\Ion\Di\ContainerException
86
+	 * @throws \Aviat\Ion\Di\NotFoundException
83 87
 	 * @return string
84 88
 	 */
85
-	public function path()
89
+	public function path(): string
86 90
 	{
87 91
 		$request = $this->container->get('request');
88 92
 		$path = $request->getUri()->getPath();
@@ -97,10 +101,11 @@ class RoutingBase {
97 101
 
98 102
 	/**
99 103
 	 * Get the url segments
100
-	 *
104
+	 * @throws \Aviat\Ion\Di\ContainerException
105
+	 * @throws \Aviat\Ion\Di\NotFoundException
101 106
 	 * @return array
102 107
 	 */
103
-	public function segments()
108
+	public function segments(): array
104 109
 	{
105 110
 		$path = $this->path();
106 111
 		return explode('/', $path);
@@ -110,20 +115,24 @@ class RoutingBase {
110 115
 	 * Get a segment of the current url
111 116
 	 *
112 117
 	 * @param int $num
118
+	 * @throws \Aviat\Ion\Di\ContainerException
119
+	 * @throws \Aviat\Ion\Di\NotFoundException
113 120
 	 * @return string|null
114 121
 	 */
115
-	public function getSegment($num)
122
+	public function getSegment($num): ?string
116 123
 	{
117 124
 		$segments = $this->segments();
118
-		return (array_key_exists($num, $segments)) ? $segments[$num] : NULL;
125
+		return $segments[$num] ?? NULL;
119 126
 	}
120 127
 
121 128
 	/**
122 129
 	 * Retrieve the last url segment
123 130
 	 *
131
+	 * @throws \Aviat\Ion\Di\ContainerException
132
+	 * @throws \Aviat\Ion\Di\NotFoundException
124 133
 	 * @return string
125 134
 	 */
126
-	public function lastSegment()
135
+	public function lastSegment(): string
127 136
 	{
128 137
 		$segments = $this->segments();
129 138
 		return end($segments);

+ 9
- 7
src/UrlGenerator.php View File

@@ -34,6 +34,8 @@ class UrlGenerator extends RoutingBase {
34 34
 	 * Constructor
35 35
 	 *
36 36
 	 * @param ContainerInterface $container
37
+	 * @throws \Aviat\Ion\Di\ContainerException
38
+	 * @throws \Aviat\Ion\Di\NotFoundException
37 39
 	 */
38 40
 	public function __construct(ContainerInterface $container)
39 41
 	{
@@ -44,17 +46,17 @@ class UrlGenerator extends RoutingBase {
44 46
 	/**
45 47
 	 * Get the base url for css/js/images
46 48
 	 *
47
-	 * @param string ...$args url segments to apend to the base asset url
49
+	 * @param string[] ...$args
48 50
 	 * @return string
49 51
 	 */
50
-	public function assetUrl(...$args): string
52
+	public function assetUrl(string ...$args): string
51 53
 	{
52
-		$baseUrl = rtrim($this->url(""), '/');
53
-		$baseUrl = "{$baseUrl}" . $this->__get("asset_path");
54
+		$baseUrl = rtrim($this->url(''), '/')
55
+			. $this->__get('asset_path');
54 56
 
55 57
 		array_unshift($args, $baseUrl);
56 58
 
57
-		return implode("/", $args);
59
+		return implode('/', $args);
58 60
 	}
59 61
 
60 62
 	/**
@@ -82,7 +84,7 @@ class UrlGenerator extends RoutingBase {
82 84
 				$segments[$i + 1] = "";
83 85
 			}
84 86
 
85
-			$path_segments[$i] = preg_replace('`{.*?}`i', $segments[$i + 1], $path_segments[$i]);
87
+			$path_segments[$i] = preg_replace('`{.*?}`', $segments[$i + 1], $path_segments[$i]);
86 88
 		}
87 89
 		$path = implode('/', $path_segments);
88 90
 
@@ -101,7 +103,7 @@ class UrlGenerator extends RoutingBase {
101 103
 		$type = trim($type);
102 104
 		$defaultPath = $this->__get("default_{$type}_list_path");
103 105
 
104
-		if ( ! is_null($defaultPath))
106
+		if ($defaultPath !== NULL)
105 107
 		{
106 108
 			return $this->url("{$type}/{$defaultPath}");
107 109
 		}

+ 9
- 4
src/Util.php View File

@@ -18,7 +18,6 @@ namespace Aviat\AnimeClient;
18 18
 
19 19
 use Aviat\Ion\ConfigInterface;
20 20
 use Aviat\Ion\Di\{ContainerAware, ContainerInterface};
21
-use DomainException;
22 21
 
23 22
 /**
24 23
  * Utility method class
@@ -53,6 +52,8 @@ class Util {
53 52
 	 * Set up the Util class
54 53
 	 *
55 54
 	 * @param ContainerInterface $container
55
+	 * @throws \Aviat\Ion\Di\ContainerException
56
+	 * @throws \Aviat\Ion\Di\NotFoundException
56 57
 	 */
57 58
 	public function __construct(ContainerInterface $container)
58 59
 	{
@@ -87,12 +88,14 @@ class Util {
87 88
 	/**
88 89
 	 * Determine whether to show the sub-menu
89 90
 	 *
91
+	 * @throws \Aviat\Ion\Di\ContainerException
92
+	 * @throws \Aviat\Ion\Di\NotFoundException
90 93
 	 * @return bool
91 94
 	 */
92
-	public function isViewPage()
95
+	public function isViewPage(): bool
93 96
 	{
94 97
 		$url = $this->container->get('request')->getUri();
95
-		$pageSegments = explode("/", (string) $url);
98
+		$pageSegments = explode('/', (string) $url);
96 99
 
97 100
 		$intersect = array_intersect($pageSegments, self::$formPages);
98 101
 
@@ -103,9 +106,11 @@ class Util {
103 106
 	 * Determine whether the page is a page with a form, and
104 107
 	 * not suitable for redirection
105 108
 	 *
109
+	 * @throws \Aviat\Ion\Di\ContainerException
110
+	 * @throws \Aviat\Ion\Di\NotFoundException
106 111
 	 * @return boolean
107 112
 	 */
108
-	public function isFormPage()
113
+	public function isFormPage(): bool
109 114
 	{
110 115
 		return ! $this->isViewPage();
111 116
 	}