Browse Source

Code cleanup and fix 'On Hold' title on all section of anime list

Timothy J. Warren 1 year ago
parent
commit
493ac3ca03

+ 2
- 2
RoboFile.php View File

@@ -105,7 +105,7 @@ class RoboFile extends Tasks {
105 105
 	 */
106 106
 	public function coverage()
107 107
 	{
108
-		$this->_run(['vendor/bin/phpunit -c build']);
108
+		$this->_run(['phpdbg -qrr -- vendor/bin/phpunit -c build']);
109 109
 	}
110 110
 
111 111
 	/**
@@ -114,7 +114,7 @@ class RoboFile extends Tasks {
114 114
 	public function docs()
115 115
 	{
116 116
 		$cmd_parts = [
117
-			'phpdox',
117
+			'vendor/bin/phpdox',
118 118
 		];
119 119
 		$this->_run($cmd_parts, ' && ');
120 120
 	}

+ 3
- 1
composer.json View File

@@ -33,7 +33,7 @@
33 33
 	"require-dev": {
34 34
 		"pdepend/pdepend": "^2.2",
35 35
 		"sebastian/phpcpd": "^3.0",
36
-		"theseer/phpdox": "0.9.0",
36
+		"theseer/phpdox": "dev-master",
37 37
 		"phploc/phploc": "^3.0",
38 38
 		"phpmd/phpmd": "^2.4",
39 39
 		"phpunit/phpunit": "^6.0",
@@ -45,7 +45,9 @@
45 45
 		"phpstan/phpstan": "^0.6.4"
46 46
 	},
47 47
 	"scripts": {
48
+		"build": "vendor/bin/robo build",
48 49
 		"build:css": "cd public && npm run build && cd ..",
50
+		"clean": "vendor/bin/robo clean",
49 51
 		"coverage": "phpdbg -qrr -- vendor/bin/phpunit -c build",
50 52
 		"docs": "vendor/bin/phpdox",
51 53
 		"phpstan": "phpstan analyse src tests",

+ 8
- 20
console View File

@@ -1,19 +1,10 @@
1 1
 #!/usr/bin/env php
2 2
 <?php declare(strict_types=1);
3 3
 
4
-if ( ! function_exists('_dir'))
5
-{
6
-	/**
7
-	 * Joins paths together. Variadic to take an
8
-	 * arbitrary number of arguments
9
-	 *
10
-	 * @return string
11
-	 */
12
-	function _dir()
13
-	{
14
-		return implode(DIRECTORY_SEPARATOR, func_get_args());
15
-	}
16
-}
4
+// Set up autoloader for third-party dependencies
5
+require_once realpath(__DIR__ . '/vendor/autoload.php');
6
+
7
+use Aviat\AnimeClient\Command;
17 8
 
18 9
 $_SERVER['HTTP_HOST'] = 'localhost';
19 10
 
@@ -22,9 +13,6 @@ $APP_DIR = __DIR__ . '/app/';
22 13
 $SRC_DIR = __DIR__ . '/src/';
23 14
 $CONF_DIR = realpath("${APP_DIR}/config/");
24 15
 
25
-// Set up autoloader for third-party dependencies
26
-require_once realpath(__DIR__ . '/vendor/autoload.php');
27
-
28 16
 // Unset 'constants'
29 17
 unset($APP_DIR);
30 18
 unset($SRC_DIR);
@@ -34,10 +22,10 @@ unset($CONF_DIR);
34 22
 // Start console script
35 23
 // ---------------------------------------------------------------------------------------------------------------------
