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

This commit is contained in:
Timothy Warren 2017-03-27 10:09:45 -04:00
parent f59827f95f
commit 493ac3ca03
9 changed files with 69 additions and 73 deletions

View File

@ -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, ' && ');
}

View File

@ -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",

28
console
View File

@ -1,19 +1,10 @@
#!/usr/bin/env php
<?php declare(strict_types=1);
if ( ! function_exists('_dir'))
{
/**
* Joins paths together. Variadic to take an
* arbitrary number of arguments
*
* @return string
*/
function _dir()
{
return implode(DIRECTORY_SEPARATOR, func_get_args());
}
}
// Set up autoloader for third-party dependencies
require_once realpath(__DIR__ . '/vendor/autoload.php');
use Aviat\AnimeClient\Command;
$_SERVER['HTTP_HOST'] = 'localhost';
@ -22,9 +13,6 @@ $APP_DIR = __DIR__ . '/app/';
$SRC_DIR = __DIR__ . '/src/';
$CONF_DIR = realpath("${APP_DIR}/config/");
// Set up autoloader for third-party dependencies
require_once realpath(__DIR__ . '/vendor/autoload.php');
// Unset 'constants'
unset($APP_DIR);
unset($SRC_DIR);
@ -34,10 +22,10 @@ unset($CONF_DIR);
// Start console script
// ---------------------------------------------------------------------------------------------------------------------
$console = new \ConsoleKit\Console([
'cache-prime' => '\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();

View File

@ -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';
}

View File

@ -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);

View File

@ -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,

View File

@ -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,

View File

@ -55,23 +55,23 @@ class SyncKitsuWithMal extends BaseCommand {
$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;
@ -100,7 +100,7 @@ class SyncKitsuWithMal extends BaseCommand {
return $output;
}
public function getMALList()
public function getMALAnimeList()
{
return $this->malModel->getFullList();
}
@ -120,9 +120,9 @@ class SyncKitsuWithMal extends BaseCommand {
return $output;
}
public function formatMALList()
public function formatMALAnimeList()
{
$orig = $this->getMALList();
$orig = $this->getMALAnimeList();
$output = [];
foreach($orig as $item)
@ -148,7 +148,7 @@ class SyncKitsuWithMal extends BaseCommand {
return $output;
}
public function filterKitsuList()
public function filterKitsuAnimeList()
{
$data = $this->kitsuModel->getFullAnimeList();
$includes = JsonAPI::organizeIncludes($data['included']);
@ -191,14 +191,14 @@ 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 = [];
@ -233,7 +233,7 @@ class SyncKitsuWithMal extends BaseCommand {
];
}
public function createMALListItems($itemsToAdd)
public function createMALAnimeListItems($itemsToAdd)
{
$transformer = new ALT();
$requests = [];
@ -261,5 +261,4 @@ class SyncKitsuWithMal extends BaseCommand {
}
}
}
}

View File

@ -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)