Browse Source

Lots of style fixes and minor logic tweaks

Timothy J. Warren 9 months ago
parent
commit
dc9d7ab4e1

+ 1
- 4
app/appConf/routes.php View File

@@ -16,17 +16,14 @@
16 16
 
17 17
 
18 18
 use const Aviat\AnimeClient\{
19
-	DEFAULT_CONTROLLER_NAMESPACE,
20 19
 	DEFAULT_CONTROLLER_METHOD,
21 20
 	DEFAULT_CONTROLLER
22 21
 };
23 22
 
24
-use Aviat\AnimeClient\AnimeClient;
25
-
26 23
 // -------------------------------------------------------------------------
27 24
 // Routing Config
28 25
 //
29
-// Maps paths to controlers and methods
26
+// Maps paths to controllers and methods
30 27
 // -------------------------------------------------------------------------
31 28
 return [
32 29
 	// ---------------------------------------------------------------------

+ 11
- 3
composer.json View File

@@ -4,6 +4,7 @@
4 4
   "license": "MIT",
5 5
   "autoload": {
6 6
 	"files": [
7
+	  "src/constants.php",
7 8
 	  "src/AnimeClient.php"
8 9
 	],
9 10
 	"psr-4": {
@@ -22,7 +23,7 @@
22 23
 	"aura/router": "^3.0",
23 24
 	"aura/session": "^2.0",
24 25
 	"aviat/banker": "^1.0.0",
25
-	"aviat/ion": "^2.2.0",
26
+	"aviat/ion": "^2.3.0",
26 27
 	"maximebf/consolekit": "^1.0",
27 28
 	"monolog/monolog": "^1.0",
28 29
 	"psr/http-message": "~1.0",
@@ -51,9 +52,16 @@
51 52
 	"build:css": "cd public && npm run build && cd ..",
52 53
 	"clean": "vendor/bin/robo clean",
53 54
 	"coverage": "phpdbg -qrr -- vendor/bin/phpunit -c build",
54
-	"docs": "vendor/bin/phpdox",
55
-	"phpstan": "phpstan analyse -l 3 ./phpstan.neon src tests",
55
+	"phpstan": "phpstan analyse -l 4 -c phpstan.neon src tests ./console index.php",
56 56
 	"watch:css": "cd public && npm run watch",
57 57
 	"test": "vendor/bin/phpunit"
58
+  },
59
+  "scripts-descriptions": {
60
+	"build": "Generate the api docs",
61
+	"build:css": "Generate browser css",
62
+	"clean": "Remove documentation generation files and folders",
63
+	"coverage": "Generate a test coverage report",
64
+	"phpstan": "Run PHP Static analysis",
65
+	"test": "Run the unit tests"
58 66
   }
59 67
 }

+ 17
- 18
console View File

@@ -2,30 +2,29 @@
2 2
 <?php declare(strict_types=1);
3 3
 
4 4
 // Set up autoloader for third-party dependencies
5
-require_once realpath(__DIR__ . '/vendor/autoload.php');
5
+require_once __DIR__ . '/vendor/autoload.php';
6 6
 
7 7
 use Aviat\AnimeClient\Command;
8 8
 
9 9
 $_SERVER['HTTP_HOST'] = 'localhost';
10 10
 
11
-// Define base directories
12
-$APP_DIR = __DIR__ . '/app/';
13
-$SRC_DIR = __DIR__ . '/src/';
14
-$CONF_DIR = realpath("${APP_DIR}/config/");
15
-
16
-// Unset 'constants'
17
-unset($APP_DIR);
18
-unset($SRC_DIR);
19
-unset($CONF_DIR);
20
-
21 11
 // -----------------------------------------------------------------------------
22 12
 // Start console script
23 13
 // -----------------------------------------------------------------------------
24
-$console = new \ConsoleKit\Console([
25
-	'cache-prime' => Command\CachePrime::class,
26
-	'cache-clear' => Command\CacheClear::class,
27
-	'clear-cache' => Command\CacheClear::class,
28
-	'sync-lists' => Command\SyncKitsuWithMal::class,
29
-]);
14
+try
15
+{
16
+	(new \ConsoleKit\Console([
17
+		'cache:clear' => Command\CacheClear::class,
18
+		'cache:prime' => Command\CachePrime::class,
19
+		'lists:sync' => Command\SyncKitsuWithMal::class,
20
+		'cache-prime' => Command\CachePrime::class,
21
+		'cache-clear' => Command\CacheClear::class,
22
+		'clear-cache' => Command\CacheClear::class,
23
+		'sync-lists' => Command\SyncKitsuWithMal::class,
24
+	]))->run();
25
+}
26
+catch (\Exception $e)
27
+{
28
+
29
+}
30 30
 
31
-$console->run();

+ 1
- 1
index.php View File

@@ -41,7 +41,7 @@ $CONF_DIR = _dir($APP_DIR, 'config');
41 41
 // Dependency Injection setup
42 42
 // -----------------------------------------------------------------------------
43 43
 $base_config = require $APPCONF_DIR . '/base_config.php';
44
-$di = require_once $APP_DIR . '/bootstrap.php';
44
+$di = require $APP_DIR . '/bootstrap.php';
45 45
 
46 46
 $config = loadToml($CONF_DIR);
47 47
 $config_array = array_merge($base_config, $config);

+ 6
- 4
phpstan.neon View File

@@ -1,7 +1,9 @@
1 1
 parameters:
2
+	autoload_files:
3
+		- %rootDir%/../../../tests/mocks.php
2 4
 	ignoreErrors:
3 5
 		- '#Access to an undefined property Aviat\\\Ion\\\Friend::\$[a-zA-Z0-9_]+#'
4
-		- '#Call to an undefined method Aviat\\\Ion\\\Friend:[a-zA-Z0-9_]+\(\)#'
5
-		- '#Call to an undefined method Aura\\\Html\\\HelperLocator:[a-zA-Z0-9_]+\(\)#'
6
-	excludes_analyze:
7
-		- %rootDir%/test_views/*
6
+		- '#Call to an undefined method Aviat\\\Ion\\\Friend::[a-zA-Z0-9_]+\(\)#'
7
+		- '#Call to an undefined method Aura\\\Html\\\HelperLocator::[a-zA-Z0-9_]+\(\)#'
8
+		- '#Undefined variable: \$var#'
9
+		- '#Property Amp\\Artax\\Internal\\RequestCycle::\$[a-zA-Z0-9_]+#'

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

@@ -55,7 +55,7 @@ class APIRequestBuilder {
55 55
 	protected $defaultHeaders = [];
56 56
 
57 57
 	/**
58
-	 * Valid HTTP request methos
58
+	 * Valid HTTP request methods
59 59
 	 * @var array
60 60
 	 */
61 61
 	protected $validMethods = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'];

+ 9
- 12
src/API/CacheTrait.php View File

@@ -17,18 +17,17 @@
17 17
 namespace Aviat\AnimeClient\API;
18 18
 
19 19
 use Aviat\Banker\Pool;
20
-use Aviat\Ion\Di\ContainerAware;
21 20
 
22 21
 /**
23 22
  * Helper methods for dealing with the Cache
24 23
  */
25 24
 trait CacheTrait {
26
-	
25
+
27 26
 	/**
28
-	 * @var Aviat\Banker\Pool
27
+	 * @var Pool
29 28
 	 */
30 29
 	protected $cache;
31
-	
30
+
32 31
 	/**
33 32
 	 * Inject the cache object
34 33
 	 *
@@ -40,34 +39,32 @@ trait CacheTrait {
40 39
 		$this->cache = $cache;
41 40
 		return $this;
42 41
 	}
43
-	
42
+
44 43
 	/**
45 44
 	 * Get the cache object if it exists
46 45
 	 *
47 46
 	 * @return Pool
48 47
 	 */
49
-	public function getCache()
48
+	public function getCache(): Pool
50 49
 	{
51 50
 		return $this->cache;
52 51
 	}
53
-	
52
+
54 53
 	/**
55 54
 	 * Generate a hash as a cache key from the current method call
56 55
 	 *
57
-	 * @param object $object
56
+	 * @param mixed $object
58 57
 	 * @param string $method
59 58
 	 * @param array  $args
60 59
 	 * @return string
61 60
 	 */
62 61
 	public function getHashForMethodCall($object, string $method, array $args = []): string
63 62
 	{
64
-		$classname = get_class($object);
65 63
 		$keyObj = [
66
-			'class' => $classname,
64
+			'class' => \get_class($object),
67 65
 			'method' => $method,
68 66
 			'args' => $args,
69 67
 		];
70
-		$hash = sha1(json_encode($keyObj));
71
-		return $hash;
68
+		return sha1(json_encode($keyObj));
72 69
 	}
73 70
 }

+ 3
- 3
src/API/HummingbirdClient.php View File

@@ -63,7 +63,7 @@ use function Amp\{
63 63
  * @see Client
64 64
  */
65 65
 final class HummingbirdClient implements Client {
66
-	const DEFAULT_USER_AGENT = 'Mozilla/5.0 (compatible; Artax)';
66
+	const DEFAULT_USER_AGENT = 'Hummingbird Anime Client/5.0';
67 67
 
68 68
 	private $cookieJar;
69 69
 	private $socketPool;
@@ -71,7 +71,7 @@ final class HummingbirdClient implements Client {
71 71
 	private $hasZlib;
72 72
 	private $options = [
73 73
 		self::OP_AUTO_ENCODING => true,
74
-		self::OP_TRANSFER_TIMEOUT => 15000,
74
+		self::OP_TRANSFER_TIMEOUT => 60000,
75 75
 		self::OP_MAX_REDIRECTS => 5,
76 76
 		self::OP_AUTO_REFERER => true,
77 77
 		self::OP_DISCARD_BODY => false,
@@ -89,7 +89,7 @@ final class HummingbirdClient implements Client {
89 89
 		$this->cookieJar = $cookieJar ?? new NullCookieJar;
90 90
 		$this->tlsContext = $tlsContext ?? new ClientTlsContext;
91 91
 		$this->socketPool = $socketPool ?? new HttpSocketPool;
92
-		$this->hasZlib = extension_loaded('zlib');
92
+		$this->hasZlib = \extension_loaded('zlib');
93 93
 	}
94 94
 
95 95
 	/** @inheritdoc */

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

@@ -313,7 +313,7 @@ class JsonAPI {
313 313
 
314 314
 			foreach ($data['data'] as $item)
315 315
 			{
316
-				if (is_array($item) && array_key_exists('id', $item))
316
+				if (\is_array($item) && array_key_exists('id', $item))
317 317
 				{
318 318
 					$organized[$key][] = $item['id'];
319 319
 				}

+ 2
- 2
src/API/Kitsu/KitsuTrait.php View File

@@ -177,7 +177,7 @@ trait KitsuTrait {
177 177
 
178 178
 		try
179 179
 		{
180
-			return Json::decode(wait($response->getBody()), TRUE);
180
+			return Json::decode(wait($response->getBody()));
181 181
 		}
182 182
 		catch (JsonException $e)
183 183
 		{
@@ -226,7 +226,7 @@ trait KitsuTrait {
226 226
 		$response = $this->getResponse('POST', ...$args);
227 227
 		$validResponseCodes = [200, 201];
228 228
 
229
-		if ( ! in_array((int) $response->getStatus(), $validResponseCodes))
229
+		if ( ! \in_array((int) $response->getStatus(), $validResponseCodes, TRUE))
230 230
 		{
231 231
 			if ($logger)
232 232
 			{

+ 4
- 4
src/API/Kitsu/Transformer/AnimeListTransformer.php View File

@@ -31,7 +31,7 @@ class AnimeListTransformer extends AbstractTransformer {
31 31
 	 * @param  array  $item API library item
32 32
 	 * @return array
33 33
 	 */
34
-	public function transform($item)
34
+	public function transform($item): array
35 35
 	{
36 36
 		$included = $item['included'];
37 37
 		$animeId = $item['relationships']['media']['data']['id'];
@@ -41,7 +41,7 @@ class AnimeListTransformer extends AbstractTransformer {
41 41
 		sort($genres);
42 42
 
43 43
 		$rating = (int) $item['attributes']['rating'] !== 0
44
-			? (int) 2 * $item['attributes']['rating']
44
+			? 2 * $item['attributes']['rating']
45 45
 			: '-';
46 46
 
47 47
 		$total_episodes = array_key_exists('episodeCount', $anime) && (int) $anime['episodeCount'] !== 0
@@ -97,7 +97,7 @@ class AnimeListTransformer extends AbstractTransformer {
97 97
 			'rewatching' => (bool) $item['attributes']['reconsuming'],
98 98
 			'rewatched' => (int) $item['attributes']['reconsumeCount'],
99 99
 			'user_rating' => $rating,
100
-			'private' => (bool) $item['attributes']['private'] ?? FALSE,
100
+			'private' => $item['attributes']['private'] ?? FALSE,
101 101
 		];
102 102
 	}
103 103
 
@@ -108,7 +108,7 @@ class AnimeListTransformer extends AbstractTransformer {
108 108
 	 * @param array $item Transformed library item
109 109
 	 * @return array API library item
110 110
 	 */
111
-	public function untransform($item)
111
+	public function untransform($item): array
112 112
 	{
113 113
 		$privacy = (array_key_exists('private', $item) && $item['private']);
114 114
 		$rewatching = (array_key_exists('rewatching', $item) && $item['rewatching']);

+ 4
- 4
src/API/Kitsu/Transformer/MangaListTransformer.php View File

@@ -33,7 +33,7 @@ class MangaListTransformer extends AbstractTransformer {
33 33
 	 * @param  array  $item manga entry item
34 34
 	 * @return array
35 35
 	 */
36
-	public function transform($item)
36
+	public function transform($item): array
37 37
 	{
38 38
 		$included = $item['included'];
39 39
 		$mangaId = $item['relationships']['media']['data']['id'];
@@ -43,7 +43,7 @@ class MangaListTransformer extends AbstractTransformer {
43 43
 		sort($genres);
44 44
 
45 45
 		$rating = (int) $item['attributes']['rating'] !== 0
46
-			? (int) 2 * $item['attributes']['rating']
46
+			? 2 * $item['attributes']['rating']
47 47
 			: '-';
48 48
 
49 49
 		$totalChapters = ((int) $manga['chapterCount'] !== 0)
@@ -109,9 +109,9 @@ class MangaListTransformer extends AbstractTransformer {
109 109
 	 * @param  array $item
110 110
 	 * @return array
111 111
 	 */
112
-	public function untransform($item)
112
+	public function untransform($item): array
113 113
 	{
114
-		$rereading = (array_key_exists('rereading', $item)) && (bool)$item['rereading'];
114
+		$rereading = array_key_exists('rereading', $item) && (bool)$item['rereading'];
115 115
 
116 116
 		$map = [
117 117
 			'id' => $item['id'],

+ 0
- 15
src/AnimeClient.php View File

@@ -18,21 +18,6 @@ namespace Aviat\AnimeClient;
18 18
 
19 19
 use Yosymfony\Toml\Toml;
20 20
 
21
-if ( ! \defined('SRC_DIR'))
22
-{
23
-	\define('SRC_DIR', \realpath(__DIR__));
24
-}
25
-
26
-const SESSION_SEGMENT = 'Aviat\AnimeClient\Auth';
27
-const DEFAULT_CONTROLLER = Controller\Index::class;
28
-const DEFAULT_CONTROLLER_NAMESPACE = Controller::class;
29
-const DEFAULT_LIST_CONTROLLER = Controller\Anime::class;
30
-const DEFAULT_CONTROLLER_METHOD = 'index';
31
-const NOT_FOUND_METHOD = 'notFound';
32
-const ERROR_MESSAGE_METHOD = 'errorPage';
33
-const SRC_DIR = SRC_DIR;
34
-
35
-
36 21
 if ( ! \function_exists('Aviat\AnimeClient\loadToml'))
37 22
 {
38 23
 	/**

+ 1
- 1
src/Controller.php View File

@@ -106,7 +106,7 @@ class Controller {
106 106
 		$this->request = $container->get('request');
107 107
 		$this->response = $container->get('response');
108 108
 
109
-		$this->baseData = array_merge((array)$this->baseData, [
109
+		$this->baseData = array_merge($this->baseData, [
110 110
 			'url' => $auraUrlGenerator,
111 111
 			'urlGenerator' => $urlGenerator,
112 112
 			'auth' => $container->get('auth'),

+ 2
- 2
src/Controller/Anime.php View File

@@ -232,9 +232,9 @@ class Anime extends BaseController {
232 232
 		$body = $this->request->getParsedBody();
233 233
 		$response = $this->model->deleteLibraryItem($body['id'], $body['mal_id']);
234 234
 
235
-		if ((bool)$response === TRUE)
235
+		if ($response === TRUE)
236 236
 		{
237
-			$this->setFlashMessage("Successfully deleted anime.", 'success');
237
+			$this->setFlashMessage('Successfully deleted anime.', 'success');
238 238
 			$this->cache->clear();
239 239
 		}
240 240
 		else

+ 0
- 6
src/Controller/Manga.php View File

@@ -36,12 +36,6 @@ class Manga extends Controller {
36 36
 	 */
37 37
 	protected $model;
38 38
 
39
-	/**
40
-	 * Data to ve sent to all routes in this controller
41
-	 * @var array $baseData
42
-	 */
43
-	protected $baseData;
44
-
45 39
 	/**
46 40
 	 * Constructor
47 41
 	 *

+ 42
- 24
src/Dispatcher.php View File

@@ -78,15 +78,18 @@ class Dispatcher extends RoutingBase {
78 78
 	 */
79 79
 	public function getRoute()
80 80
 	{
81
-		$logger = $this->container->getLogger('default');
81
+		$logger = $this->container->getLogger();
82 82
 
83 83
 		$rawRoute = $this->request->getUri()->getPath();
84 84
 		$routePath = '/' . trim($rawRoute, '/');
85 85
 
86
-		$logger->info('Dispatcher - Routing data from get_route method');
87
-		$logger->info(print_r([
88
-			'route_path' => $routePath
89
-		], TRUE));
86
+		if ($logger !== NULL)
87
+		{
88
+			$logger->info('Dispatcher - Routing data from get_route method');
89
+			$logger->info(print_r([
90
+				'route_path' => $routePath
91
+			], TRUE));
92
+		}
90 93
 
91 94
 		return $this->matcher->match($this->request);
92 95
 	}
@@ -107,16 +110,19 @@ class Dispatcher extends RoutingBase {
107 110
 	 * @param object|null $route
108 111
 	 * @return void
109 112
 	 */
110
-	public function __invoke($route = NULL)
113
+	public function __invoke($route = NULL): void
111 114
 	{
112
-		$logger = $this->container->getLogger('default');
115
+		$logger = $this->container->getLogger();
113 116
 
114
-		if (is_null($route))
117
+		if ($route === NULL)
115 118
 		{
116 119
 			$route = $this->getRoute();
117 120
 
118
-			$logger->info('Dispatcher - Route invoke arguments');
119
-			$logger->info(print_r($route, TRUE));
121
+			if ($logger !== NULL)
122
+			{
123
+				$logger->info('Dispatcher - Route invoke arguments');
124
+				$logger->info(print_r($route, TRUE));
125
+			}
120 126
 		}
121 127
 
122 128
 		if ($route)
@@ -147,7 +153,7 @@ class Dispatcher extends RoutingBase {
147 153
 	 * @throws \LogicException
148 154
 	 * @return array
149 155
 	 */
150
-	protected function processRoute($route)
156
+	protected function processRoute($route): array
151 157
 	{
152 158
 		if (array_key_exists('controller', $route->attributes))
153 159
 		{
@@ -155,7 +161,7 @@ class Dispatcher extends RoutingBase {
155 161
 		}
156 162
 		else
157 163
 		{
158
-			throw new \LogicException("Missing controller");
164
+			throw new \LogicException('Missing controller');
159 165
 		}
160 166
 
161 167
 		// Get the full namespace for a controller if a short name is given
@@ -181,8 +187,11 @@ class Dispatcher extends RoutingBase {
181 187
 				}
182 188
 			}
183 189
 		}
184
-		$logger = $this->container->getLogger('default');
185
-		$logger->info(json_encode($params));
190
+		$logger = $this->container->getLogger();
191
+		if ($logger !== NULL)
192
+		{
193
+			$logger->info(json_encode($params));
194
+		}
186 195
 
187 196
 		return [
188 197
 			'controller_name' => $controllerName,
@@ -205,8 +214,11 @@ class Dispatcher extends RoutingBase {
205 214
 		$segments = explode('/', $path);
206 215
 		$controller = reset($segments);
207 216
 
208
-		$logger = $this->container->getLogger('default');
209
-		$logger->info('Controller: ' . $controller);
217
+		$logger = $this->container->getLogger();
218
+		if ($logger !== NULL)
219
+		{
220
+			$logger->info('Controller: ' . $controller);
221
+		}
210 222
 
211 223
 		if (empty($controller))
212 224
 		{
@@ -234,7 +246,7 @@ class Dispatcher extends RoutingBase {
234 246
 
235 247
 		foreach ($classFiles as $file)
236 248
 		{
237
-			$rawClassName = basename(str_replace(".php", "", $file));
249
+			$rawClassName = basename(str_replace('.php', '', $file));
238 250
 			$path = $this->string($rawClassName)->dasherize()->__toString();
239 251
 			$className = trim($defaultNamespace . '\\' . $rawClassName, '\\');
240 252
 
@@ -262,9 +274,12 @@ class Dispatcher extends RoutingBase {
262 274
 			$controller = new $controllerName($this->container);
263 275
 
264 276
 			// Run the appropriate controller method
265
-			$logger->debug('Dispatcher - controller arguments', $params);
277
+			if ($logger !== NULL)
278
+			{
279
+				$logger->debug('Dispatcher - controller arguments', $params);
280
+			}
266 281
 
267
-			call_user_func_array([$controller, $method], $params);
282
+			\call_user_func_array([$controller, $method], $params);
268 283
 		}
269 284
 		catch (FailedResponseException $e)
270 285
 		{
@@ -285,11 +300,14 @@ class Dispatcher extends RoutingBase {
285 300
 	 */
286 301
 	protected function getErrorParams()
287 302
 	{
288
-		$logger = $this->container->getLogger('default');
303
+		$logger = $this->container->getLogger();
289 304
 		$failure = $this->matcher->getFailedRoute();
290 305
 
291
-		$logger->info('Dispatcher - failed route');
292
-		$logger->info(print_r($failure, TRUE));
306
+		if ($logger !== NULL)
307
+		{
308
+			$logger->info('Dispatcher - failed route');
309
+			$logger->info(print_r($failure, TRUE));
310
+		}
293 311
 
294 312
 		$actionMethod = ERROR_MESSAGE_METHOD;
295 313
 
@@ -354,9 +372,9 @@ class Dispatcher extends RoutingBase {
354 372
 			$route['controller'] = $controllerClass;
355 373
 
356 374
 			// Select the appropriate router method based on the http verb
357
-			$add = (array_key_exists('verb', $route))
375
+			$add = array_key_exists('verb', $route)
358 376
 				? strtolower($route['verb'])
359
-				: "get";
377
+				: 'get';
360 378
 
361 379
 			// Add the route to the router object
362 380
 			if ( ! array_key_exists('tokens', $route))

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

@@ -16,10 +16,13 @@
16 16
 
17 17
 namespace Aviat\AnimeClient\Model;
18 18
 
19
+use Aviat\Ion\StringWrapper;
20
+
19 21
 /**
20 22
  * Base model for api interaction
21 23
  */
22
-class API extends AbstractModel {
24
+class API {
25
+	use StringWrapper;
23 26
 
24 27
 	/**
25 28
 	 * Whether to use the MAL api

+ 17
- 18
src/Model/AnimeCollection.php View File

@@ -16,9 +16,7 @@
16 16
 
17 17
 namespace Aviat\AnimeClient\Model;
18 18
 
19
-use Aviat\AnimeClient\API\Kitsu;
20 19
 use Aviat\Ion\Di\ContainerInterface;
21
-use Aviat\Ion\Json;
22 20
 use PDO;
23 21
 
24 22
 /**
@@ -48,7 +46,7 @@ class AnimeCollection extends Collection {
48 46
 	 *
49 47
 	 * @return array
50 48
 	 */
51
-	public function getCollection()
49
+	public function getCollection(): array
52 50
 	{
53 51
 		$rawCollection = $this->getCollectionFromDatabase();
54 52
 
@@ -74,7 +72,7 @@ class AnimeCollection extends Collection {
74 72
 	 *
75 73
 	 * @return array
76 74
 	 */
77
-	public function getMediaTypeList()
75
+	public function getMediaTypeList(): array
78 76
 	{
79 77
 		$output = [];
80 78
 
@@ -93,13 +91,13 @@ class AnimeCollection extends Collection {
93 91
 	/**
94 92
 	 * Get item from collection for editing
95 93
 	 *
96
-	 * @param int $id
94
+	 * @param string $id
97 95
 	 * @return array
98 96
 	 */
99
-	public function getCollectionEntry($id)
97
+	public function getCollectionEntry($id): array
100 98
 	{
101 99
 		$query = $this->db->from('anime_set')
102
-			->where('hummingbird_id', (int)$id)
100
+			->where('hummingbird_id', $id)
103 101
 			->get();
104 102
 
105 103
 		return $query->fetch(PDO::FETCH_ASSOC);
@@ -110,7 +108,7 @@ class AnimeCollection extends Collection {
110 108
 	 *
111 109
 	 * @return array
112 110
 	 */
113
-	private function getCollectionFromDatabase()
111
+	private function getCollectionFromDatabase(): array
114 112
 	{
115 113
 		if ( ! $this->validDatabase)
116 114
 		{
@@ -134,7 +132,7 @@ class AnimeCollection extends Collection {
134 132
 	 * @param array $data
135 133
 	 * @return void
136 134
 	 */
137
-	public function add($data)
135
+	public function add($data): void
138 136
 	{
139 137
 		$anime = (object)$this->animeModel->getAnimeById($data['id']);
140 138
 		$this->db->set([
@@ -160,7 +158,7 @@ class AnimeCollection extends Collection {
160 158
 	 * @param array $data
161 159
 	 * @return void
162 160
 	 */
163
-	public function update($data)
161
+	public function update($data): void
164 162
 	{
165 163
 		// If there's no id to update, don't update
166 164
 		if ( ! array_key_exists('hummingbird_id', $data))
@@ -182,7 +180,7 @@ class AnimeCollection extends Collection {
182 180
 	 * @param  array $data
183 181
 	 * @return void
184 182
 	 */
185
-	public function delete($data)
183
+	public function delete($data): void
186 184
 	{
187 185
 		// If there's no id to update, don't delete
188 186
 		if ( ! array_key_exists('hummingbird_id', $data))
@@ -203,7 +201,7 @@ class AnimeCollection extends Collection {
203 201
 	 * @param int $kitsuId
204 202
 	 * @return array
205 203
 	 */
206
-	public function get($kitsuId)
204
+	public function get($kitsuId): array
207 205
 	{
208 206
 		$query = $this->db->from('anime_set')
209 207
 			->where('hummingbird_id', $kitsuId)
@@ -215,13 +213,14 @@ class AnimeCollection extends Collection {
215 213
 	/**
216 214
 	 * Update genre information for selected anime
217 215
 	 *
218
-	 * @param int $animeId The current anime
216
+	 * @param string $animeId The current anime
219 217
 	 * @return void
220 218
 	 */
221
-	private function updateGenre($animeId)
219
+	private function updateGenre($animeId): void
222 220
 	{
223 221
 		$genreInfo = $this->getGenreData();
224
-		extract($genreInfo, \EXTR_SKIP);
222
+		$genres = $genreInfo['genres'];
223
+		$links = $genreInfo['links'];
225 224
 
226 225
 		// Get api information
227 226
 		$anime = $this->animeModel->getAnimeById($animeId);
@@ -229,7 +228,7 @@ class AnimeCollection extends Collection {
229 228
 		foreach ($anime['genres'] as $genre)
230 229
 		{
231 230
 			// Add genres that don't currently exist
232
-			if ( ! in_array($genre, $genres))
231
+			if ( ! \in_array($genre, $genres, TRUE))
233 232
 			{
234 233
 				$this->db->set('genre', $genre)
235 234
 					->insert('genres');
@@ -248,7 +247,7 @@ class AnimeCollection extends Collection {
248 247
 
249 248
 			if (array_key_exists($animeId, $links))
250 249
 			{
251
-				if ( ! in_array($flippedGenres[$genre], $links[$animeId]))
250
+				if ( ! \in_array($flippedGenres[$genre], $links[$animeId], TRUE))
252 251
 				{
253 252
 					$this->db->set($insertArray)->insert('genre_anime_set_link');
254 253
 				}
@@ -265,7 +264,7 @@ class AnimeCollection extends Collection {
265 264
 	 *
266 265
 	 * @return array
267 266
 	 */
268
-	private function getGenreData()
267
+	private function getGenreData(): array
269 268
 	{
270 269
 		$genres = [];
271 270
 		$links = [];

+ 4
- 11
src/Model/Collection.php View File

@@ -16,8 +16,7 @@
16 16
 
17 17
 namespace Aviat\AnimeClient\Model;
18 18
 
19
-use Aviat\AnimeClient\Model\DB;
20
-use Aviat\Ion\Di\{ContainerAware, ContainerInterface};
19
+use Aviat\Ion\Di\ContainerInterface;
21 20
 use PDO;
22 21
 use PDOException;
23 22
 
@@ -26,8 +25,6 @@ use PDOException;
26 25
  */
27 26
 class Collection extends DB {
28 27
 
29
-	use ContainerAware;
30
-
31 28
 	/**
32 29
 	 * Whether the database is valid for querying
33 30
 	 * @var boolean
@@ -47,11 +44,7 @@ class Collection extends DB {
47 44
 		{
48 45
 			$this->db = \Query($this->dbConfig['collection']);
49 46
 		}
50
-		catch (PDOException $e)
51
-		{
52
-			//$this->validDatabase = FALSE;
53
-			//return FALSE;
54
-		}
47
+		catch (PDOException $e) {}
55 48
 
56 49
 		// Is database valid? If not, set a flag so the
57 50
 		// app can be run without a valid database
@@ -81,7 +74,7 @@ class Collection extends DB {
81 74
 	 * @param array $filter
82 75
 	 * @return array
83 76
 	 */
84
-	public function getGenreList($filter = [])
77
+	public function getGenreList(array $filter = []): array
85 78
 	{
86 79
 		$this->db->select('hummingbird_id, genre')
87 80
 			->from('genre_anime_set_link gl')
@@ -112,7 +105,7 @@ class Collection extends DB {
112 105
 
113 106
 			if (array_key_exists($id, $output))
114 107
 			{
115
-				array_push($output[$id], $genre);
108
+				$output[$id][] = $genre;
116 109
 			}
117 110
 			else
118 111
 			{

+ 5
- 2
src/Model/DB.php View File

@@ -17,16 +17,19 @@
17 17
 namespace Aviat\AnimeClient\Model;
18 18
 
19 19
 use Aviat\Ion\Di\{ContainerAware, ContainerInterface};
20
+use Aviat\Ion\{ArrayWrapper, StringWrapper};
20 21
 
21 22
 /**
22 23
  * Base model for database interaction
23 24
  */
24
-class DB extends AbstractModel {
25
+class DB {
26
+	use ArrayWrapper;
25 27
 	use ContainerAware;
28
+	use StringWrapper;
26 29
 
27 30
 	/**
28 31
 	 * The query builder object
29
-	 * @var \Query\Query_Builder_Interface $db
32
+	 * @var \Query\Query_Builder_Interface
30 33
 	 */
31 34
 	protected $db;
32 35
 

+ 17
- 18
src/Model/MangaCollection.php View File

@@ -16,9 +16,7 @@
16 16
 
17 17
 namespace Aviat\AnimeClient\Model;
18 18
 
19
-use Aviat\AnimeClient\API\Kitsu;
20 19
 use Aviat\Ion\Di\ContainerInterface;
21
-use Aviat\Ion\Json;
22 20
 use PDO;
23 21
 
24 22
 /**
@@ -48,7 +46,7 @@ class MangaCollection extends Collection {
48 46
 	 *
49 47
 	 * @return array
50 48
 	 */
51
-	public function getCollection()
49
+	public function getCollection(): array
52 50
 	{
53 51
 		$rawCollection = $this->getCollectionFromDatabase();
54 52
 
@@ -74,7 +72,7 @@ class MangaCollection extends Collection {
74 72
 	 *
75 73
 	 * @return array
76 74
 	 */
77
-	public function getMediaTypeList()
75
+	public function getMediaTypeList(): array
78 76
 	{
79 77
 		$output = [];
80 78
 
@@ -96,10 +94,10 @@ class MangaCollection extends Collection {
96 94
 	 * @param int $id
97 95
 	 * @return array
98 96
 	 */
99
-	public function getCollectionEntry($id)
97
+	public function getCollectionEntry($id): array
100 98
 	{
101 99
 		$query = $this->db->from('anime_set')
102
-			->where('hummingbird_id', (int)$id)
100
+			->where('hummingbird_id', $id)
103 101
 			->get();
104 102
 
105 103
 		return $query->fetch(PDO::FETCH_ASSOC);
@@ -110,7 +108,7 @@ class MangaCollection extends Collection {
110 108
 	 *
111 109
 	 * @return array
112 110
 	 */
113
-	private function getCollectionFromDatabase()
111
+	private function getCollectionFromDatabase(): array
114 112
 	{
115 113
 		if ( ! $this->validDatabase)
116 114
 		{
@@ -134,7 +132,7 @@ class MangaCollection extends Collection {
134 132
 	 * @param array $data
135 133
 	 * @return void
136 134
 	 */
137
-	public function add($data)
135
+	public function add($data): void
138 136
 	{
139 137
 		$anime = (object)$this->mangaModel->getMangaById($data['id']);
140 138
 		$this->db->set([
@@ -160,7 +158,7 @@ class MangaCollection extends Collection {
160 158
 	 * @param array $data
161 159
 	 * @return void
162 160
 	 */
163
-	public function update($data)
161
+	public function update($data): void
164 162
 	{
165 163
 		// If there's no id to update, don't update
166 164
 		if ( ! array_key_exists('hummingbird_id', $data))
@@ -182,7 +180,7 @@ class MangaCollection extends Collection {
182 180
 	 * @param  array $data
183 181
 	 * @return void
184 182
 	 */
185
-	public function delete($data)
183
+	public function delete($data): void
186 184
 	{
187 185
 		// If there's no id to update, don't delete
188 186
 		if ( ! array_key_exists('hummingbird_id', $data))
@@ -200,10 +198,10 @@ class MangaCollection extends Collection {
200 198
 	/**
201 199
 	 * Get the details of a collection item
202 200
 	 *
203
-	 * @param int $kitsuId
201
+	 * @param string $kitsuId
204 202
 	 * @return array
205 203
 	 */
206
-	public function get($kitsuId)
204
+	public function get($kitsuId): array
207 205
 	{
208 206
 		$query = $this->db->from('manga_set')
209 207
 			->where('hummingbird_id', $kitsuId)
@@ -215,13 +213,14 @@ class MangaCollection extends Collection {
215 213
 	/**
216 214
 	 * Update genre information for selected manga
217 215
 	 *
218
-	 * @param int $mangaId The current manga
216
+	 * @param string $mangaId The current manga
219 217
 	 * @return void
220 218
 	 */
221
-	private function updateGenre($mangaId)
219
+	private function updateGenre($mangaId): void
222 220
 	{
223 221
 		$genreInfo = $this->getGenreData();
224
-		extract($genreInfo, EXTR_SKIP);
222
+		$genres = $genreInfo['genres'];
223
+		$links = $genreInfo['links'];
225 224
 
226 225
 		// Get api information
227 226
 		$manga = $this->mangaModel->getMangaById($mangaId);
@@ -229,7 +228,7 @@ class MangaCollection extends Collection {
229 228
 		foreach ($manga['genres'] as $genre)
230 229
 		{
231 230
 			// Add genres that don't currently exist
232
-			if ( ! in_array($genre, $genres))
231
+			if ( ! \in_array($genre, $genres, TRUE))
233 232
 			{
234 233
 				$this->db->set('genre', $genre)
235 234
 					->insert('genres');
@@ -248,7 +247,7 @@ class MangaCollection extends Collection {
248 247
 
249 248
 			if (array_key_exists($mangaId, $links))
250 249
 			{
251
-				if ( ! in_array($flippedGenres[$genre], $links[$mangaId]))
250
+				if ( ! \in_array($flippedGenres[$genre], $links[$mangaId], TRUE))
252 251
 				{
253 252
 					$this->db->set($insertArray)->insert('genre_manga_set_link');
254 253
 				}
@@ -265,7 +264,7 @@ class MangaCollection extends Collection {
265 264
 	 *
266 265
 	 * @return array
267 266
 	 */
268
-	private function getGenreData()
267
+	private function getGenreData(): array
269 268
 	{
270 269
 		$genres = [];
271 270
 		$links = [];

src/Model/AbstractModel.php → src/constants.php View File

@@ -14,13 +14,13 @@
14 14
  * @link        https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
15 15
  */
16 16
 
17
-namespace Aviat\AnimeClient\Model;
17
+namespace Aviat\AnimeClient;
18 18
 
19
-use Aviat\Ion\StringWrapper;
20
-
21
-/**
22
- * Base class for Models
23
- */
24
-abstract class AbstractModel {
25
-	use StringWrapper;
26
-}
19
+const DEFAULT_CONTROLLER = Controller\Index::class;
20
+const DEFAULT_CONTROLLER_METHOD = 'index';
21
+const DEFAULT_CONTROLLER_NAMESPACE = Controller::class;
22
+const DEFAULT_LIST_CONTROLLER = Controller\Anime::class;
23
+const ERROR_MESSAGE_METHOD = 'errorPage';
24
+const NOT_FOUND_METHOD = 'notFound';
25
+const SESSION_SEGMENT = 'Aviat\AnimeClient\Auth';
26
+const SRC_DIR = __DIR__;

+ 6
- 6
tests/ControllerTest.php View File

@@ -59,30 +59,30 @@ class ControllerTest extends AnimeClientTestCase {
59 59
 		$this->container->setInstance('config', $config);
60 60
 
61 61
 		$this->assertInstanceOf(
62
-			'Aviat\AnimeClient\Controller',
62
+			Controller::class,
63 63
 			new AnimeController($this->container)
64 64
 		);
65 65
 		$this->assertInstanceOf(
66
-			'Aviat\AnimeClient\Controller',
66
+			Controller::class,
67 67
 			new MangaController($this->container)
68 68
 		);
69 69
 		$this->assertInstanceOf(
70
-			'Aviat\AnimeClient\Controller',
70
+			Controller::class,
71 71
 			new CharacterController($this->container)
72 72
 		);
73 73
 		$this->assertInstanceOf(
74
-			'Aviat\AnimeClient\Controller',
74
+			Controller::class,
75 75
 			new AnimeCollectionController($this->container)
76 76
 		);
77 77
 		$this->assertInstanceOf(
78
-			'Aviat\AnimeClient\Controller',
78
+			Controller::class,
79 79
 			new MangaCollectionController($this->container)
80 80
 		);
81 81
 	}
82 82
 
83 83
 	public function testBaseControllerSanity()
84 84
 	{
85
-		$this->assertTrue(is_object($this->BaseController));
85
+		$this->assertTrue(\is_object($this->BaseController));
86 86
 	}
87 87
 
88 88
 	public function testFormatTitle()

+ 3
- 3
tests/mocks.php View File

@@ -72,7 +72,7 @@ class TestTransformer extends AbstractTransformer {
72 72
 }
73 73
 
74 74
 trait MockViewOutputTrait {
75
-	protected function output() {
75
+	protected function output(): void {
76 76
 		$reflect = new ReflectionClass($this);
77 77
 		$properties = $reflect->getProperties();
78 78
 		$props = [];
@@ -102,8 +102,8 @@ class MockUtil {
102 102
 }
103 103
 
104 104
 class TestView extends View {
105
-	public function send() {}
106
-	protected function output()
105
+	public function send(): void {}
106
+	protected function output(): void
107 107
 	{
108 108
 		/*$content =& $this->response->content;
109 109
 		$content->set($this->output);