36 24
 $console = new \ConsoleKit\Console([
37
-	'cache-prime' => '\Aviat\AnimeClient\Command\CachePrime',
38
-	'cache-clear' => '\Aviat\AnimeClient\Command\CacheClear',
39
-	'clear-cache' => '\Aviat\AnimeClient\Command\CacheClear',
40
-	'sync-lists' => '\Aviat\AnimeClient\Command\SyncKitsuWithMal',
25
+	'cache-prime' => Command\CachePrime::class,
26
+	'cache-clear' => Command\CacheClear::class,
27
+	'clear-cache' => Command\CacheClear::class,
28
+	'sync-lists' => Command\SyncKitsuWithMal::class,
41 29
 ]);
42 30
 
43 31
 $console->run();

+ 1
- 1
src/API/Enum/AnimeWatchingStatus/Kitsu.php View File

@@ -24,7 +24,7 @@ use Aviat\Ion\Enum;
24 24
 class Kitsu extends Enum {
25 25
 	const WATCHING = 'current';
26 26
 	const PLAN_TO_WATCH = 'planned';
27
-	const COMPLETED = 'completed';
28 27
 	const ON_HOLD = 'on_hold';
29 28
 	const DROPPED = 'dropped';
29
+	const COMPLETED = 'completed';
30 30
 }

+ 4
- 8
src/API/Kitsu/Model.php View File

