Merge remote-tracking branch 'origin/develop'

This commit is contained in:
Timothy Warren 2018-02-02 09:53:22 -05:00
commit 98cabd32af
24 changed files with 361 additions and 171 deletions

11
console
View File

@ -5,6 +5,7 @@
require_once __DIR__ . '/vendor/autoload.php';
use Aviat\AnimeClient\Command;
use ConsoleKit\Console;
$_SERVER['HTTP_HOST'] = 'localhost';
@ -13,14 +14,10 @@ $_SERVER['HTTP_HOST'] = 'localhost';
// -----------------------------------------------------------------------------
try
{
(new \ConsoleKit\Console([
(new Console([
'cache:clear' => Command\CacheClear::class,
'cache:prime' => Command\CachePrime::class,
'lists:sync' => Command\SyncKitsuWithMal::class,
'cache-prime' => Command\CachePrime::class,
'cache-clear' => Command\CacheClear::class,
'clear-cache' => Command\CacheClear::class,
'sync-lists' => Command\SyncKitsuWithMal::class,
'cache:refresh' => Command\CachePrime::class,
'lists:sync' => Command\SyncLists::class,
]))->run();
}
catch (\Exception $e)

View File

@ -1,21 +0,0 @@
<?php declare(strict_types=1);
/**
* Hummingbird Anime List Client
*
* An API client for Kitsu and MyAnimeList to manage anime and manga watch lists
*
* PHP version 7
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.0
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
namespace Aviat\AnimeClient\API;
abstract class AbstractListItem implements ListItemInterface {
}

View File

@ -21,15 +21,17 @@ use const Aviat\AnimeClient\SESSION_SEGMENT;
use function Amp\Promise\wait;
use Amp\Artax\Request;
use Aviat\AnimeClient\API\{AbstractListItem, HummingbirdClient};
use Aviat\AnimeClient\API\{
HummingbirdClient,
ListItemInterface
};
use Aviat\Ion\Di\ContainerAware;
use Aviat\Ion\Json;
use RuntimeException;
/**
* CRUD operations for Kitsu list items
*/
class ListItem extends AbstractListItem {
class ListItem implements ListItemInterface {
use ContainerAware;
use KitsuTrait;
@ -41,7 +43,7 @@ class ListItem extends AbstractListItem {
->get('session')
->getSegment(SESSION_SEGMENT);
if ( ! is_null($sessionSegment->get('auth_token')))
if ($sessionSegment->get('auth_token') !== NULL)
{
$token = $sessionSegment->get('auth_token');
return "bearer {$token}";

View File

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

View File

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

View File

@ -18,8 +18,7 @@ namespace Aviat\AnimeClient\API\MAL;
use Aviat\AnimeClient\API\{
APIRequestBuilder,
MAL as M,
XML
MAL as M
};
class MALRequestBuilder extends APIRequestBuilder {

View File

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

View File

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

View File

@ -174,14 +174,12 @@ class XML {
*/
private static function stripXMLWhitespace(string $xml): string
{
// Get rid of unimportant text nodes by removing
// whitespace characters from between xml tags,
// except for the xml declaration tag, Which looks
// something like:
/* <?xml version="1.0" encoding="UTF-8"?> */
return preg_replace('/([^\?])>\s+</', '$1><', $xml);
return preg_replace('/([^?])>\s+</', '$1><', $xml);
}
/**
@ -191,7 +189,7 @@ class XML {
* @param DOMNodeList $nodeList The current NodeList object
* @return void
*/
private static function childNodesToArray(array &$root, DOMNodelist $nodeList)
private static function childNodesToArray(array &$root, DOMNodelist $nodeList): void
{
$length = $nodeList->length;
for ($i = 0; $i < $length; $i++)
@ -200,14 +198,14 @@ class XML {
$current =& $root[$el->nodeName];
// It's a top level element!
if (is_a($el->childNodes->item(0), 'DomText') OR ( ! $el->hasChildNodes()))
if (( ! $el->hasChildNodes()) || is_a($el->childNodes->item(0), 'DomText'))
{
$current = $el->textContent;
continue;
}
// An empty value at the current root
if (is_null($current))
if ($current === NULL)
{
$current = [];
static::childNodesToArray($current, $el->childNodes);
@ -230,7 +228,7 @@ class XML {
$current = [$current];
}
array_push($current, []);
$current[] = [];
$index = count($current) - 1;
static::childNodesToArray($current[$index], $el->childNodes);
@ -245,7 +243,7 @@ class XML {
* @param array $data The data for the current node
* @return void
*/
private static function arrayPropertiesToXmlNodes(DOMDocument &$dom, DOMNode &$parent, array $data)
private static function arrayPropertiesToXmlNodes(DOMDocument $dom, DOMNode $parent, array $data): void
{
foreach($data as $key => $props)
{
@ -260,7 +258,7 @@ class XML {
$node = $dom->createElement($key);
if (is_array($props))
if (\is_array($props))
{
static::arrayPropertiesToXmlNodes($dom, $node, $props);
}

View File

@ -27,7 +27,7 @@ use Aviat\AnimeClient\API\MAL\MALRequestBuilder;
use Aviat\Banker\Pool;
use Aviat\Ion\Config;
use Aviat\Ion\Di\{Container, ContainerAware};
use ConsoleKit\Command;
use ConsoleKit\{Command, ConsoleException};
use ConsoleKit\Widgets\Box;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Logger;
@ -47,10 +47,17 @@ class BaseCommand extends Command {
*/
protected function echoBox($message)
{
echo "\n";
$box = new Box($this->getConsole(), $message);
$box->write();
echo "\n";
try
{
echo "\n";
$box = new Box($this->getConsole(), $message);
$box->write();
echo "\n";
}
catch (ConsoleException $e)
{
// oops
}
}
/**
@ -58,12 +65,12 @@ class BaseCommand extends Command {
*
* @return Container
*/
protected function setupContainer()
protected function setupContainer(): Container
{
$APP_DIR = realpath(__DIR__ . '/../../app');
$APPCONF_DIR = realpath("{$APP_DIR}/appConf/");
$CONF_DIR = realpath("{$APP_DIR}/config/");
$base_config = require_once $APPCONF_DIR . '/base_config.php';
$base_config = require $APPCONF_DIR . '/base_config.php';
$config = loadToml($CONF_DIR);
$config_array = array_merge($base_config, $config);

View File

@ -25,10 +25,11 @@ class CacheClear extends BaseCommand {
*
* @param array $args
* @param array $options
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @return void
* @throws \ConsoleKit\ConsoleException
*/
public function execute(array $args, array $options = [])
public function execute(array $args, array $options = []): void
{
$this->setContainer($this->setupContainer());
$cache = $this->container->get('cache');

View File

@ -25,10 +25,11 @@ class CachePrime extends BaseCommand {
*
* @param array $args
* @param array $options
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @return void
* @throws \ConsoleKit\ConsoleException
*/
public function execute(array $args, array $options = [])
public function execute(array $args, array $options = []): void
{
$this->setContainer($this->setupContainer());
@ -42,7 +43,7 @@ class CachePrime extends BaseCommand {
$this->echoBox('Cache cleared, re-priming...');
if ( ! is_null($userId))
if ($userId !== NULL)
{
$userIdItem = $cache->getItem('kitsu-auth-token');
$userIdItem->set($userId);

View File

@ -27,11 +27,12 @@ use Aviat\AnimeClient\API\MAL\Transformer\{
AnimeListTransformer as ALT
};
use Aviat\Ion\Json;
use DateTime;
/**
* Clears the API Cache
*/
class SyncKitsuWithMal extends BaseCommand {
class SyncLists extends BaseCommand {
/**
* Model for making requests to Kitsu API
@ -50,9 +51,11 @@ class SyncKitsuWithMal extends BaseCommand {
*
* @param array $args
* @param array $options
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @return void
*/
public function execute(array $args, array $options = [])
public function execute(array $args, array $options = []): void
{
$this->setContainer($this->setupContainer());
$this->setCache($this->container->get('cache'));
@ -63,7 +66,13 @@ class SyncKitsuWithMal extends BaseCommand {
$this->sync('manga');
}
public function sync(string $type)
/**
* Attempt to synchronize external apis
*
* @param string $type anime|manga
* @return void
*/
protected function sync(string $type): void
{
$uType = ucfirst($type);
@ -124,7 +133,14 @@ class SyncKitsuWithMal extends BaseCommand {
}
}
public function filterMappings(array $includes, string $type = 'anime'): array
/**
* Filter Kitsu mappings for the specified type
*
* @param array $includes
* @param string $type
* @return array
*/
protected function filterMappings(array $includes, string $type = 'anime'): array
{
$output = [];
@ -139,20 +155,25 @@ class SyncKitsuWithMal extends BaseCommand {
return $output;
}
public function formatMALList(string $type): array
/**
* Format a MAL list for comparison
*
* @param string $type
* @return array
*/
protected function formatMALList(string $type): array
{
if ($type === 'anime')
{
return $this->formatMALAnimeList();
}
if ($type === 'manga')
{
return $this->formatMALMangaList();
}
$type = ucfirst($type);
$method = "formatMAL{$type}List";
return $this->$method();
}
public function formatMALAnimeList()
/**
* Format a MAL anime list for comparison
*
* @return array
*/
protected function formatMALAnimeList(): array
{
$orig = $this->malModel->getList('anime');
$output = [];
@ -191,7 +212,12 @@ class SyncKitsuWithMal extends BaseCommand {
return $output;
}
public function formatMALMangaList()
/**
* Format a MAL manga list for comparison
*
* @return array
*/
protected function formatMALMangaList(): array
{
$orig = $this->malModel->getList('manga');
$output = [];
@ -232,7 +258,13 @@ class SyncKitsuWithMal extends BaseCommand {
return $output;
}
public function formatKitsuList(string $type = 'anime'): array
/**
* Format a kitsu list for the sake of comparision
*
* @param string $type
* @return array
*/
protected function formatKitsuList(string $type = 'anime'): array
{
$data = $this->kitsuModel->{'getFull' . ucfirst($type) . 'List'}();
@ -262,7 +294,7 @@ class SyncKitsuWithMal extends BaseCommand {
}
// Skip to the next item if there isn't a MAL ID
if (is_null($malId))
if ($malId === NULL)
{
continue;
}
@ -277,7 +309,13 @@ class SyncKitsuWithMal extends BaseCommand {
return $output;
}
public function diffLists(string $type = 'anime'): array
/**
* Go through lists of the specified type, and determine what kind of action each item needs
*
* @param string $type
* @return array
*/
protected function diffLists(string $type = 'anime'): array
{
// Get libraryEntries with media.mappings from Kitsu
// Organize mappings, and ignore entries without mappings
@ -305,21 +343,21 @@ class SyncKitsuWithMal extends BaseCommand {
foreach($kitsuList as $kitsuItem)
{
if (in_array($kitsuItem['malId'], $malIds))
if (\in_array($kitsuItem['malId'], $malIds, TRUE))
{
$item = $this->compareListItems($kitsuItem, $malList[$kitsuItem['malId']]);
if (is_null($item))
if ($item === NULL)
{
continue;
}
if (in_array('kitsu', $item['updateType']))
if (\in_array('kitsu', $item['updateType'], TRUE))
{
$kitsuUpdateItems[] = $item['data'];
}
if (in_array('mal', $item['updateType']))
if (\in_array('mal', $item['updateType'], TRUE))
{
$malUpdateItems[] = $item['data'];
}
@ -343,11 +381,18 @@ class SyncKitsuWithMal extends BaseCommand {
];
}
public function compareListItems(array $kitsuItem, array $malItem)
/**
* Compare two list items, and return the out of date one, if one exists
*
* @param array $kitsuItem
* @param array $malItem
* @return array|null
*/
protected function compareListItems(array $kitsuItem, array $malItem): ?array
{
$compareKeys = ['status', 'progress', 'rating', 'reconsuming'];
$diff = [];
$dateDiff = (new \DateTime($kitsuItem['data']['updatedAt'])) <=> (new \DateTime($malItem['data']['updatedAt']));
$dateDiff = new DateTime($kitsuItem['data']['updatedAt']) <=> new DateTime($malItem['data']['updatedAt']);
foreach($compareKeys as $key)
{
@ -359,7 +404,7 @@ class SyncKitsuWithMal extends BaseCommand {
$diffValues = array_unique($diffValues);
if (count($diffValues) === 1 && $diffValues[0] === 0)
{
return;
return NULL;
}
$update = [
@ -460,7 +505,14 @@ class SyncKitsuWithMal extends BaseCommand {
return $return;
}
public function updateKitsuListItems($itemsToUpdate, string $action = 'update', string $type = 'anime'): void
/**
* Create/Update list items on Kitsu
*
* @param array $itemsToUpdate
* @param string $action
* @param string $type
*/
protected function updateKitsuListItems(array $itemsToUpdate, string $action = 'update', string $type = 'anime'): void
{
$requester = new ParallelAPIRequest();
foreach($itemsToUpdate as $item)
@ -496,7 +548,14 @@ class SyncKitsuWithMal extends BaseCommand {
}
}
public function updateMALListItems($itemsToUpdate, string $action = 'update', string $type = 'anime'): void
/**
* Create/Update list items on MAL
*
* @param array $itemsToUpdate
* @param string $action
* @param string $type
*/
protected function updateMALListItems(array$itemsToUpdate, string $action = 'update', string $type = 'anime'): void
{
$transformer = new ALT();
$requester = new ParallelAPIRequest();

View File

@ -22,10 +22,6 @@ use Aviat\Ion\Di\{
ContainerAware,
ContainerInterface
};
use Aviat\Ion\Di\Exception\{
ContainerException,
NotFoundException
};
use Aviat\Ion\Exception\DoubleRenderException;
use Aviat\Ion\View\{HtmlView, HttpView, JsonView};
use InvalidArgumentException;
@ -92,9 +88,9 @@ class Controller {
/**
* Constructor
*
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @param ContainerInterface $container
* @throws ContainerException
* @throws NotFoundException
*/
public function __construct(ContainerInterface $container)
{
@ -135,7 +131,7 @@ class Controller {
*
* @return void
*/
public function redirectToPrevious()
public function redirectToPrevious(): void
{
$previous = $this->session->getFlash('previous');
$this->redirect($previous, 303);
@ -144,9 +140,9 @@ class Controller {
/**
* Set the current url in the session as the target of a future redirect
*
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @param string|null $url
* @throws ContainerException
* @throws NotFoundException
* @return void
*/
public function setSessionRedirect(string $url = NULL): void
@ -312,6 +308,7 @@ class Controller {
/**
* Redirect to the default controller/url from an empty path
*
* @throws InvalidArgumentException
* @return void
*/
public function redirectToDefaultRoute(): void

View File

@ -41,6 +41,8 @@ class Anime extends BaseController {
* Constructor
*
* @param ContainerInterface $container
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
*/
public function __construct(ContainerInterface $container)
{
@ -63,11 +65,14 @@ class Anime extends BaseController {
*
* @param string|int $type - The section of the list
* @param string $view - List or cover view
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws \InvalidArgumentException
* @return void
*/
public function index($type = KitsuWatchingStatus::WATCHING, string $view = NULL)
public function index($type = KitsuWatchingStatus::WATCHING, string $view = NULL): void
{
$title = (array_key_exists($type, AnimeWatchingStatus::ROUTE_TO_TITLE))
$title = array_key_exists($type, AnimeWatchingStatus::ROUTE_TO_TITLE)
? $this->formatTitle(
$this->config->get('whose_list') . "'s Anime List",
AnimeWatchingStatus::ROUTE_TO_TITLE[$type]
@ -92,9 +97,13 @@ class Anime extends BaseController {
/**
* Form to add an anime
*
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws \Aura\Router\Exception\RouteNotFound
* @throws \InvalidArgumentException
* @return void
*/
public function addForm()
public function addForm(): void
{
$this->setSessionRedirect();
$this->outputHTML('anime/add', [
@ -110,9 +119,11 @@ class Anime extends BaseController {
/**
* Add an anime to the list
*
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @return void
*/
public function add()
public function add(): void
{
$data = $this->request->getParsedBody();
if ( ! array_key_exists('id', $data))
@ -140,9 +151,12 @@ class Anime extends BaseController {
*
* @param int $id
* @param string $status
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws \InvalidArgumentException
* @return void
*/
public function edit($id, $status = "all")
public function edit($id, $status = 'all'): void
{
$item = $this->model->getLibraryItem($id);
$this->setSessionRedirect();
@ -165,7 +179,7 @@ class Anime extends BaseController {
*
* @return void
*/
public function search()
public function search(): void
{
$queryParams = $this->request->getQueryParams();
$query = $queryParams['query'];
@ -175,9 +189,11 @@ class Anime extends BaseController {
/**
* Update an anime item via a form submission
*
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @return void
*/
public function formUpdate()
public function formUpdate(): void
{
$data = $this->request->getParsedBody();
@ -205,7 +221,7 @@ class Anime extends BaseController {
*
* @return void
*/
public function update()
public function update(): void
{
if (stripos($this->request->getHeader('content-type')[0], 'application/json') !== FALSE)
{
@ -225,9 +241,11 @@ class Anime extends BaseController {
/**
* Remove an anime from the list
*
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @return void
*/
public function delete()
public function delete(): void
{
$body = $this->request->getParsedBody();
$response = $this->model->deleteLibraryItem($body['id'], $body['mal_id']);
@ -249,9 +267,12 @@ class Anime extends BaseController {
* View details of an anime
*
* @param string $animeId
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws \InvalidArgumentException
* @return void
*/
public function details(string $animeId)
public function details(string $animeId): void
{
$show_data = $this->model->getAnime($animeId);
$characters = [];
@ -287,5 +308,14 @@ class Anime extends BaseController {
]);
}
/**
* Find anime matching the selected genre
*
* @param string $genre
*/
public function genre(string $genre): void
{
// @TODO: implement
}
}
// End of AnimeController.php

View File

@ -44,6 +44,8 @@ class AnimeCollection extends BaseController {
* Constructor
*
* @param ContainerInterface $container
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
*/
public function __construct(ContainerInterface $container)
{
@ -63,6 +65,7 @@ class AnimeCollection extends BaseController {
/**
* Search for anime
*
* @throws \Aviat\Ion\Exception\DoubleRenderException
* @return void
*/
public function search()
@ -76,6 +79,9 @@ class AnimeCollection extends BaseController {
* Show the anime collection page
*
* @param string $view
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws \InvalidArgumentException
* @return void
*/
public function index($view)
@ -98,13 +104,17 @@ class AnimeCollection extends BaseController {
* Show the anime collection add/edit form
*
* @param integer|null $id
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws \Aura\Router\Exception\RouteNotFound
* @throws \InvalidArgumentException
* @return void
*/
public function form($id = NULL)
{
$this->setSessionRedirect();
$action = (is_null($id)) ? "Add" : "Edit";
$action = $id === NULL ? 'Add' : 'Edit';
$urlAction = strtolower($action);
$this->outputHTML('collection/' . $urlAction, [
@ -115,13 +125,16 @@ class AnimeCollection extends BaseController {
$action
),
'media_items' => $this->animeCollectionModel->getMediaTypeList(),
'item' => ($action === "Edit") ? $this->animeCollectionModel->get($id) : []
'item' => ($action === 'Edit') ? $this->animeCollectionModel->get($id) : []
]);
}
/**
* Update a collection item
*
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws \InvalidArgumentException
* @return void
*/
public function edit()
@ -143,6 +156,9 @@ class AnimeCollection extends BaseController {
/**
* Add a collection item
*
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws \InvalidArgumentException
* @return void
*/
public function add()
@ -171,13 +187,13 @@ class AnimeCollection extends BaseController {
$data = $this->request->getParsedBody();
if ( ! array_key_exists('hummingbird_id', $data))
{
$this->redirect("/anime-collection/view", 303);
$this->redirect('/anime-collection/view', 303);
}
$this->animeCollectionModel->delete($data);
$this->setFlashMessage("Successfully removed anime from collection.", 'success');
$this->setFlashMessage('Successfully removed anime from collection.', 'success');
$this->redirect("/anime-collection/view", 303);
$this->redirect('/anime-collection/view', 303);
}
}
// End of CollectionController.php

View File

@ -27,7 +27,16 @@ class Character extends BaseController {
use ArrayWrapper;
public function index(string $slug)
/**
* Show information about a character
*
* @param string $slug
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws \InvalidArgumentException
* @return void
*/
public function index(string $slug): void
{
$model = $this->container->get('kitsu-model');
@ -88,8 +97,9 @@ class Character extends BaseController {
$person = current($role['relationships']['person']['people'])['attributes'];
$hasName = array_key_exists($person['name'], $people);
if ( ! array_key_exists($person['name'], $people))
if ( ! $hasName)
{
$people[$person['name']] = $i;
$role['relationships']['media']['anime'] = [current($role['relationships']['media']['anime'])];
@ -99,15 +109,13 @@ class Character extends BaseController {
continue;
}
else if(array_key_exists($person['name'], $people))
if (array_key_exists('anime', $role['relationships']['media']))
{
if (array_key_exists('anime', $role['relationships']['media']))
{
$key = $people[$person['name']];
$output[$key]['relationships']['media']['anime'][] = current($role['relationships']['media']['anime']);
}
continue;
$key = $people[$person['name']];
$output[$key]['relationships']['media']['anime'][] = current($role['relationships']['media']['anime']);
}
continue;
}
return $output;
@ -122,7 +130,7 @@ class Character extends BaseController {
if (
array_key_exists('attributes', $role) &&
array_key_exists('role', $role['attributes']) &&
( ! is_null($role['attributes']['role']))
$role['attributes']['role'] !== NULL
) {
$count++;
}

View File

@ -30,6 +30,9 @@ class Index extends BaseController {
/**
* Purges the API cache
*
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws \InvalidArgumentException
* @return void
*/
public function clearCache()
@ -37,13 +40,16 @@ class Index extends BaseController {
$this->cache->clear();
$this->outputHTML('blank', [
'title' => 'Cache cleared'
], NULL, 200);
]);
}
/**
* Show the login form
*
* @param string $status
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws \InvalidArgumentException
* @return void
*/
public function login(string $status = '')
@ -69,6 +75,10 @@ class Index extends BaseController {
/**
* Attempt login authentication
*
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws \Aura\Router\Exception\RouteNotFound
* @throws \InvalidArgumentException
* @return void
*/
public function loginAction()
@ -88,6 +98,9 @@ class Index extends BaseController {
/**
* Deauthorize the current user
*
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws \InvalidArgumentException
* @return void
*/
public function logout()
@ -101,6 +114,9 @@ class Index extends BaseController {
/**
* Show the user profile page
*
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws \InvalidArgumentException
* @return void
*/
public function me()
@ -111,8 +127,8 @@ class Index extends BaseController {
$orgData = JsonAPI::organizeData($data)[0];
$rels = $orgData['relationships'] ?? [];
$favorites = array_key_exists('favorites', $rels) ? $rels['favorites'] : [];
$this->outputHTML('me', [
'title' => 'About ' . $this->config->get('whose_list'),
'data' => $orgData,
@ -125,9 +141,17 @@ class Index extends BaseController {
/**
* Get image covers from kitsu
*
* @param string $type The category of image
* @param string $file The filename to look for
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws \InvalidArgumentException
* @throws \TypeError
* @throws \Error
* @throws \Throwable
* @return void
*/
public function images($type, $file)
public function images(string $type, string $file): void
{
$kitsuUrl = 'https://media.kitsu.io/';
list($id, $ext) = explode('.', basename($file));
@ -164,9 +188,14 @@ class Index extends BaseController {
echo $data;
}
/**
* Reorganize favorites data to be more useful
*
* @param array $rawfavorites
* @return array
*/
private function organizeFavorites(array $rawfavorites): array
{
// return $rawfavorites;
$output = [];
unset($rawfavorites['data']);

View File

@ -40,6 +40,8 @@ class Manga extends Controller {
* Constructor
*
* @param ContainerInterface $container
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
*/
public function __construct(ContainerInterface $container)
{
@ -59,9 +61,12 @@ class Manga extends Controller {
*
* @param string $status
* @param string $view
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws \InvalidArgumentException
* @return void
*/
public function index($status = "all", $view = "")
public function index($status = 'all', $view = ''): void
{
$statusTitle = MangaReadingStatus::ROUTE_TO_TITLE[$status];
@ -88,9 +93,13 @@ class Manga extends Controller {
/**
* Form to add an manga
*
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws \Aura\Router\Exception\RouteNotFound
* @throws \InvalidArgumentException
* @return void
*/
public function addForm()
public function addForm(): void
{
$statuses = MangaReadingStatus::KITSU_TO_TITLE;
@ -108,14 +117,16 @@ class Manga extends Controller {
/**
* Add an manga to the list
*
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @return void
*/
public function add()
public function add(): void
{
$data = $this->request->getParsedBody();
if ( ! array_key_exists('id', $data))
{
$this->redirect("manga/add", 303);
$this->redirect('manga/add', 303);
}
$result = $this->model->createLibraryItem($data);
@ -138,9 +149,13 @@ class Manga extends Controller {
*
* @param string $id
* @param string $status
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws \Aura\Router\Exception\RouteNotFound
* @throws \InvalidArgumentException
* @return void
*/
public function edit($id, $status = "All")
public function edit($id, $status = 'All'): void
{
$this->setSessionRedirect();
$item = $this->model->getLibraryItem($id);
@ -164,7 +179,7 @@ class Manga extends Controller {
*
* @return void
*/
public function search()
public function search(): void
{
$query_data = $this->request->getQueryParams();
$this->outputJSON($this->model->search($query_data['query']));
@ -173,9 +188,11 @@ class Manga extends Controller {
/**
* Update an manga item via a form submission
*
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @return void
*/
public function formUpdate()
public function formUpdate(): void
{
$data = $this->request->getParsedBody();
@ -202,9 +219,11 @@ class Manga extends Controller {
/**
* Update a manga item
*
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @return void
*/
public function update()
public function update(): void
{
if (stripos($this->request->getHeader('content-type')[0], 'application/json') !== FALSE)
{
@ -224,9 +243,11 @@ class Manga extends Controller {
/**
* Remove an manga from the list
*
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @return void
*/
public function delete()
public function delete(): void
{
$body = $this->request->getParsedBody();
$id = $body['id'];
@ -250,9 +271,12 @@ class Manga extends Controller {
* View details of an manga
*
* @param string $manga_id
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws \InvalidArgumentException
* @return void
*/
public function details($manga_id)
public function details($manga_id): void
{
$data = $this->model->getManga($manga_id);
$characters = [];
@ -286,5 +310,15 @@ class Manga extends Controller {
'data' => $data,
]);
}
/**
* Find manga matching the selected genre
*
* @param string $genre
*/
public function genre(string $genre): void
{
// @TODO: implement
}
}
// End of MangaController.php

View File

@ -21,7 +21,6 @@ use Aviat\AnimeClient\Model\{
Manga as MangaModel,
MangaCollection as MangaCollectionModel
};
use Aviat\AnimeClient\UrlGenerator;
use Aviat\Ion\Di\ContainerInterface;
/**
@ -45,6 +44,9 @@ class MangaCollection extends BaseController {
* Constructor
*
* @param ContainerInterface $container
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws \InvalidArgumentException
*/
public function __construct(ContainerInterface $container)
{
@ -64,9 +66,10 @@ class MangaCollection extends BaseController {
/**
* Search for manga
*
* @throws \Aviat\Ion\Exception\DoubleRenderException
* @return void
*/
public function search()
public function search(): void
{
$queryParams = $this->request->getQueryParams();
$query = $queryParams['query'];
@ -77,9 +80,12 @@ class MangaCollection extends BaseController {
* Show the manga collection page
*
* @param string $view
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws \InvalidArgumentException
* @return void
*/
public function index($view)
public function index($view): void
{
$viewMap = [
'' => 'cover',
@ -99,13 +105,17 @@ class MangaCollection extends BaseController {
* Show the manga collection add/edit form
*
* @param integer|null $id
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws \Aura\Router\Exception\RouteNotFound
* @throws \InvalidArgumentException
* @return void
*/
public function form($id = NULL)
public function form($id = NULL): void
{
$this->setSessionRedirect();
$action = (is_null($id)) ? "Add" : "Edit";
$action = $id === NULL ? 'Add' : 'Edit';
$urlAction = strtolower($action);
$this->outputHTML('collection/' . $urlAction, [
@ -116,13 +126,16 @@ class MangaCollection extends BaseController {
$action
),
'media_items' => $this->mangaCollectionModel->getMediaTypeList(),
'item' => ($action === "Edit") ? $this->mangaCollectionModel->get($id) : []
'item' => ($action === 'Edit') ? $this->mangaCollectionModel->get($id) : []
]);
}
/**
* Update a collection item
*
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws \InvalidArgumentException
* @return void
*/
public function edit()
@ -144,6 +157,9 @@ class MangaCollection extends BaseController {
/**
* Add a collection item
*
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws \InvalidArgumentException
* @return void
*/
public function add()
@ -172,13 +188,13 @@ class MangaCollection extends BaseController {
$data = $this->request->getParsedBody();
if ( ! array_key_exists('hummingbird_id', $data))
{
$this->redirect("/manga-collection/view", 303);
$this->redirect('/manga-collection/view', 303);
}
$this->mangaCollectionModel->delete($data);
$this->setFlashMessage("Successfully removed manga from collection.", 'success');
$this->setFlashMessage('Successfully removed manga from collection.', 'success');
$this->redirect("/manga-collection/view", 303);
$this->redirect('/manga-collection/view', 303);
}
}
// End of CollectionController.php

View File

@ -45,6 +45,8 @@ class Manga extends API
* Constructor
*
* @param ContainerInterface $container
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
*/
public function __construct(ContainerInterface $container)
{
@ -61,7 +63,7 @@ class Manga extends API
* @param string $status
* @return array
*/
public function getList($status)
public function getList($status): array
{
if ($status === 'All')
{
@ -79,7 +81,7 @@ class Manga extends API
* @param string $manga_id
* @return array
*/
public function getManga($manga_id)
public function getManga($manga_id): array
{
return $this->kitsuModel->getManga($manga_id);
}
@ -122,7 +124,7 @@ class Manga extends API
$malData = $data;
$malId = $this->kitsuModel->getMalIdForManga($malData['id']);
if ( ! is_null($malId))
if ($malId !== NULL)
{
$malData['id'] = $malId;
$requester->addRequest($this->malModel->createListItem($malData, 'manga'), 'mal');
@ -155,7 +157,7 @@ class Manga extends API
$results = $requester->makeRequests();
$body = Json::decode($results['kitsu']);
$statusCode = (array_key_exists('error', $body)) ? 400: 200;
$statusCode = array_key_exists('error', $body) ? 400: 200;
return [
'body' => Json::decode($results['kitsu']),
@ -174,7 +176,7 @@ class Manga extends API
{
$requester = new ParallelAPIRequest();
if ($this->useMALAPI && ! is_null($malId))
if ($this->useMALAPI && $malId !== NULL)
{
$requester->addRequest($this->malModel->deleteListItem($malId, 'manga'), 'MAL');
}
@ -192,7 +194,7 @@ class Manga extends API
* @param string $name
* @return array
*/
public function search($name)
public function search($name): array
{
return $this->kitsuModel->search('manga', $name);
}
@ -203,7 +205,7 @@ class Manga extends API
* @param array $data
* @return array
*/
private function mapByStatus($data)
private function mapByStatus(array $data): array
{
$output = [
Title::READING => [],

View File

@ -54,6 +54,9 @@ class RoutingBase {
* Constructor
*
* @param ContainerInterface $container
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws \Aviat\Ion\Exception\ConfigException
*/
public function __construct(ContainerInterface $container)
{
@ -64,7 +67,7 @@ class RoutingBase {
}
/**
* Retreive the appropriate value for the routing key
* Retrieve the appropriate value for the routing key
*
* @param string $key
* @return mixed
@ -79,10 +82,11 @@ class RoutingBase {
/**
* Get the current url path
*
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @return string
*/
public function path()
public function path(): string
{
$request = $this->container->get('request');
$path = $request->getUri()->getPath();
@ -97,10 +101,11 @@ class RoutingBase {
/**
* Get the url segments
*
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @return array
*/
public function segments()
public function segments(): array
{
$path = $this->path();
return explode('/', $path);
@ -110,20 +115,24 @@ class RoutingBase {
* Get a segment of the current url
*
* @param int $num
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @return string|null
*/
public function getSegment($num)
public function getSegment($num): ?string
{
$segments = $this->segments();
return (array_key_exists($num, $segments)) ? $segments[$num] : NULL;
return $segments[$num] ?? NULL;
}
/**
* Retrieve the last url segment
*
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @return string
*/
public function lastSegment()
public function lastSegment(): string
{
$segments = $this->segments();
return end($segments);

View File

@ -34,6 +34,8 @@ class UrlGenerator extends RoutingBase {
* Constructor
*
* @param ContainerInterface $container
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
*/
public function __construct(ContainerInterface $container)
{
@ -44,17 +46,17 @@ class UrlGenerator extends RoutingBase {
/**
* Get the base url for css/js/images
*
* @param string ...$args url segments to apend to the base asset url
* @param string[] ...$args
* @return string
*/
public function assetUrl(...$args): string
public function assetUrl(string ...$args): string
{
$baseUrl = rtrim($this->url(""), '/');
$baseUrl = "{$baseUrl}" . $this->__get("asset_path");
$baseUrl = rtrim($this->url(''), '/')
. $this->__get('asset_path');
array_unshift($args, $baseUrl);
return implode("/", $args);
return implode('/', $args);
}
/**
@ -82,7 +84,7 @@ class UrlGenerator extends RoutingBase {
$segments[$i + 1] = "";
}
$path_segments[$i] = preg_replace('`{.*?}`i', $segments[$i + 1], $path_segments[$i]);
$path_segments[$i] = preg_replace('`{.*?}`', $segments[$i + 1], $path_segments[$i]);
}
$path = implode('/', $path_segments);
@ -101,7 +103,7 @@ class UrlGenerator extends RoutingBase {
$type = trim($type);
$defaultPath = $this->__get("default_{$type}_list_path");
if ( ! is_null($defaultPath))
if ($defaultPath !== NULL)
{
return $this->url("{$type}/{$defaultPath}");
}

View File

@ -18,7 +18,6 @@ namespace Aviat\AnimeClient;
use Aviat\Ion\ConfigInterface;
use Aviat\Ion\Di\{ContainerAware, ContainerInterface};
use DomainException;
/**
* Utility method class
@ -53,6 +52,8 @@ class Util {
* Set up the Util class
*
* @param ContainerInterface $container
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
*/
public function __construct(ContainerInterface $container)
{
@ -87,12 +88,14 @@ class Util {
/**
* Determine whether to show the sub-menu
*
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @return bool
*/
public function isViewPage()
public function isViewPage(): bool
{
$url = $this->container->get('request')->getUri();
$pageSegments = explode("/", (string) $url);
$pageSegments = explode('/', (string) $url);
$intersect = array_intersect($pageSegments, self::$formPages);
@ -103,9 +106,11 @@ class Util {
* Determine whether the page is a page with a form, and
* not suitable for redirection
*
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @return boolean
*/
public function isFormPage()
public function isFormPage(): bool
{
return ! $this->isViewPage();
}