diff --git a/RoboFile.php b/RoboFile.php index e4c3b729..3e2140c3 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -105,7 +105,7 @@ class RoboFile extends Tasks { */ public function coverage() { - $this->_run(['vendor/bin/phpunit -c build']); + $this->_run(['phpdbg -qrr -- vendor/bin/phpunit -c build']); } /** @@ -114,7 +114,7 @@ class RoboFile extends Tasks { public function docs() { $cmd_parts = [ - 'phpdox', + 'vendor/bin/phpdox', ]; $this->_run($cmd_parts, ' && '); } diff --git a/composer.json b/composer.json index d85c4a18..e71d64ee 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ "require-dev": { "pdepend/pdepend": "^2.2", "sebastian/phpcpd": "^3.0", - "theseer/phpdox": "0.9.0", + "theseer/phpdox": "dev-master", "phploc/phploc": "^3.0", "phpmd/phpmd": "^2.4", "phpunit/phpunit": "^6.0", @@ -45,7 +45,9 @@ "phpstan/phpstan": "^0.6.4" }, "scripts": { + "build": "vendor/bin/robo build", "build:css": "cd public && npm run build && cd ..", + "clean": "vendor/bin/robo clean", "coverage": "phpdbg -qrr -- vendor/bin/phpunit -c build", "docs": "vendor/bin/phpdox", "phpstan": "phpstan analyse src tests", diff --git a/console b/console index 899cc7eb..3a7c90fc 100755 --- a/console +++ b/console @@ -1,19 +1,10 @@ #!/usr/bin/env php '\Aviat\AnimeClient\Command\CachePrime', - 'cache-clear' => '\Aviat\AnimeClient\Command\CacheClear', - 'clear-cache' => '\Aviat\AnimeClient\Command\CacheClear', - 'sync-lists' => '\Aviat\AnimeClient\Command\SyncKitsuWithMal', + 'cache-prime' => Command\CachePrime::class, + 'cache-clear' => Command\CacheClear::class, + 'clear-cache' => Command\CacheClear::class, + 'sync-lists' => Command\SyncKitsuWithMal::class, ]); $console->run(); \ No newline at end of file diff --git a/src/API/Enum/AnimeWatchingStatus/Kitsu.php b/src/API/Enum/AnimeWatchingStatus/Kitsu.php index 829fe2d5..b3447c29 100644 --- a/src/API/Enum/AnimeWatchingStatus/Kitsu.php +++ b/src/API/Enum/AnimeWatchingStatus/Kitsu.php @@ -24,7 +24,7 @@ use Aviat\Ion\Enum; class Kitsu extends Enum { const WATCHING = 'current'; const PLAN_TO_WATCH = 'planned'; - const COMPLETED = 'completed'; const ON_HOLD = 'on_hold'; const DROPPED = 'dropped'; + const COMPLETED = 'completed'; } \ No newline at end of file diff --git a/src/API/Kitsu/Model.php b/src/API/Kitsu/Model.php index 3ea4a08a..7f4f5457 100644 --- a/src/API/Kitsu/Model.php +++ b/src/API/Kitsu/Model.php @@ -400,17 +400,13 @@ class Model { if ( ! $cacheItem->isHit()) { $output = []; - $statuses = [ - Title::WATCHING => KitsuWatchingStatus::WATCHING, - Title::PLAN_TO_WATCH => KitsuWatchingStatus::PLAN_TO_WATCH, - Title::ON_HOLD, KitsuWatchingStatus::ON_HOLD, - Title::DROPPED => KitsuWatchingStatus::DROPPED, - Title::COMPLETED => KitsuWatchingStatus::COMPLETED - ]; + + $statuses = KitsuWatchingStatus::getConstList(); foreach ($statuses as $key => $status) { - $output[$key] = $this->getAnimeList($status) ?? []; + $mappedStatus = AnimeWatchingStatus::KITSU_TO_TITLE[$status]; + $output[$mappedStatus] = $this->getAnimeList($status) ?? []; } $cacheItem->set($output); diff --git a/src/API/Mapping/AnimeWatchingStatus.php b/src/API/Mapping/AnimeWatchingStatus.php index 94c4648e..34b44930 100644 --- a/src/API/Mapping/AnimeWatchingStatus.php +++ b/src/API/Mapping/AnimeWatchingStatus.php @@ -24,6 +24,10 @@ use Aviat\AnimeClient\API\Enum\AnimeWatchingStatus\{ }; use Aviat\Ion\Enum; +/** + * Anime watching status mappings, among Kitsu, MAL, Page titles + * and url route segments + */ class AnimeWatchingStatus extends Enum { const KITSU_TO_MAL = [ Kitsu::WATCHING => MAL::WATCHING, diff --git a/src/API/Mapping/MangaReadingStatus.php b/src/API/Mapping/MangaReadingStatus.php index 57a447c1..7b01c2ce 100644 --- a/src/API/Mapping/MangaReadingStatus.php +++ b/src/API/Mapping/MangaReadingStatus.php @@ -24,6 +24,10 @@ use Aviat\AnimeClient\API\Enum\MangaReadingStatus\{ }; use Aviat\Ion\Enum; +/** + * Manga reading status mappings, among Kitsu, MAL, Page titles + * and url route segments + */ class MangaReadingStatus extends Enum { const MAL_TO_KITSU = [ Kitsu::READING => MAL::READING, diff --git a/src/Command/SyncKitsuWithMal.php b/src/Command/SyncKitsuWithMal.php index d0fdf42c..441396f7 100644 --- a/src/Command/SyncKitsuWithMal.php +++ b/src/Command/SyncKitsuWithMal.php @@ -54,38 +54,38 @@ class SyncKitsuWithMal extends BaseCommand { $this->setCache($this->container->get('cache')); $this->kitsuModel = $this->container->get('kitsu-model'); $this->malModel = $this->container->get('mal-model'); - - $malCount = count($this->getMALList()); + + $malCount = count($this->getMALAnimeList()); $kitsuCount = $this->getKitsuAnimeListPageCount(); - + $this->echoBox("Number of MAL list items: {$malCount}"); $this->echoBox("Number of Kitsu list items: {$kitsuCount}"); - - $data = $this->diffLists(); + + $data = $this->diffAnimeLists(); $this->echoBox("Number of items that need to be added to MAL: " . count($data)); - + if ( ! empty($data['addToMAL'])) { $this->echoBox("Adding missing list items to MAL"); - $this->createMALListItems($data['addToMAL']); + $this->createMALAnimeListItems($data['addToMAL']); } } - - public function getKitsuList() + + public function getKitsuAnimeList() { $count = $this->getKitsuAnimeListPageCount(); $size = 100; $pages = ceil($count / $size); - + $requests = []; - + // Set up requests for ($i = 0; $i < $pages; $i++) { $offset = $i * $size; $requests[] = $this->kitsuModel->getPagedAnimeList($size, $offset); } - + $promiseArray = (new Client())->requestMulti($requests); $responses = wait(all($promiseArray)); @@ -100,15 +100,15 @@ class SyncKitsuWithMal extends BaseCommand { return $output; } - public function getMALList() + public function getMALAnimeList() { return $this->malModel->getFullList(); } - + public function filterMappings(array $includes): array { $output = []; - + foreach($includes as $id => $mapping) { if ($mapping['externalSite'] === 'myanimelist/anime') @@ -116,15 +116,15 @@ class SyncKitsuWithMal extends BaseCommand { $output[$id] = $mapping; } } - + return $output; } - - public function formatMALList() + + public function formatMALAnimeList() { - $orig = $this->getMALList(); + $orig = $this->getMALAnimeList(); $output = []; - + foreach($orig as $item) { $output[$item['series_animedb_id']] = [ @@ -144,24 +144,24 @@ class SyncKitsuWithMal extends BaseCommand { ] ]; } - + return $output; } - - public function filterKitsuList() + + public function filterKitsuAnimeList() { $data = $this->kitsuModel->getFullAnimeList(); $includes = JsonAPI::organizeIncludes($data['included']); $includes['mappings'] = $this->filterMappings($includes['mappings']); - + $output = []; - + foreach($data['data'] as $listItem) { $animeId = $listItem['relationships']['anime']['data']['id']; $potentialMappings = $includes['anime'][$animeId]['relationships']['mappings']; $malId = NULL; - + foreach ($potentialMappings as $mappingId) { if (array_key_exists($mappingId, $includes['mappings'])) @@ -169,20 +169,20 @@ class SyncKitsuWithMal extends BaseCommand { $malId = $includes['mappings'][$mappingId]['externalId']; } } - + // Skip to the next item if there isn't a MAL ID if (is_null($malId)) { continue; } - + $output[$listItem['id']] = [ 'id' => $listItem['id'], 'malId' => $malId, 'data' => $listItem['attributes'], ]; } - + return $output; } @@ -191,32 +191,32 @@ class SyncKitsuWithMal extends BaseCommand { return $this->kitsuModel->getAnimeListCount(); } - public function diffLists() + public function diffAnimeLists() { // Get libraryEntries with media.mappings from Kitsu // Organize mappings, and ignore entries without mappings - $kitsuList = $this->filterKitsuList(); + $kitsuList = $this->filterKitsuAnimeList(); // Get MAL list data - $malList = $this->formatMALList(); - + $malList = $this->formatMALAnimeList(); + $itemsToAddToMAL = []; - + foreach($kitsuList as $kitsuItem) { if (array_key_exists($kitsuItem['malId'], $malList)) { - // Eventually, compare the list entries, and determine which + // Eventually, compare the list entries, and determine which // needs to be updated continue; } - + // Looks like this item only exists on Kitsu $itemsToAddToMAL[] = [ 'mal_id' => $kitsuItem['malId'], 'data' => $kitsuItem['data'] ]; - + } // Compare each list entry @@ -227,17 +227,17 @@ class SyncKitsuWithMal extends BaseCommand { // Otherwise, use rewatch count, then episode progress as critera for selecting the more up // to date entry // Based on the 'newer' entry, update the other api list item - + return [ 'addToMAL' => $itemsToAddToMAL, ]; } - public function createMALListItems($itemsToAdd) + public function createMALAnimeListItems($itemsToAdd) { $transformer = new ALT(); $requests = []; - + foreach($itemsToAdd as $item) { $data = $transformer->untransform($item); @@ -261,5 +261,4 @@ class SyncKitsuWithMal extends BaseCommand { } } } - } \ No newline at end of file diff --git a/src/Controller/Character.php b/src/Controller/Character.php index b6204ce8..4d60d0e4 100644 --- a/src/Controller/Character.php +++ b/src/Controller/Character.php @@ -18,6 +18,9 @@ namespace Aviat\AnimeClient\Controller; use Aviat\AnimeClient\Controller as BaseController; +/** + * Controller for character description pages + */ class Character extends BaseController { public function index(string $slug)