@@ -400,17 +400,13 @@ class Model {
400 400
 		if ( ! $cacheItem->isHit())
401 401
 		{
402 402
 			$output = [];
403
-			$statuses = [
404
-				Title::WATCHING => KitsuWatchingStatus::WATCHING,
405
-				Title::PLAN_TO_WATCH => KitsuWatchingStatus::PLAN_TO_WATCH,
406
-				Title::ON_HOLD, KitsuWatchingStatus::ON_HOLD,
407
-				Title::DROPPED => KitsuWatchingStatus::DROPPED,
408
-				Title::COMPLETED => KitsuWatchingStatus::COMPLETED
409
-			];
403
+
404
+			$statuses = KitsuWatchingStatus::getConstList();
410 405
 
411 406
 			foreach ($statuses as $key => $status)
412 407
 			{
413
-				$output[$key] = $this->getAnimeList($status) ?? [];
408
+				$mappedStatus = AnimeWatchingStatus::KITSU_TO_TITLE[$status];
409
+				$output[$mappedStatus] = $this->getAnimeList($status) ?? [];
414 410
 			}
415 411
 
416 412
 			$cacheItem->set($output);

+ 4
- 0
src/API/Mapping/AnimeWatchingStatus.php View File

@@ -24,6 +24,10 @@ use Aviat\AnimeClient\API\Enum\AnimeWatchingStatus\{
24 24
 };
25 25
 use Aviat\Ion\Enum;
26 26
 
27
+/**
28
+ * Anime watching status mappings, among Kitsu, MAL, Page titles
29
+ * and url route segments
30
+ */
27 31
 class AnimeWatchingStatus extends Enum {
28 32
 	const KITSU_TO_MAL = [
29 33
 		Kitsu::WATCHING => MAL::WATCHING,

+ 4
- 0
src/API/Mapping/MangaReadingStatus.php View File

@@ -24,6 +24,10 @@ use Aviat\AnimeClient\API\Enum\MangaReadingStatus\{
24 24
 };
25 25
 use Aviat\Ion\Enum;
26 26
 
27
+/**
28
+ * Manga reading status mappings, among Kitsu, MAL, Page titles
29
+ * and url route segments
30
+ */
27 31
 class MangaReadingStatus extends Enum {
28 32
 	const MAL_TO_KITSU = [
29 33
 		Kitsu::READING => MAL::READING,

+ 40
- 41
src/Command/SyncKitsuWithMal.php View File

@@ -54,38 +54,38 @@ class SyncKitsuWithMal extends BaseCommand {
54 54
 		$this->setCache($this->container->get('cache'));
55 55
 		$this->kitsuModel = $this->container->get('kitsu-model');
56 56
 		$this->malModel = $this->container->get('mal-model');
57
-		
58
-		$malCount = count($this->getMALList());
57
+
58
+		$malCount = count($this->getMALAnimeList());
59 59
 		$kitsuCount = $this->getKitsuAnimeListPageCount();
60
-		
60
+
61 61
 		$this->echoBox("Number of MAL list items: {$malCount}");
62 62
 		$this->echoBox("Number of Kitsu list items: {$kitsuCount}");
63
-		
64
-		$data = $this->diffLists();
63
+
64
+		$data = $this->diffAnimeLists();
65 65
 		$this->echoBox("Number of items that need to be added to MAL: " . count($data));
66
-		
66
+
67 67
 		if ( ! empty($data['addToMAL']))
68 68
 		{
69 69
 			$this->echoBox("Adding missing list items to MAL");
70
-			$this->createMALListItems($data['addToMAL']);
70
+			$this->createMALAnimeListItems($data['addToMAL']);
71 71
 		}
72 72
 	}
73
-	
74
-	public function getKitsuList()
73
+
74
+	public function getKitsuAnimeList()
75 75
 	{
76 76
 		$count = $this->getKitsuAnimeListPageCount();
77 77
 		$size = 100;
78 78
 		$pages = ceil($count / $size);
79
-		
79
+
80 80
 		$requests = [];
81
-		
81
+
82 82
 		// Set up requests
83 83
 		for ($i = 0; $i < $pages; $i++)
84 84
 		{
85 85
 			$offset = $i * $size;
86 86
 			$requests[] = $this->kitsuModel->getPagedAnimeList($size, $offset);
87 87
 		}
88
-		
88
+
89 89
 		$promiseArray = (new Client())->requestMulti($requests);
90 90
 
91 91
 		$responses = wait(all($promiseArray));
@@ -100,15 +100,15 @@ class SyncKitsuWithMal extends BaseCommand {
100 100
 		return $output;
101 101
 	}
102 102
 
103
-	public function getMALList()
103
+	public function getMALAnimeList()
104 104
 	{
105 105
 		return $this->malModel->getFullList();
106 106
 	}
107
-	
107
+
108 108
 	public function filterMappings(array $includes): array
109 109
 	{
110 110
 		$output = [];
111
-		
111
+
112 112
 		foreach($includes as $id => $mapping)
113 113
 		{
114 114
 			if ($mapping['externalSite'] === 'myanimelist/anime')
@@ -116,15 +116,15 @@ class SyncKitsuWithMal extends BaseCommand {
116 116
 				$output[$id] = $mapping;
117 117
 			}
118 118
 		}
119
-		
119
+
120 120
 		return $output;
121 121
 	}
122
-	
123
-	public function formatMALList()
122
+
123
+	public function formatMALAnimeList()
124 124
 	{
125
-		$orig = $this->getMALList();
125
+		$orig = $this->getMALAnimeList();
126 126
 		$output = [];
127
-		
127
+
128 128
 		foreach($orig as $item)
129 129
 		{
130 130
 			$output[$item['series_animedb_id']] = [
@@ -144,24 +144,24 @@ class SyncKitsuWithMal extends BaseCommand {
144 144
 				]
145 145
 			];
146 146
 		}
147
-		
147
+
148 148
 		return $output;
149 149
 	}
150
-	
151
-	public function filterKitsuList()
150
+
151
+	public function filterKitsuAnimeList()
152 152
 	{
153 153
 		$data = $this->kitsuModel->getFullAnimeList();
154 154
 		$includes = JsonAPI::organizeIncludes($data['included']);
155 155
 		$includes['mappings'] = $this->filterMappings($includes['mappings']);
156
-		
156
+
157 157
 		$output = [];
158
-		
158
+
159 159
 		foreach($data['data'] as $listItem)
160 160
 		{
161 161
 			$animeId = $listItem['relationships']['anime']['data']['id'];
162 162
 			$potentialMappings = $includes['anime'][$animeId]['relationships']['mappings'];
163 163
 			$malId = NULL;
164
-			
164
+
165 165
 			foreach ($potentialMappings as $mappingId)
166 166
 			{
167 167
 				if (array_key_exists($mappingId, $includes['mappings']))
@@ -169,20 +169,20 @@ class SyncKitsuWithMal extends BaseCommand {
169 169
 					$malId = $includes['mappings'][$mappingId]['externalId'];
170 170
 				}
171 171
 			}
172
-			
172
+
173 173
 			// Skip to the next item if there isn't a MAL ID
174 174
 			if (is_null($malId))
175 175
 			{
176 176
 				continue;
177 177
 			}
178
-			
178
+
179 179
 			$output[$listItem['id']] = [
180 180
 				'id' => $listItem['id'],
181 181
 				'malId' => $malId,
182 182
 				'data' => $listItem['attributes'],
183 183
 			];
184 184
 		}
185
-		
185
+
186 186
 		return $output;
187 187
 	}
188 188
 
@@ -191,32 +191,32 @@ class SyncKitsuWithMal extends BaseCommand {
191 191
 		return $this->kitsuModel->getAnimeListCount();
192 192
 	}
193 193
 
194
-	public function diffLists()
194
+	public function diffAnimeLists()
195 195
 	{
196 196
 		// Get libraryEntries with media.mappings from Kitsu
197 197
 		// Organize mappings, and ignore entries without mappings
198
-		$kitsuList = $this->filterKitsuList();
198
+		$kitsuList = $this->filterKitsuAnimeList();
199 199
 
200 200
 		// Get MAL list data
201
-		$malList = $this->formatMALList();
202
-		
201
+		$malList = $this->formatMALAnimeList();
202
+
203 203
 		$itemsToAddToMAL = [];
204
-		
204
+
205 205
 		foreach($kitsuList as $kitsuItem)
206 206
 		{
207 207
 			if (array_key_exists($kitsuItem['malId'], $malList))
208 208
 			{
209
-				// Eventually, compare the list entries, and determine which 
209
+				// Eventually, compare the list entries, and determine which
210 210
 				// needs to be updated
211 211
 				continue;
212 212
 			}
213
-			
213
+
214 214
 			// Looks like this item only exists on Kitsu
215 215
 			$itemsToAddToMAL[] = [
216 216
 				'mal_id' => $kitsuItem['malId'],
217 217
 				'data' => $kitsuItem['data']
218 218
 			];
219
-			
219
+
220 220
 		}
221 221
 
222 222
 		// Compare each list entry
@@ -227,17 +227,17 @@ class SyncKitsuWithMal extends BaseCommand {
227 227
 				// Otherwise, use rewatch count, then episode progress as critera for selecting the more up
228 228
 				// to date entry
229 229
 				// Based on the 'newer' entry, update the other api list item
230
-		
230
+
231 231
 		return [
232 232
 			'addToMAL' => $itemsToAddToMAL,
233 233
 		];
234 234
 	}
235 235
 
236
-	public function createMALListItems($itemsToAdd)
236
+	public function createMALAnimeListItems($itemsToAdd)
237 237
 	{
238 238
 		$transformer = new ALT();
239 239
 		$requests = [];
240
-		
240
+
241 241
 		foreach($itemsToAdd as $item)
242 242
 		{
243 243
 			$data = $transformer->untransform($item);
@@ -261,5 +261,4 @@ class SyncKitsuWithMal extends BaseCommand {
261 261
 			}
262 262
 		}
263 263
 	}
264
-
265 264
 }

+ 3
- 0
src/Controller/Character.php View File

@@ -18,6 +18,9 @@ namespace Aviat\AnimeClient\Controller;
18 18
 
19 19
 use Aviat\AnimeClient\Controller as BaseController;
20 20
 
21
+/**
22
+ * Controller for character description pages
23
+ */
21 24
 class Character extends BaseController {
22 25
 
23 26
 	public function index(string $slug)