Version 5.1 - All the GraphQL #32

Closed
timw4mail wants to merge 1160 commits from develop into master
310 changed files with 6862 additions and 1791 deletions
Showing only changes of commit b200085a3f - Show all commits

1
.gitignore vendored
View File

@ -146,3 +146,4 @@ public/images/manga/**
public/images/characters/**
public/images/people/**
public/mal_mappings.json
.phpunit.result.cache

View File

@ -4,23 +4,21 @@ install:
- composer install --ignore-platform-reqs
php:
- 7.1
- 7.2
- 7.3
- 7.4
- nightly
script:
- mkdir -p build/logs
- phpdbg -qrr -- vendor/bin/phpunit -c build
- php vendor/bin/phpunit -c build
after_script:
- CODECLIMATE_REPO_TOKEN=2cbddcebcb9256b3402867282e119dbe61de0b31039325356af3c7d72ed6d058 vendor/bin/test-reporter
#after_script:
# - CODECLIMATE_REPO_TOKEN=2cbddcebcb9256b3402867282e119dbe61de0b31039325356af3c7d72ed6d058 vendor/bin/test-reporter
matrix:
allow_failures:
- php: nightly
- php: hhvm
addons:
code_climate:
repo_token: 2cbddcebcb9256b3402867282e119dbe61de0b31039325356af3c7d72ed6d058
#addons:
# code_climate:
# repo_token: 2cbddcebcb9256b3402867282e119dbe61de0b31039325356af3c7d72ed6d058

View File

@ -1,6 +1,11 @@
# Changelog
## Version 4.2
* Updated dependencies
* Updated PHP requirement to 7.3
## Version 4.1
* Added optional dark theme
* Removed MAL integration, added Anilist Integration
* Now uses WebP cache images when the browser supports it
* Replaces JS minifier with pre-minified scripts (Removes the need for one caching folder, too)

74
Jenkinsfile vendored
View File

@ -1,36 +1,13 @@
pipeline {
agent none
stages {
stage('PHP 7.1') {
agent {
docker {
image 'php:7.1-alpine'
args '-u root --privileged'
}
}
stage('setup') {
agent any
steps {
sh 'chmod +x ./build/docker_install.sh'
sh 'sh build/docker_install.sh'
sh 'apk add --no-cache php7-phpdbg'
sh 'curl -sS https://getcomposer.org/installer | php'
sh 'rm -rf ./vendor'
sh 'rm -f composer.lock'
sh 'php composer.phar install --ignore-platform-reqs'
sh 'phpdbg -qrr -- ./vendor/bin/phpunit --coverage-text --colors=never'
}
}
stage('PHP 7.2') {
agent {
docker {
image 'php:7.2-alpine'
args '-u root --privileged'
}
}
steps {
sh 'chmod +x ./build/docker_install.sh'
sh 'sh build/docker_install.sh'
sh 'apk add --no-cache php7-phpdbg'
sh 'curl -sS https://getcomposer.org/installer | php'
sh 'php composer.phar install --ignore-platform-reqs'
sh 'phpdbg -qrr -- ./vendor/bin/phpunit --coverage-text --colors=never'
}
}
stage('PHP 7.3') {
@ -41,12 +18,43 @@ pipeline {
}
}
steps {
sh 'chmod +x ./build/docker_install.sh'
sh 'sh build/docker_install.sh'
sh 'apk add --no-cache php7-phpdbg'
sh 'curl -sS https://getcomposer.org/installer | php'
sh 'php composer.phar install --ignore-platform-reqs'
sh 'phpdbg -qrr -- ./vendor/bin/phpunit --coverage-text --colors=never'
sh 'apk add --no-cache git'
sh 'php ./vendor/bin/phpunit --colors=never'
}
}
stage('PHP 7.4') {
agent {
docker {
image 'php:7.4-alpine'
args '-u root --privileged'
}
}
steps {
sh 'apk add --no-cache git'
sh 'php ./vendor/bin/phpunit --colors=never'
}
}
stage('Latest PHP') {
agent {
docker {
image 'php:alpine'
args '-u root --privileged'
}
}
steps {
sh 'apk add --no-cache git'
sh 'php ./vendor/bin/phpunit --colors=never'
}
}
stage('Coverage') {
agent any
steps {
sh 'php composer.phar run-script coverage'
step([
$class: 'CloverPublisher',
cloverReportDir: '',
cloverReportFileName: 'build/logs/clover.xml',
])
}
}
}

View File

@ -3,7 +3,7 @@
Update your anime/manga list on Kitsu.io and MyAnimeList.net
[![Build Status](https://travis-ci.org/timw4mail/HummingBirdAnimeClient.svg?branch=master)](https://travis-ci.org/timw4mail/HummingBirdAnimeClient)
[![Build Status](https://jenkins.timshomepage.net/buildStatus/icon?job=aviat/HummingBirdAnimeClient/develop)](https://jenkins.timshomepage.net/job/aviat/HummingBirdAnimeClient/develop)
[![Build Status](https://jenkins.timshomepage.net/buildStatus/icon?job=timw4mail/HummingBirdAnimeClient/develop)](https://jenkins.timshomepage.net/job/timw4mail/HummingBirdAnimeClient/develop)
[[Hosted Example](https://list.timshomepage.net)]
@ -31,7 +31,7 @@ Update your anime/manga list on Kitsu.io and MyAnimeList.net
### Requirements
* PHP 7.1+
* PHP 7.3+
* PDO SQLite or PDO PostgreSQL (For collection tab)
* GD extension for caching images

View File

@ -54,12 +54,13 @@ class RoboFile extends Tasks {
/**
* Do static analysis tasks
*/
public function analyze()
public function analyze(): void
{
$this->prepare();
$this->lint();
$this->phploc(TRUE);
$this->phpcs(TRUE);
$this->phpmd(TRUE);
$this->dependencyReport();
$this->phpcpdReport();
}
@ -67,7 +68,7 @@ class RoboFile extends Tasks {
/**
* Run all tests, generate coverage, generate docs, generate code statistics
*/
public function build()
public function build(): void
{
$this->analyze();
$this->coverage();
@ -77,19 +78,19 @@ class RoboFile extends Tasks {
/**
* Cleanup temporary files
*/
public function clean()
public function clean(): void
{
$cleanFiles = [
'build/humbug.json',
'build/humbug-log.txt',
];
array_map(function ($file) {
array_map(static function ($file) {
@unlink($file);
}, $cleanFiles);
// So the task doesn't complain,
// make any 'missing' dirs to cleanup
array_map(function ($dir) {
array_map(static function ($dir) {
if ( ! is_dir($dir))
{
`mkdir -p {$dir}`;
@ -103,7 +104,7 @@ class RoboFile extends Tasks {
/**
* Run unit tests and generate coverage reports
*/
public function coverage()
public function coverage(): void
{
$this->_run(['phpdbg -qrr -- vendor/bin/phpunit -c build']);
}
@ -111,7 +112,7 @@ class RoboFile extends Tasks {
/**
* Generate documentation with phpdox
*/
public function docs()
public function docs(): void
{
$cmd_parts = [
'vendor/bin/phpdox',
@ -122,11 +123,11 @@ class RoboFile extends Tasks {
/**
* Verify that source files are valid
*/
public function lint()
public function lint(): void
{
$files = $this->getAllSourceFiles();
$chunks = array_chunk($files, 12);
$chunks = array_chunk($files, (int)shell_exec('getconf _NPROCESSORS_ONLN'));
foreach($chunks as $chunk)
{
@ -139,7 +140,7 @@ class RoboFile extends Tasks {
*
* @param bool $report - if true, generates reports instead of direct output
*/
public function phpcs($report = FALSE)
public function phpcs($report = FALSE): void
{
$report_cmd_parts = [
'vendor/bin/phpcs',
@ -157,12 +158,36 @@ class RoboFile extends Tasks {
$this->_run($cmd_parts);
}
public function phpmd($report = FALSE): void
{
$report_cmd_parts = [
'vendor/bin/phpmd',
'./src',
'xml',
'cleancode,codesize,controversial,design,naming,unusedcode',
'--exclude ParallelAPIRequest',
'--reportfile ./build/logs/phpmd.xml'
];
$normal_cmd_parts = [
'vendor/bin/phpmd',
'./src',
'ansi',
'cleancode,codesize,controversial,design,naming,unusedcode',
'--exclude ParallelAPIRequest'
];
$cmd_parts = ($report) ? $report_cmd_parts : $normal_cmd_parts;
$this->_run($cmd_parts);
}
/**
* Run the phploc tool
*
* @param bool $report - if true, generates reports instead of direct output
*/
public function phploc($report = FALSE)
public function phploc($report = FALSE): void
{
// Command for generating reports
$report_cmd_parts = [
@ -190,7 +215,7 @@ class RoboFile extends Tasks {
/**
* Create temporary directories
*/
public function prepare()
public function prepare(): void
{
array_map([$this, '_mkdir'], $this->taskDirs);
}
@ -198,35 +223,17 @@ class RoboFile extends Tasks {
/**
* Lint php files and run unit tests
*/
public function test()
public function test(): void
{
$this->lint();
$this->_run(['phpunit']);
}
/**
* Watches for file updates, and automatically runs appropriate actions
*/
public function watch()
{
$this->taskWatch()
->monitor('composer.json', function() {
$this->taskComposerUpdate()->run();
})
->monitor('src', function () {
$this->taskExec('test')->run();
})
->monitor('tests', function () {
$this->taskExec('test')->run();
})
->run();
}
/**
* Create pdepend reports
*/
protected function dependencyReport()
protected function dependencyReport(): void
{
$cmd_parts = [
'vendor/bin/pdepend',
@ -243,7 +250,7 @@ class RoboFile extends Tasks {
*
* @return array
*/
protected function getAllSourceFiles()
protected function getAllSourceFiles(): array
{
$files = array_merge(
glob_recursive('build/*.php'),
@ -254,6 +261,10 @@ class RoboFile extends Tasks {
glob('*.php')
);
$files = array_filter($files, static function(string $value) {
return strpos($value, '__snapshots__') === FALSE;
});
sort($files);
return $files;
@ -264,7 +275,7 @@ class RoboFile extends Tasks {
*
* @param array $chunk
*/
protected function parallelLint(array $chunk)
protected function parallelLint(array $chunk): void
{
$task = $this->taskParallelExec()
->timeout(5)
@ -281,7 +292,7 @@ class RoboFile extends Tasks {
/**
* Generate copy paste detector report
*/
protected function phpcpdReport()
protected function phpcpdReport(): void
{
$cmd_parts = [
'vendor/bin/phpcpd',
@ -298,7 +309,7 @@ class RoboFile extends Tasks {
* @param array $cmd_parts - command arguments
* @param string $join_on - what to join the command arguments with
*/
protected function _run(array $cmd_parts, $join_on = ' ')
protected function _run(array $cmd_parts, $join_on = ' '): void
{
$this->taskExec(implode($join_on, $cmd_parts))->run();
}

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
@ -44,10 +44,13 @@ return static function ($configArray = []) {
$appLogger = new Logger('animeclient');
$appLogger->pushHandler(new RotatingFileHandler(__DIR__ . '/logs/app.log', Logger::NOTICE));
$anilistRequestLogger = new Logger('anilist-request');
$anilistRequestLogger->pushHandler(new RotatingFileHandler(__DIR__ . '/logs/anilist_request.log', Logger::NOTICE));
$kitsuRequestLogger = new Logger('kitsu-request');
$kitsuRequestLogger->pushHandler(new RotatingFileHandler(__DIR__ . '/logs/kitsu_request.log', Logger::NOTICE));
$container->setLogger($appLogger);
$container->setLogger($anilistRequestLogger, 'anilist-request');
$container->setLogger($kitsuRequestLogger, 'kitsu-request');
@ -62,7 +65,7 @@ return static function ($configArray = []) {
});
// Create Cache Object
$container->set('cache', static function($container) {
$container->set('cache', static function($container): Pool {
$logger = $container->getLogger();
$config = $container->get('config')->get('cache');
return new Pool($config, $logger);
@ -117,12 +120,12 @@ return static function ($configArray = []) {
});
// Miscellaneous helper methods
$container->set('util', static function($container) {
$container->set('util', static function($container): Util {
return new Util($container);
});
// Models
$container->set('kitsu-model', static function($container) {
$container->set('kitsu-model', static function($container): Kitsu\Model {
$requestBuilder = new KitsuRequestBuilder();
$requestBuilder->setLogger($container->getLogger('kitsu-request'));
@ -138,7 +141,7 @@ return static function ($configArray = []) {
$model->setCache($cache);
return $model;
});
$container->set('anilist-model', static function($container) {
$container->set('anilist-model', static function($container): Anilist\Model {
$requestBuilder = new Anilist\AnilistRequestBuilder();
$requestBuilder->setLogger($container->getLogger('anilist-request'));
@ -153,9 +156,6 @@ return static function ($configArray = []) {
return $model;
});
$container->set('api-model', static function($container) {
return new Model\API($container);
});
$container->set('anime-model', static function($container) {
return new Model\Anime($container);
});

View File

@ -9,7 +9,7 @@
<?= $helper->picture("images/anime/{$item['anime']['id']}.webp") ?>
<div class="name">
<a href="<?= $url->generate('anime.details', ['id' => $item['anime']['slug']]); ?>">
<a href="<?= $url->generate('anime.details', ['id' => $item['anime']['slug']]) ?>">
<span class="canonical"><?= $item['anime']['title'] ?></span>
<?php foreach ($item['anime']['titles'] as $title): ?>
<br/>

View File

@ -1,5 +1,8 @@
<?php
$setupErrors = \Aviat\AnimeClient\checkFolderPermissions($container->get('config'));
<?php declare(strict_types=1);
use function Aviat\AnimeClient\checkFolderPermissions;
$setupErrors = checkFolderPermissions($container->get('config'));
?>
<?php if ( ! empty($setupErrors)): ?>

View File

@ -93,12 +93,12 @@ class InlineCommentSniff implements Sniff
private function _checkCommentStyle(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
if ($tokens[$stackPtr]['content']{0} === '#') {
if ($tokens[$stackPtr]['content'][0] === '#') {
$error = 'Perl-style comments are not allowed; use "// Comment" or DocBlock comments instead';
$phpcsFile->addError($error, $stackPtr, 'WrongStyle');
return FALSE;
} else if (substr($tokens[$stackPtr]['content'], 0, 2) === '/*'
|| $tokens[$stackPtr]['content']{0} === '*'
|| $tokens[$stackPtr]['content'][0] === '*'
) {
$error = 'Multi lines comments are not allowed; use "// Comment" DocBlock comments instead';
$phpcsFile->addError($error, $stackPtr, 'WrongStyle');

View File

@ -1,81 +0,0 @@
<?php
/**
* CodeIgniter_Sniffs_Operators_LogicalOperatorAndSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Thomas Ernest <thomas.ernest@baobaz.com>
* @copyright 2006 Thomas Ernest
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
/**
* CodeIgniter_Sniffs_Operators_LogicalOperatorAndSniff.
*
* Ensures that the logical operator 'AND' is in upper case and suggest the use of its symbolic equivalent.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Thomas Ernest <thomas.ernest@baobaz.com>
* @copyright 2006 Thomas Ernest
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
namespace CodeIgniter\Sniffs\Operators;
use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;
class LogicalOperatorAndSniff implements Sniff
{
/**
* Returns an array of tokens this test wants to listen for: symbolic and literal operators and.
*
* @return array
*/
public function register()
{
return array(
T_LOGICAL_AND,
);
}//end register()
/**
* Processes this test, when one of its tokens is encountered.
*
* @param File $phpcsFile The current file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$operator_token = $tokens[$stackPtr];
$operator_string = $operator_token['content'];
$operator_code = $operator_token['code'];
if ($operator_string !== strtoupper($operator_string)) {
$error_message = 'Logical operator should be in upper case;'
. ' use "' . strtoupper($operator_string)
. '" instead of "' . $operator_string . '"';
$phpcsFile->addError($error_message, $stackPtr, 'LowercaseLogicalOperator');
}
$warning_message = 'The symbolic form "&&" is preferred over the literal form "AND"';
$phpcsFile->addWarning($warning_message, $stackPtr, 'UseOfLiteralAndOperator');
}//end process()
}//end class
?>

View File

@ -1,84 +0,0 @@
<?php
/**
* CodeIgniter_Sniffs_Operators_UppercaseLogicalOperatorOrSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Thomas Ernest <thomas.ernest@baobaz.com>
* @copyright 2006 Thomas Ernest
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
/**
* CodeIgniter_Sniffs_Operators_UppercaseLogicalOperatorOrSniff.
*
* Ensures that the logical operator 'OR' is in upper cases and its symbolic equivalent.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Thomas Ernest <thomas.ernest@baobaz.com>
* @copyright 2006 Thomas Ernest
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
namespace CodeIgniter\Sniffs\Operators;
use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;
class UppercaseLogicalOperatorOrSniff implements Sniff
{
/**
* Returns an array of tokens this test wants to listen for: literal and symbolic operators or.
*
* @return array
*/
public function register()
{
return array(
T_BOOLEAN_OR,
T_LOGICAL_OR,
);
}//end register()
/**
* Processes this test, when one of its tokens is encountered.
*
* @param File $phpcsFile The current file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$operator_token = $tokens[$stackPtr];
$operator_string = $operator_token['content'];
$operator_code = $operator_token['code'];
if ($operator_code == T_BOOLEAN_OR) {
$error_message = 'Logical operator "' . $operator_string
. '" is prohibited; use "OR" instead';
$phpcsFile->addError($error_message, $stackPtr, 'UseOf||InsteadOfOR');
}
// it is literal, if it is not symbolic
else if ($operator_string !== strtoupper($operator_string)) {
$error_message = 'Logical operator should be in upper case;'
. ' use "' . strtoupper($operator_string)
. '" instead of "' . $operator_string . '"';
$phpcsFile->addError($error_message, $stackPtr, 'UseOfLowercaseOr');
}
}//end process()
}//end class
?>

View File

@ -23,7 +23,7 @@
<!-- Classes and functions should be commented -->
<rule ref="PEAR.Commenting.ClassComment"/>
<rule ref="PEAR.Commenting.FunctionComment"/>
<rule ref="Squiz.Commenting.FunctionCommentThrowTag"/>
<!-- <rule ref="Squiz.Commenting.FunctionCommentThrowTag"/>-->
<!-- Use warnings for docblock comments for files and variables, since nothing is cleary explained -->
<rule ref="PEAR.Commenting.FileComment">
<properties>

View File

@ -1,12 +0,0 @@
#!/bin/bash
# We need to install dependencies only for Docker
[[ ! -e /.dockerenv ]] && [[ ! -e /.dockerinit ]] && exit 0
set -xe
# Install git (the php image doesn't have it) which is required by composer
# echo -e 'http://dl-cdn.alpinelinux.org/alpine/edge/main\nhttp://dl-cdn.alpinelinux.org/alpine/edge/community\nhttp://dl-cdn.alpinelinux.org/alpine/edge/testing' > /etc/apk/repositories
apk --update add --no-cache \
curl \
git

View File

@ -3,13 +3,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/

View File

@ -18,9 +18,6 @@
<logging>
<log type="coverage-html" target="../coverage"/>
<log type="coverage-clover" target="logs/clover.xml"/>
<log type="coverage-crap4j" target="logs/crap4j.xml"/>
<log type="coverage-xml" target="logs/coverage" />
<log type="junit" target="logs/junit.xml" />
</logging>
<php>
<server name="HTTP_USER_AGENT" value="Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Firefox/38.0" />

View File

@ -29,13 +29,13 @@ if ( ! function_exists('glob_recursive'))
}
}
function get_text_to_replace($tokens)
function get_text_to_replace(array $tokens): string
{
$output = '';
// Tokens have the follow structure if arrays:
// [0] => token type constant
// [1] => raw sytax parsed to that token
// [1] => raw syntax parsed to that token
// [2] => line number
foreach($tokens as $token)
{
@ -57,7 +57,7 @@ function get_text_to_replace($tokens)
return $output;
}
function get_tokens($source)
function get_tokens($source): array
{
return token_get_all($source);
}

View File

@ -2,54 +2,74 @@
"name": "aviat/hummingbird-anime-client",
"description": "A self-hosted anime/manga client for Kitsu.",
"license": "MIT",
"authors": [
{
"name": "Timothy J. Warren",
"email": "tim@timshomepage.net",
"homepage": "https://timshomepage.net",
"role": "Developer"
}
],
"autoload": {
"files": [
"src/constants.php",
"src/AnimeClient.php"
"src/Ion/functions.php",
"src/AnimeClient/constants.php",
"src/AnimeClient/AnimeClient.php"
],
"psr-4": {
"Aviat\\AnimeClient\\": "src/"
"Aviat\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Aviat\\AnimeClient\\Tests\\": "tests/",
"Aviat\\AnimeClient\\Tests\\": "tests/AnimeClient",
"Aviat\\Ion\\Tests\\": "tests/Ion",
"CodeIgniter\\": "build/CodeIgniter/"
}
},
"config": {
"lock": false,
"platform": {
"php": "7.3"
}
},
"require": {
"amphp/artax": "^3.0",
"amphp/http-client": "^4.2",
"aura/html": "^2.0",
"aura/router": "^3.0",
"aura/session": "^2.0",
"aviat/banker": "^2.0.0",
"aviat/ion": "^2.4.1",
"aviat/query": "^2.5.1",
"danielstjules/stringy": "^3.1.0",
"ext-dom": "*",
"ext-iconv": "*",
"ext-json": "*",
"ext-gd":"*",
"ext-gd": "*",
"ext-pdo": "*",
"laminas/laminas-diactoros": "^2.0.0",
"laminas/laminas-httphandlerrunner": "^1.0",
"maximebf/consolekit": "^1.0",
"monolog/monolog": "^1.0",
"monolog/monolog": "^2.0.1",
"php": "^7.3",
"psr/container": "~1.0",
"psr/http-message": "~1.0",
"psr/log": "~1.0",
"yosymfony/toml": "^1.0",
"zendframework/zend-diactoros": "^2.0.0"
"yosymfony/toml": "^1.0"
},
"require-dev": {
"consolidation/robo": "~1.0",
"consolidation/robo": "^2.0.0",
"filp/whoops": "^2.1",
"henrikbjorn/lurker": "^1.1.0",
"pdepend/pdepend": "^2.2",
"phploc/phploc": "^4.0",
"phpmd/phpmd": "^2.4",
"phpstan/phpstan": "^0.10.5",
"phpunit/phpunit": "^7.4.3",
"phploc/phploc": "^5.0",
"phpmd/phpmd": "^2.8",
"phpstan/phpstan": "^0.12.0",
"phpunit/phpunit": "^8.4.3",
"roave/security-advisories": "dev-master",
"robmorgan/phinx": "^0.10.6",
"sebastian/phpcpd": "^4.1.0",
"spatie/phpunit-snapshot-assertions": "^1.2.0",
"spatie/phpunit-snapshot-assertions": "^2.2.1",
"squizlabs/php_codesniffer": "^3.2.2",
"symfony/var-dumper": "^4.0.1",
"symfony/var-dumper": "^5",
"theseer/phpdox": "*"
},
"scripts": {
@ -58,10 +78,11 @@
"build:js": "cd public && npm run build:js && cd ..",
"clean": "vendor/bin/robo clean",
"coverage": "phpdbg -qrr -- vendor/bin/phpunit -c build",
"phpstan": "phpstan analyse -l 4 -c phpstan.neon src tests ./console index.php",
"phpstan": "phpstan analyse -c phpstan.neon",
"watch:css": "cd public && npm run watch:css",
"watch:js": "cd public && npm run watch:js",
"test": "vendor/bin/phpunit"
"test": "vendor/bin/phpunit -c build --no-coverage",
"test-update": "vendor/bin/phpunit -c build --no-coverage -d --update-snapshots"
},
"scripts-descriptions": {
"build": "Generate the api docs",

View File

@ -4,19 +4,21 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
namespace Aviat\AnimeClient;
use Aviat\AnimeClient\Types\Config as ConfigType;
use Whoops\Handler\PrettyPageHandler;
use Whoops\Run;
use function Aviat\Ion\_dir;
@ -34,8 +36,8 @@ require_once __DIR__ . '/vendor/autoload.php';
// if (array_key_exists('ENV', $_ENV) && $_ENV['ENV'] === 'development')
{
$whoops = new \Whoops\Run;
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);
$whoops = new Run;
$whoops->pushHandler(new PrettyPageHandler);
$whoops->register();
}

View File

@ -78,10 +78,10 @@
</source>
<!-- git vcs information -->
<source type="git">
<!-- <source type="git">
<git binary="/usr/bin/git" />
<history enabled="true" limit="15" cache="${phpDox.project.workdir}/gitlog.xml" />
</source>
</source> -->
<!-- PHP Code Sniffer findings -->
<source type="checkstyle">
@ -89,24 +89,18 @@
</source>
<!-- PHPMessDetector -->
<!--
<source type="pmd">
<file name="pmd.xml" />
<file name="phpmd.xml" />
</source>
-->
<!-- PHPUnit Coverage XML -->
<source type="phpunit">
<coverage path="coverage/clover.xml" />
<!-- <source type="phpunit"> -->
<!-- <coverage path="coverage" /> -->
<!-- <coverage path="clover.xml" />-->
<!-- @path - the directory where the xml code coverage report can be found -->
<!--<filter directory="${phpDox.project.source}" />-->
<!-- @directory - path of the phpunit config whitelist filter directory -->
</source>
<source type="phpunit">
<filter directory="${phpDox.project.source}" />
</source>
<!-- </source> -->
</enrich>
<!-- <build engine="..." enabled="true" output="..." /> -->

View File

@ -1,9 +1,18 @@
parameters:
checkGenericClassInNonGenericObjectType: false
checkMissingIterableValueType: false
inferPrivatePropertyTypeFromConstructor: true
level: 7
autoload_files:
- %rootDir%/../../../tests/mocks.php
paths:
- src
- ./console
- index.php
ignoreErrors:
- '#Access to an undefined property Aviat\\\Ion\\\Friend::\$[a-zA-Z0-9_]+#'
- '#Call to an undefined method Aviat\\\Ion\\\Friend::[a-zA-Z0-9_]+\(\)#'
- '#Call to an undefined method Aura\\\Html\\\HelperLocator::[a-zA-Z0-9_]+\(\)#'
- '#Undefined variable: \$var#'
- '#Property Amp\\Artax\\Internal\\RequestCycle::\$[a-zA-Z0-9_]+#'
excludes_analyse:
- tests/mocks.php

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
@ -22,15 +22,16 @@ use function Amp\Promise\wait;
use function Aviat\AnimeClient\getResponse;
use Amp;
use Amp\Artax\{FormBody, Request};
use Amp\Http\Client\Request;
use Amp\Http\Client\Body\FormBody;
use Aviat\Ion\Json;
use InvalidArgumentException;
use Psr\Log\LoggerAwareTrait;
/**
* Wrapper around Artax to make it easier to build API requests
* Wrapper around Http\Client to make it easier to build API requests
*/
class APIRequestBuilder {
abstract class APIRequestBuilder {
use LoggerAwareTrait;
/**
@ -65,7 +66,7 @@ class APIRequestBuilder {
/**
* The current request
* @var \Amp\Artax\Request
* @var Request
*/
protected $request;
@ -78,7 +79,7 @@ class APIRequestBuilder {
public static function simpleRequest(string $uri): Request
{
return (new Request($uri))
->withHeader('User-Agent', USER_AGENT);
->setHeader('User-Agent', USER_AGENT);
}
/**
@ -118,7 +119,7 @@ class APIRequestBuilder {
*/
public function setBody($body): self
{
$this->request = $this->request->withBody($body);
$this->request->setBody($body);
return $this;
}
@ -145,7 +146,7 @@ class APIRequestBuilder {
*/
public function unsetHeader(string $name): self
{
$this->request = $this->request->withoutHeader($name);
$this->request->removeHeader($name);
return $this;
}
@ -164,7 +165,7 @@ class APIRequestBuilder {
}
else
{
$this->request = $this->request->withHeader($name, $value);
$this->request->setHeader($name, $value);
}
return $this;
@ -219,14 +220,14 @@ class APIRequestBuilder {
/**
* Return the promise for the current request
*
* @return Request
* @throws \Throwable
* @return \Amp\Artax\Request
*/
public function getFullRequest(): Request
{
$this->buildUri();
if ($this->logger)
if ($this->logger !== NULL)
{
$this->logger->debug('API Request', [
'request_url' => $this->request->getUri(),
@ -254,7 +255,7 @@ class APIRequestBuilder {
public function getResponseData(Request $request)
{
$response = getResponse($request);
return wait($response->getBody());
return wait($response->getBody()->buffer());
}
/**
@ -306,7 +307,7 @@ class APIRequestBuilder {
$url .= '?' . $this->query;
}
$this->request = $this->request->withUri($url);
$this->request->setUri($url);
return $this->request;
}
@ -324,7 +325,8 @@ class APIRequestBuilder {
$this->path = '';
$this->query = '';
$this->request = (new Request($requestUrl))
->withMethod($type);
$this->request = new Request($requestUrl, $type);
$this->request->setTcpConnectTimeout(300000);
$this->request->setTransferTimeout(300000);
}
}

View File

@ -4,25 +4,25 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
namespace Aviat\AnimeClient\API;
use Amp\Artax\Request;
use Amp\Http\Client\Request;
use Aviat\AnimeClient\Types\FormItemData;
/**
* Common interface for anime and manga list item CRUD
*/
interface ListItemInterface {
abstract class AbstractListItem {
/**
* Create a list item
@ -30,7 +30,7 @@ interface ListItemInterface {
* @param array $data -
* @return Request
*/
public function create(array $data): Request;
abstract public function create(array $data): Request;
/**
* Retrieve a list item
@ -38,7 +38,7 @@ interface ListItemInterface {
* @param string $id - The id of the list item
* @return array
*/
public function get(string $id): array;
abstract public function get(string $id): array;
/**
* Increase progress on a list item
@ -47,7 +47,7 @@ interface ListItemInterface {
* @param FormItemData $data
* @return Request
*/
public function increment(string $id, FormItemData $data): Request;
abstract public function increment(string $id, FormItemData $data): Request;
/**
* Update a list item
@ -56,7 +56,7 @@ interface ListItemInterface {
* @param FormItemData $data - The data with which to update the list item
* @return Request
*/
public function update(string $id, FormItemData $data): Request;
abstract public function update(string $id, FormItemData $data): Request;
/**
* Delete a list item
@ -64,5 +64,5 @@ interface ListItemInterface {
* @param string $id - The id of the list item to delete
* @return Request
*/
public function delete(string $id): Request;
abstract public function delete(string $id):?Request;
}

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
@ -21,13 +21,16 @@ use const Aviat\AnimeClient\USER_AGENT;
use function Amp\Promise\wait;
use function Aviat\AnimeClient\getResponse;
use Amp\Artax\Request;
use Amp\Artax\Response;
use Amp\Http\Client\Request;
use Amp\Http\Client\Response;
use Aviat\AnimeClient\API\Anilist;
use Aviat\Ion\Json;
use Aviat\Ion\Di\ContainerAware;
use LogicException;
use Throwable;
trait AnilistTrait {
use ContainerAware;
@ -69,10 +72,10 @@ trait AnilistTrait {
/**
* Create a request object
* @param string $url
* @param array $options
* @return Request
* @throws Throwable
*/
public function setUpRequest(string $url, array $options = []): Request
{
@ -123,7 +126,7 @@ trait AnilistTrait {
$file = realpath(__DIR__ . "/GraphQL/Queries/{$name}.graphql");
if ( ! file_exists($file))
{
throw new \LogicException('GraphQL query file does not exist.');
throw new LogicException('GraphQL query file does not exist.');
}
// $query = str_replace(["\t", "\n"], ' ', file_get_contents($file));
@ -146,12 +149,18 @@ trait AnilistTrait {
]);
}
/**
* @param string $name
* @param array $variables
* @return Request
* @throws Throwable
*/
public function mutateRequest (string $name, array $variables = []): Request
{
$file = realpath(__DIR__ . "/GraphQL/Mutations/{$name}.graphql");
if (!file_exists($file))
{
throw new \LogicException('GraphQL mutation file does not exist.');
throw new LogicException('GraphQL mutation file does not exist.');
}
// $query = str_replace(["\t", "\n"], ' ', file_get_contents($file));
@ -174,12 +183,18 @@ trait AnilistTrait {
]);
}
/**
* @param string $name
* @param array $variables
* @return array
* @throws Throwable
*/
public function mutate (string $name, array $variables = []): array
{
$request = $this->mutateRequest($name, $variables);
$response = $this->getResponseFromRequest($request);
return Json::decode(wait($response->getBody()));
return Json::decode(wait($response->getBody()->buffer()));
}
/**
@ -188,6 +203,7 @@ trait AnilistTrait {
* @param string $url
* @param array $options
* @return Response
* @throws Throwable
*/
private function getResponse(string $url, array $options = []): Response
{
@ -211,6 +227,11 @@ trait AnilistTrait {
return $response;
}
/**
* @param Request $request
* @return Response
* @throws Throwable
*/
private function getResponseFromRequest(Request $request): Response
{
$logger = NULL;
@ -237,6 +258,7 @@ trait AnilistTrait {
*
* @param array $options
* @return array
* @throws Throwable
*/
protected function postRequest(array $options = []): array
{
@ -258,14 +280,14 @@ trait AnilistTrait {
if ( ! \in_array($response->getStatus(), $validResponseCodes, TRUE))
{
if ($logger)
if ($logger !== NULL)
{
$logger->warning('Non 200 response for POST api call', (array)$response->getBody());
}
}
// dump(wait($response->getBody()));
// dump(wait($response->getBody()->buffer()));
return Json::decode(wait($response->getBody()));
return Json::decode(wait($response->getBody()->buffer()));
}
}

View File

@ -4,21 +4,21 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
namespace Aviat\AnimeClient\API\Anilist;
use Amp\Artax\Request;
use Amp\Http\Client\Request;
use Aviat\AnimeClient\API\ListItemInterface;
use Aviat\AnimeClient\API\AbstractListItem;
use Aviat\AnimeClient\API\Enum\AnimeWatchingStatus\Anilist as AnilistStatus;
use Aviat\AnimeClient\API\Mapping\AnimeWatchingStatus;
use Aviat\AnimeClient\Types\FormItemData;
@ -26,7 +26,7 @@ use Aviat\AnimeClient\Types\FormItemData;
/**
* CRUD operations for MAL list items
*/
final class ListItem implements ListItemInterface{
final class ListItem extends AbstractListItem {
use AnilistTrait;
/**
@ -37,7 +37,8 @@ final class ListItem implements ListItemInterface{
*/
public function create(array $data): Request
{
return $this->mutateRequest('CreateMediaListEntry', $data);
$checkedData = (new Types\MediaListEntry($data))->toArray();
return $this->mutateRequest('CreateMediaListEntry', $checkedData);
}
/**
@ -48,7 +49,8 @@ final class ListItem implements ListItemInterface{
*/
public function createFull(array $data): Request
{
return $this->mutateRequest('CreateFullMediaListEntry', $data);
$checkedData = (new Types\MediaListEntry($data))->toArray();
return $this->mutateRequest('CreateFullMediaListEntry', $checkedData);
}
/**
@ -83,10 +85,12 @@ final class ListItem implements ListItemInterface{
*/
public function increment(string $id, FormItemData $data): Request
{
return $this->mutateRequest('IncrementMediaListEntry', [
$checkedData = (new Types\MediaListEntry([
'id' => $id,
'progress' => $data['progress'],
]);
'progress' => $data->progress,
]))->toArray();
return $this->mutateRequest('IncrementMediaListEntry', $checkedData);
}
/**
@ -98,15 +102,15 @@ final class ListItem implements ListItemInterface{
*/
public function update(string $id, FormItemData $data): Request
{
$array = $data->toArray();
$notes = $data->notes ?? '';
$progress = (int)$data->progress;
$private = (bool)$data->private;
$rating = $data->ratingTwenty;
$status = ($data->reconsuming === TRUE)
? AnilistStatus::REPEATING
: AnimeWatchingStatus::KITSU_TO_ANILIST[$data->status];
$notes = $data['notes'] ?? '';
$progress = array_key_exists('progress', $array) ? $data['progress'] : 0;
$private = array_key_exists('private', $array) ? (bool)$data['private'] : false;
$rating = array_key_exists('ratingTwenty', $array) ? $data['ratingTwenty'] : NULL;
$status = ($data['reconsuming'] === true) ? AnilistStatus::REPEATING : AnimeWatchingStatus::KITSU_TO_ANILIST[$data['status']];
$updateData = [
$updateData = (new Types\MediaListEntry([
'id' => (int)$id,
'status' => $status,
'score' => $rating * 5,
@ -114,7 +118,7 @@ final class ListItem implements ListItemInterface{
'repeat' => (int)$data['reconsumeCount'],
'private' => $private,
'notes' => $notes,
];
]))->toArray();
return $this->mutateRequest('UpdateMediaListEntry', $updateData);
}

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
@ -20,11 +20,15 @@ use function Amp\Promise\wait;
use InvalidArgumentException;
use Amp\Artax\Request;
use Amp\Http\Client\Request;
use Aviat\AnimeClient\API\Anilist;
use Aviat\AnimeClient\API\Mapping\{AnimeWatchingStatus, MangaReadingStatus};
use Aviat\AnimeClient\Types\FormItem;
use Aviat\Ion\Json;
use Aviat\Ion\Di\Exception\ContainerException;
use Aviat\Ion\Di\Exception\NotFoundException;
use Throwable;
/**
* Anilist API Model
@ -57,6 +61,7 @@ final class Model
* @param string $code - The request token
* @param string $redirectUri - The oauth callback url
* @return array
* @throws Throwable
*/
public function authenticate(string $code, string $redirectUri): array
{
@ -74,7 +79,7 @@ final class Model
$response = $this->getResponseFromRequest($request);
return Json::decode(wait($response->getBody()));
return Json::decode(wait($response->getBody()->buffer()));
}
/**
@ -92,8 +97,8 @@ final class Model
*
* @param string $type
* @return array
* @throws \Aviat\Ion\Di\Exception\ContainerException
* @throws \Aviat\Ion\Di\Exception\NotFoundException
* @throws ContainerException
* @throws NotFoundException
*/
public function getSyncList(string $type = 'anime'): array
{
@ -118,16 +123,21 @@ final class Model
* @param string $type
* @return Request
*/
public function createListItem(array $data, string $type = 'anime'): Request
public function createListItem(array $data, string $type = 'anime'): ?Request
{
$createData = [];
if ($data['mal_id'] === NULL)
{
return NULL;
}
$mediaId = $this->getMediaIdFromMalId($data['mal_id'], mb_strtoupper($type));
/* if (empty($mediaId))
if ($mediaId === NULL)
{
throw new InvalidArgumentException('Media id missing');
} */
return NULL;
}
$createData = [];
if ($type === 'ANIME')
{
@ -144,7 +154,7 @@ final class Model
];
}
return $this->listItem->create($createData, $type);
return $this->listItem->create($createData);
}
/**
@ -174,7 +184,8 @@ final class Model
*
* @param string $malId - The unique identifier of that list item
* @param string $type - Them media type (anime/manga)
* @return mixed
*
* @return array
*/
public function getListItem(string $malId, string $type): array
{
@ -194,9 +205,13 @@ final class Model
* @param string $type - Them media type (anime/manga)
* @return Request
*/
public function incrementListItem(FormItem $data, string $type): Request
public function incrementListItem(FormItem $data, string $type): ?Request
{
$id = $this->getListIdFromMalId($data['mal_id'], $type);
if ($id === NULL)
{
return NULL;
}
return $this->listItem->increment($id, $data['data']);
}
@ -208,10 +223,15 @@ final class Model
* @param string $type - Them media type (anime/manga)
* @return Request
*/
public function updateListItem(FormItem $data, string $type): Request
public function updateListItem(FormItem $data, string $type): ?Request
{
$id = $this->getListIdFromMalId($data['mal_id'], mb_strtoupper($type));
if ($id === NULL)
{
return NULL;
}
return $this->listItem->update($id, $data['data']);
}
@ -222,11 +242,15 @@ final class Model
* @param string $type - Them media type (anime/manga)
* @return Request
*/
public function deleteListItem(string $malId, string $type): Request
public function deleteListItem(string $malId, string $type): ?Request
{
$item_id = $this->getListIdFromMalId($malId, $type);
$id = $this->getListIdFromMalId($malId, $type);
if ($id === NULL)
{
return NULL;
}
return $this->listItem->delete($item_id);
return $this->listItem->delete($id);
}
/**
@ -239,6 +263,11 @@ final class Model
public function getListIdFromMalId(string $malId, string $type): ?string
{
$mediaId = $this->getMediaIdFromMalId($malId, $type);
if ($mediaId === NULL)
{
return NULL;
}
return $this->getListIdFromMediaId($mediaId);
}

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/

View File

@ -0,0 +1,56 @@
<?php declare(strict_types=1);
/**
* Hummingbird Anime List Client
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
namespace Aviat\AnimeClient\API\Anilist\Types;
use Aviat\AnimeClient\Types\AbstractType;
class MediaListEntry extends AbstractType {
/**
* @var int
*/
public $id;
/**
* @var string
*/
public $notes;
/**
* @var bool
*/
public $private;
/**
* @var int
*/
public $progress;
/**
* @var int
*/
public $repeat;
/**
* @var string
*/
public $status;
/**
* @var int
*/
public $score;
}

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
@ -144,6 +144,8 @@ final class JsonAPI {
}
}
unset($item);
$data['data']['included'] = $included;
return $data['data'];
@ -193,6 +195,7 @@ final class JsonAPI {
$organized[$type][$id] = $newItem;
}
unset($item);
// Second pass, go through and fill missing relationships in the first pass
foreach($organized as $type => $items)

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/

View File

@ -4,18 +4,21 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
namespace Aviat\AnimeClient\API\Kitsu;
use Aura\Session\Segment;
use Aviat\Banker\Exception\InvalidArgumentException;
use const Aviat\AnimeClient\SESSION_SEGMENT;
use Aviat\AnimeClient\API\{
@ -23,7 +26,9 @@ use Aviat\AnimeClient\API\{
Kitsu as K
};
use Aviat\Ion\Di\{ContainerAware, ContainerInterface};
use Exception;
use Aviat\Ion\Di\Exception\{ContainerException, NotFoundException};
use Throwable;
/**
* Kitsu API Authentication
@ -42,7 +47,7 @@ final class Auth {
/**
* Session object
*
* @var \Aura\Session\Segment
* @var Segment
*/
private $segment;
@ -50,6 +55,8 @@ final class Auth {
* Constructor
*
* @param ContainerInterface $container
* @throws ContainerException
* @throws NotFoundException
*/
public function __construct(ContainerInterface $container)
{
@ -66,6 +73,8 @@ final class Auth {
*
* @param string $password
* @return boolean
* @throws InvalidArgumentException
* @throws Throwable
*/
public function authenticate(string $password): bool
{
@ -109,6 +118,8 @@ final class Auth {
*
* @param string $token
* @return boolean
* @throws InvalidArgumentException
* @throws Throwable
*/
public function reAuthenticate(string $token): bool
{

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
@ -21,8 +21,8 @@ use const Aviat\AnimeClient\SESSION_SEGMENT;
use function Amp\Promise\wait;
use function Aviat\AnimeClient\getResponse;
use Amp\Artax\Request;
use Amp\Artax\Response;
use Amp\Http\Client\Request;
use Amp\Http\Client\Response;
use Aviat\AnimeClient\API\{
FailedResponseException,
Kitsu as K
@ -30,6 +30,8 @@ use Aviat\AnimeClient\API\{
use Aviat\Ion\Json;
use Aviat\Ion\JsonException;
use Throwable;
trait KitsuTrait {
/**
@ -56,7 +58,7 @@ trait KitsuTrait {
* @param string $type
* @param string $url
* @param array $options
* @return \Amp\Artax\Request
* @return Request
*/
public function setUpRequest(string $type, string $url, array $options = []): Request
{
@ -120,6 +122,7 @@ trait KitsuTrait {
* @param string $url
* @param array $options
* @return Response
* @throws Throwable
*/
private function getResponse(string $type, string $url, array $options = []): Response
{
@ -151,8 +154,9 @@ trait KitsuTrait {
* @param string $type
* @param string $url
* @param array $options
* @throws \Aviat\Ion\JsonException
* @throws JsonException
* @throws FailedResponseException
* @throws Throwable
* @return array
*/
private function request(string $type, string $url, array $options = []): array
@ -165,7 +169,7 @@ trait KitsuTrait {
$response = $this->getResponse($type, $url, $options);
if ((int) $response->getStatus() > 299 OR (int) $response->getStatus() < 200)
if ((int) $response->getStatus() > 299 || (int) $response->getStatus() < 200)
{
if ($logger)
{
@ -177,7 +181,7 @@ trait KitsuTrait {
try
{
return Json::decode(wait($response->getBody()));
return Json::decode(wait($response->getBody()->buffer()));
}
catch (JsonException $e)
{
@ -191,6 +195,7 @@ trait KitsuTrait {
* Remove some boilerplate for get requests
*
* @param mixed ...$args
* @throws Throwable
* @return array
*/
protected function getRequest(...$args): array
@ -202,6 +207,7 @@ trait KitsuTrait {
* Remove some boilerplate for patch requests
*
* @param mixed ...$args
* @throws Throwable
* @return array
*/
protected function patchRequest(...$args): array
@ -213,6 +219,7 @@ trait KitsuTrait {
* Remove some boilerplate for post requests
*
* @param mixed ...$args
* @throws Throwable
* @return array
*/
protected function postRequest(...$args): array
@ -234,13 +241,14 @@ trait KitsuTrait {
}
}
return JSON::decode(wait($response->getBody()), TRUE);
return JSON::decode(wait($response->getBody()->buffer()), TRUE);
}
/**
* Remove some boilerplate for delete requests
*
* @param mixed ...$args
* @throws Throwable
* @return bool
*/
protected function deleteRequest(...$args): bool

View File

@ -4,36 +4,45 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
namespace Aviat\AnimeClient\API\Kitsu;
use Aviat\Ion\Di\Exception\ContainerException;
use Aviat\Ion\Di\Exception\NotFoundException;
use const Aviat\AnimeClient\SESSION_SEGMENT;
use function Amp\Promise\wait;
use function Aviat\AnimeClient\getResponse;
use Amp\Artax\Request;
use Aviat\AnimeClient\API\ListItemInterface;
use Amp\Http\Client\Request;
use Aviat\AnimeClient\API\AbstractListItem;
use Aviat\AnimeClient\Types\FormItemData;
use Aviat\Ion\Di\ContainerAware;
use Aviat\Ion\Json;
use Throwable;
/**
* CRUD operations for Kitsu list items
*/
final class ListItem implements ListItemInterface {
final class ListItem extends AbstractListItem {
use ContainerAware;
use KitsuTrait;
/**
* @param array $data
* @return Request
* @throws Throwable
*/
public function create(array $data): Request
{
$body = [
@ -78,6 +87,11 @@ final class ListItem implements ListItemInterface {
->getFullRequest();
}
/**
* @param string $id
* @return Request
* @throws Throwable
*/
public function delete(string $id): Request
{
$authHeader = $this->getAuthHeader();
@ -91,6 +105,11 @@ final class ListItem implements ListItemInterface {
return $request->getFullRequest();
}
/**
* @param string $id
* @return array
* @throws Throwable
*/
public function get(string $id): array
{
$authHeader = $this->getAuthHeader();
@ -107,7 +126,7 @@ final class ListItem implements ListItemInterface {
$request = $request->getFullRequest();
$response = getResponse($request);
return Json::decode(wait($response->getBody()));
return Json::decode(wait($response->getBody()->buffer()));
}
public function increment(string $id, FormItemData $data): Request
@ -115,6 +134,12 @@ final class ListItem implements ListItemInterface {
return $this->update($id, $data);
}
/**
* @param string $id
* @param FormItemData $data
* @return Request
* @throws Throwable
*/
public function update(string $id, FormItemData $data): Request
{
$authHeader = $this->getAuthHeader();
@ -137,6 +162,11 @@ final class ListItem implements ListItemInterface {
return $request->getFullRequest();
}
/**
* @return bool|string
* @throws ContainerException
* @throws NotFoundException
*/
private function getAuthHeader()
{
$cache = $this->getContainer()->get('cache');

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
@ -18,7 +18,7 @@ namespace Aviat\AnimeClient\API\Kitsu;
use function Amp\Promise\wait;
use Amp\Artax\Request;
use Amp\Http\Client\Request;
use Aviat\AnimeClient\API\{
CacheTrait,
JsonAPI,
@ -41,8 +41,13 @@ use Aviat\AnimeClient\Types\{
FormItem,
MangaPage
};
use Aviat\Banker\Exception\InvalidArgumentException;
use Aviat\Ion\{Di\ContainerAware, Json};
use ReflectionException;
use Throwable;
/**
* Kitsu API Model
*/
@ -103,6 +108,7 @@ final class Model {
* @param string $username
* @param string $password
* @return bool|array
* @throws Throwable
*/
public function authenticate(string $username, string $password)
{
@ -120,7 +126,7 @@ final class Model {
'password' => $password
]
]);
$data = Json::decode(wait($response->getBody()));
$data = Json::decode(wait($response->getBody()->buffer()));
if (array_key_exists('error', $data))
{
@ -142,6 +148,7 @@ final class Model {
*
* @param string $token
* @return bool|array
* @throws Throwable
*/
public function reAuthenticate(string $token)
{
@ -156,7 +163,7 @@ final class Model {
]
]);
$data = Json::decode(wait($response->getBody()));
$data = Json::decode(wait($response->getBody()->buffer()));
if (array_key_exists('access_token', $data))
{
@ -171,6 +178,7 @@ final class Model {
*
* @param string $username
* @return string
* @throws InvalidArgumentException
*/
public function getUserIdByUsername(string $username = NULL): string
{
@ -206,7 +214,7 @@ final class Model {
*/
public function getCharacter(string $slug): array
{
$data = $this->getRequest('characters', [
return $this->getRequest('characters', [
'query' => [
'filter' => [
'slug' => $slug,
@ -218,8 +226,6 @@ final class Model {
'include' => 'castings.person,castings.media'
]
]);
return $data;
}
/**
@ -227,6 +233,7 @@ final class Model {
*
* @param string $id
* @return array
* @throws InvalidArgumentException
*/
public function getPerson(string $id): array
{
@ -265,8 +272,7 @@ final class Model {
*/
public function getUserData(string $username): array
{
// $userId = $this->getUserIdByUsername($username);
$data = $this->getRequest('users', [
return $this->getRequest('users', [
'query' => [
'filter' => [
'name' => $username,
@ -279,8 +285,6 @@ final class Model {
'include' => 'waifu,favorites.item,stats'
]
]);
return $data;
}
/**
@ -399,6 +403,7 @@ final class Model {
*
* @param string $status - The watching status to filter the list with
* @return array
* @throws InvalidArgumentException
*/
public function getAnimeList(string $status): array
{
@ -421,6 +426,7 @@ final class Model {
{
$item['included'] = $included;
}
unset($item);
$transformed = $this->animeListTransformer->transformCollection($data['data']);
$keyed = [];
@ -441,6 +447,7 @@ final class Model {
*
* @param string $status - Optional status to filter by
* @return int
* @throws InvalidArgumentException
*/
public function getAnimeListCount(string $status = '') : int
{
@ -472,6 +479,8 @@ final class Model {
*
* @param array $options
* @return array
* @throws InvalidArgumentException
* @throws Throwable
*/
public function getFullRawAnimeList(array $options = [
'include' => 'anime.mappings'
@ -507,6 +516,8 @@ final class Model {
* Get all the anime entries, that are organized for output to html
*
* @return array
* @throws ReflectionException
* @throws InvalidArgumentException
*/
public function getFullOrganizedAnimeList(): array
{
@ -564,6 +575,7 @@ final class Model {
* @param int $offset
* @param array $options
* @return Request
* @throws InvalidArgumentException
*/
public function getPagedAnimeList(int $limit, int $offset = 0, array $options = [
'include' => 'anime.mappings'
@ -590,6 +602,8 @@ final class Model {
*
* @param string $status - The watching status to filter the list with
* @return array
* @throws InvalidArgumentException
* @throws Throwable
*/
public function getRawAnimeList(string $status): array
{
@ -647,6 +661,7 @@ final class Model {
* @param int $limit - The number of list items to fetch per page
* @param int $offset - The page offset
* @return array
* @throws InvalidArgumentException
*/
public function getMangaList(string $status, int $limit = 200, int $offset = 0): array
{
@ -685,6 +700,7 @@ final class Model {
{
$item['included'] = $included;
}
unset($item);
$transformed = $this->mangaListTransformer->transformCollection($data['data']);
@ -700,6 +716,7 @@ final class Model {
*
* @param string $status - Optional status to filter by
* @return int
* @throws InvalidArgumentException
*/
public function getMangaListCount(string $status = '') : int
{
@ -731,6 +748,8 @@ final class Model {
*
* @param array $options
* @return array
* @throws InvalidArgumentException
* @throws Throwable
*/
public function getFullRawMangaList(array $options = [
'include' => 'manga.mappings'
@ -766,6 +785,8 @@ final class Model {
* Get all Manga lists
*
* @return array
* @throws ReflectionException
* @throws InvalidArgumentException
*/
public function getFullOrganizedMangaList(): array
{
@ -787,6 +808,7 @@ final class Model {
* @param int $offset
* @param array $options
* @return Request
* @throws InvalidArgumentException
*/
public function getPagedMangaList(int $limit, int $offset = 0, array $options = [
'include' => 'manga.mappings'
@ -845,10 +867,16 @@ final class Model {
*
* @param array $data
* @return Request
* @throws InvalidArgumentException
*/
public function createListItem(array $data): Request
public function createListItem(array $data): ?Request
{
$data['user_id'] = $this->getUserIdByUsername($this->getUsername());
if ($data['id'] === NULL)
{
return NULL;
}
return $this->listItem->create($data);
}

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
@ -100,7 +100,7 @@ final class AnimeListTransformer extends AbstractTransformer {
'title' => $title,
'titles' => $titles,
'slug' => $anime['slug'],
'show_type' => $this->string($anime['subtype'])->upperCaseFirst()->__toString(),
'show_type' => (string)$this->string($anime['subtype'])->upperCaseFirst(),
'cover_image' => $anime['posterImage']['small'],
'genres' => $genres,
'streaming_links' => $streamingLinks,

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
@ -89,14 +89,14 @@ final class AnimeTransformer extends AbstractTransformer {
if ( ! empty($characters['main']))
{
uasort($characters['main'], function ($a, $b) {
uasort($characters['main'], static function ($a, $b) {
return $a['name'] <=> $b['name'];
});
}
if ( ! empty($characters['supporting']))
{
uasort($characters['supporting'], function ($a, $b) {
uasort($characters['supporting'], static function ($a, $b) {
return $a['name'] <=> $b['name'];
});
}
@ -114,7 +114,7 @@ final class AnimeTransformer extends AbstractTransformer {
'genres' => $item['genres'],
'id' => $item['id'],
'included' => $item['included'],
'show_type' => $this->string($item['showType'])->upperCaseFirst()->__toString(),
'show_type' => (string)$this->string($item['showType'])->upperCaseFirst(),
'slug' => $item['slug'],
'staff' => $staff,
'status' => Kitsu::getAiringStatus($item['startDate'], $item['endDate']),

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
@ -26,6 +26,10 @@ use Aviat\Ion\Transformer\AbstractTransformer;
*/
final class CharacterTransformer extends AbstractTransformer {
/**
* @param array $characterData
* @return Character
*/
public function transform($characterData): Character
{
$data = JsonAPI::organizeData($characterData);
@ -44,14 +48,14 @@ final class CharacterTransformer extends AbstractTransformer {
{
if (array_key_exists('anime', $data['included']))
{
uasort($data['included']['anime'], function ($a, $b) {
uasort($data['included']['anime'], static function ($a, $b) {
return $a['attributes']['canonicalTitle'] <=> $b['attributes']['canonicalTitle'];
});
}
if (array_key_exists('manga', $data['included']))
{
uasort($data['included']['manga'], function ($a, $b) {
uasort($data['included']['manga'], static function ($a, $b) {
return $a['attributes']['canonicalTitle'] <=> $b['attributes']['canonicalTitle'];
});
}
@ -142,13 +146,12 @@ final class CharacterTransformer extends AbstractTransformer {
foreach ($role['relationships']['person']['people'] as $pid => $peoples)
{
$p = $peoples;
}
$person = $p['attributes'];
$person['id'] = $pid;
$person['image'] = $person['image']['original'];
uasort($role['relationships']['media']['anime'], function ($a, $b) {
uasort($role['relationships']['media']['anime'], static function ($a, $b) {
return $a['attributes']['canonicalTitle'] <=> $b['attributes']['canonicalTitle'];
});
@ -158,7 +161,9 @@ final class CharacterTransformer extends AbstractTransformer {
];
$output[$roleName][$language][] = $item;
} else
}
}
else
{
foreach ($role['relationships']['person']['people'] as $pid => $person)
{

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
@ -85,7 +85,7 @@ final class MangaListTransformer extends AbstractTransformer {
$titles = Kitsu::filterTitles($manga);
$title = array_shift($titles);
$map = new MangaListItem([
return new MangaListItem([
'id' => $item['id'],
'mal_id' => $MALid,
'chapters' => [
@ -103,7 +103,7 @@ final class MangaListTransformer extends AbstractTransformer {
'slug' => $manga['slug'],
'title' => $title,
'titles' => $titles,
'type' => $this->string($manga['subtype'])->upperCaseFirst()->__toString(),
'type' => (string)$this->string($manga['subtype'])->upperCaseFirst(),
'url' => 'https://kitsu.io/manga/' . $manga['slug'],
]),
'reading_status' => $item['attributes']['status'],
@ -112,8 +112,6 @@ final class MangaListTransformer extends AbstractTransformer {
'reread' => $item['attributes']['reconsumeCount'],
'user_rating' => $rating,
]);
return $map;
}
/**

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
@ -98,14 +98,14 @@ final class MangaTransformer extends AbstractTransformer {
if ( ! empty($characters['main']))
{
uasort($characters['main'], function ($a, $b) {
uasort($characters['main'], static function ($a, $b) {
return $a['name'] <=> $b['name'];
});
}
if ( ! empty($characters['supporting']))
{
uasort($characters['supporting'], function ($a, $b) {
uasort($characters['supporting'], static function ($a, $b) {
return $a['name'] <=> $b['name'];
});
}
@ -130,10 +130,14 @@ final class MangaTransformer extends AbstractTransformer {
]);
}
private function count(int $value = NULL)
/**
* @param int|null $value
* @return string
*/
private function count(int $value = NULL): string
{
return ((int)$value === 0)
? '-'
: $value;
: (string)$value;
}
}

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
@ -25,6 +25,10 @@ use Aviat\Ion\Transformer\AbstractTransformer;
*/
final class PersonTransformer extends AbstractTransformer {
/**
* @param array|object $personData
* @return Person
*/
public function transform($personData): Person
{
$data = JsonAPI::organizeData($personData);
@ -78,7 +82,7 @@ final class PersonTransformer extends AbstractTransformer {
$includedMedia = array_replace_recursive($existingMedia, $relatedMedia);
uasort($includedMedia, function ($a, $b) {
uasort($includedMedia, static function ($a, $b) {
return $a['canonicalTitle'] <=> $b['canonicalTitle'];
});
@ -103,10 +107,10 @@ final class PersonTransformer extends AbstractTransformer {
}
}
uasort($output['characters']['main'], function ($a, $b) {
uasort($output['characters']['main'], static function ($a, $b) {
return $a['character']['canonicalName'] <=> $b['character']['canonicalName'];
});
uasort($output['characters']['supporting'], function ($a, $b) {
uasort($output['characters']['supporting'], static function ($a, $b) {
return $a['character']['canonicalName'] <=> $b['character']['canonicalName'];
});
ksort($output['staff']);
@ -114,14 +118,14 @@ final class PersonTransformer extends AbstractTransformer {
{
if (array_key_exists('anime', $media))
{
uasort($media['anime'], function ($a, $b) {
uasort($media['anime'], static function ($a, $b) {
return $a['canonicalTitle'] <=> $b['canonicalTitle'];
});
}
if (array_key_exists('manga', $media))
{
uasort($media['manga'], function ($a, $b) {
uasort($media['manga'], static function ($a, $b) {
return $a['canonicalTitle'] <=> $b['canonicalTitle'];
});
}

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
@ -24,6 +24,9 @@ use Aviat\Ion\Transformer\AbstractTransformer;
/**
* Transform user profile data for display
*
* @param array|object $profileData
* @return User
*/
final class UserTransformer extends AbstractTransformer {
public function transform($profileData): User
@ -41,6 +44,7 @@ final class UserTransformer extends AbstractTransformer {
$stats[$key] = $item['attributes']['statsData'];
unset($item);
}
unset($item);
$waifu = [];
if (array_key_exists('waifu', $rels))
@ -131,7 +135,7 @@ final class UserTransformer extends AbstractTransformer {
return $output;
}
private function organizeStats($stats, $data = []): array
private function organizeStats(array $stats, $data = []): array
{
$animeStats = [];
$mangaStats = [];

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/

View File

@ -4,22 +4,25 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
namespace Aviat\AnimeClient\API;
use Amp\Http\Client\Request;
use function Amp\call;
use function Amp\Promise\{all, wait};
use function Aviat\AnimeClient\getApiClient;
use Throwable;
/**
* Class to simplify making and validating simultaneous requests
*/
@ -35,7 +38,7 @@ final class ParallelAPIRequest {
/**
* Add a request
*
* @param string|\Amp\Artax\Request $request
* @param string|Request $request
* @param string|number $key
* @return self
*/
@ -54,7 +57,7 @@ final class ParallelAPIRequest {
/**
* Add multiple requests
*
* @param string[]|\Amp\Artax\Request[] $requests
* @param string[]|Request[] $requests
* @return self
*/
public function addRequests(array $requests): self
@ -67,7 +70,7 @@ final class ParallelAPIRequest {
* Make the requests, and return the body for each
*
* @return array
* @throws \Throwable
* @throws Throwable
*/
public function makeRequests(): array
{
@ -77,9 +80,9 @@ final class ParallelAPIRequest {
foreach ($this->requests as $key => $url)
{
$promises[$key] = call(function () use ($client, $url) {
$promises[$key] = call(static function () use ($client, $url) {
$response = yield $client->request($url);
return yield $response->getBody();
return yield $response->getBody()->buffer();
});
}
@ -90,7 +93,7 @@ final class ParallelAPIRequest {
* Make the requests and return the response objects
*
* @return array
* @throws \Throwable
* @throws Throwable
*/
public function getResponses(): array
{
@ -100,7 +103,7 @@ final class ParallelAPIRequest {
foreach ($this->requests as $key => $url)
{
$promises[$key] = call(function () use ($client, $url) {
$promises[$key] = call(static function () use ($client, $url) {
return yield $client->request($url);
});
}

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
@ -18,7 +18,10 @@ namespace Aviat\AnimeClient;
use function Amp\Promise\wait;
use Amp\Artax\{Client, DefaultClient, Response};
use Amp\Http\Client\Request;
use Amp\Http\Client\Response;
use Amp\Http\Client\HttpClient;
use Amp\Http\Client\HttpClientBuilder;
use Aviat\Ion\ConfigInterface;
use Yosymfony\Toml\{Toml, TomlBuilder};
@ -178,8 +181,8 @@ function checkFolderPermissions(ConfigInterface $config): array
$publicDir = $config->get('asset_dir');
$pathMap = [
'app/config' => realpath(__DIR__ . '/../app/config'),
'app/logs' => realpath(__DIR__ . '/../app/logs'),
'app/config' => realpath(__DIR__ . '/../../app/config'),
'app/logs' => realpath(__DIR__ . '/../../app/logs'),
'public/images/avatars' => "{$publicDir}/images/avatars",
'public/images/anime' => "{$publicDir}/images/anime",
'public/images/characters' => "{$publicDir}/images/characters",
@ -218,23 +221,29 @@ function getApiClient ()
if ($client === NULL)
{
$client = new DefaultClient;
$client->setOption(Client::OP_TRANSFER_TIMEOUT, 0);
$client = HttpClientBuilder::buildDefault();
}
return $client;
}
/**
* Simplify making a request with Artax
* Simplify making a request with Http\Client
*
* @param $request
* @param string|Request $request
* @return Response
* @throws \Throwable
*/
function getResponse ($request): Response
{
$client = getApiClient();
if (is_string($request))
{
$request = new Request($request);
}
return wait($client->request($request));
}

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
@ -36,7 +36,7 @@ use Zend\Diactoros\{Response, ServerRequestFactory};
/**
* Base class for console command setup
*/
class BaseCommand extends Command {
abstract class BaseCommand extends Command {
use CacheTrait;
use ContainerAware;
@ -46,7 +46,7 @@ class BaseCommand extends Command {
* @param string $message
* @return void
*/
protected function echoBox($message)
protected function echoBox($message): void
{
try
{
@ -68,7 +68,7 @@ class BaseCommand extends Command {
*/
protected function setupContainer(): Container
{
$APP_DIR = realpath(__DIR__ . '/../../app');
$APP_DIR = realpath(__DIR__ . '/../../../app');
$APPCONF_DIR = realpath("{$APP_DIR}/appConf/");
$CONF_DIR = realpath("{$APP_DIR}/config/");
$baseConfig = require $APPCONF_DIR . '/base_config.php';
@ -82,7 +82,7 @@ class BaseCommand extends Command {
$configArray = array_replace_recursive($baseConfig, $config, $overrideConfig);
$di = static function ($configArray) use ($APP_DIR) {
$di = static function ($configArray) use ($APP_DIR): Container {
$container = new Container();
// -------------------------------------------------------------------------
@ -91,16 +91,19 @@ class BaseCommand extends Command {
$app_logger = new Logger('animeclient');
$app_logger->pushHandler(new RotatingFileHandler($APP_DIR . '/logs/app-cli.log', Logger::NOTICE));
$kitsu_request_logger = new Logger('kitsu-request');
$kitsu_request_logger->pushHandler(new RotatingFileHandler($APP_DIR . '/logs/kitsu_request-cli.log', Logger::NOTICE));
$anilistRequestLogger = new Logger('anilist-request');
$anilistRequestLogger->pushHandler(new RotatingFileHandler($APP_DIR . '/logs/anilist_request-cli.log', Logger::NOTICE));
$container->setLogger($app_logger);
$container->setLogger($anilistRequestLogger, 'anilist-request');
$container->setLogger($kitsu_request_logger, 'kitsu-request');
// Create Config Object
$container->set('config', static function() use ($configArray) {
$container->set('config', static function() use ($configArray): Config {
return new Config($configArray);
});
@ -126,7 +129,7 @@ class BaseCommand extends Command {
$_FILES
);
});
$container->set('response', static function() {
$container->set('response', static function(): Response {
return new Response;
});
@ -136,7 +139,7 @@ class BaseCommand extends Command {
});
// Models
$container->set('kitsu-model', static function($container) {
$container->set('kitsu-model', static function($container): Kitsu\Model {
$requestBuilder = new KitsuRequestBuilder();
$requestBuilder->setLogger($container->getLogger('kitsu-request'));
@ -152,7 +155,7 @@ class BaseCommand extends Command {
$model->setCache($cache);
return $model;
});
$container->set('anilist-model', static function ($container) {
$container->set('anilist-model', static function ($container): Anilist\Model {
$requestBuilder = new Anilist\AnilistRequestBuilder();
$requestBuilder->setLogger($container->getLogger('anilist-request'));
@ -166,21 +169,21 @@ class BaseCommand extends Command {
return $model;
});
$container->set('settings-model', static function($container) {
$container->set('settings-model', static function($container): Model\Settings {
$model = new Model\Settings($container->get('config'));
$model->setContainer($container);
return $model;
});
$container->set('auth', static function($container) {
$container->set('auth', static function($container): Kitsu\Auth {
return new Kitsu\Auth($container);
});
$container->set('url-generator', static function($container) {
$container->set('url-generator', static function($container): UrlGenerator {
return new UrlGenerator($container);
});
$container->set('util', static function($container) {
$container->set('util', static function($container): Util {
return new Util($container);
});

View File

@ -4,18 +4,21 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
namespace Aviat\AnimeClient\Command;
use Aviat\Ion\Di\Exception\ContainerException;
use Aviat\Ion\Di\Exception\NotFoundException;
/**
* Clears the API Cache
*/
@ -25,15 +28,15 @@ final class CacheClear extends BaseCommand {
*
* @param array $args
* @param array $options
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws ContainerException
* @throws NotFoundException
* @return void
*/
public function execute(array $args, array $options = []): void
{
$this->setContainer($this->setupContainer());
$cache = $this->container->get('cache');
$cache->clear();
$this->container->get('cache')->clear();
$this->echoBox('API Cache has been cleared.');
}

View File

@ -4,18 +4,21 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
namespace Aviat\AnimeClient\Command;
use Aviat\Ion\Di\Exception\ContainerException;
use Aviat\Ion\Di\Exception\NotFoundException;
/**
* Clears the API Cache
*/
@ -25,8 +28,8 @@ final class CachePrime extends BaseCommand {
*
* @param array $args
* @param array $options
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws ContainerException
* @throws NotFoundException
* @return void
*/
public function execute(array $args, array $options = []): void
@ -50,8 +53,9 @@ final class CachePrime extends BaseCommand {
$userIdItem->save();
}
// Prime anime list cache
$kitsuModel = $this->container->get('kitsu-model');
// Prime anime list cache
$kitsuModel->getFullOrganizedAnimeList();
// Prime manga list cache

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/

View File

@ -4,26 +4,34 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
namespace Aviat\AnimeClient\Command;
use Aviat\AnimeClient\API\
{Anilist\MissingIdException, FailedResponseException, JsonAPI, ParallelAPIRequest};
use Aviat\AnimeClient\API\{
Anilist\MissingIdException,
FailedResponseException,
JsonAPI,
ParallelAPIRequest
};
use Aviat\AnimeClient\API\Anilist\Transformer\{
AnimeListTransformer as AALT,
MangaListTransformer as AMLT
};
use Aviat\AnimeClient\API\Anilist\Model as AnilistModel;
use Aviat\AnimeClient\API\Kitsu\Model as KitsuModel;
use Aviat\AnimeClient\API\Mapping\{AnimeWatchingStatus, MangaReadingStatus};
use Aviat\AnimeClient\Types\FormItem;
use Aviat\Ion\Di\Exception\ContainerException;
use Aviat\Ion\Di\Exception\NotFoundException;
use Aviat\Ion\Json;
use DateTime;
@ -34,13 +42,13 @@ final class SyncLists extends BaseCommand {
/**
* Model for making requests to Anilist API
* @var \Aviat\AnimeClient\API\Anilist\Model
* @var AnilistModel
*/
protected $anilistModel;
/**
* Model for making requests to Kitsu API
* @var \Aviat\AnimeClient\API\Kitsu\Model
* @var KitsuModel
*/
protected $kitsuModel;
@ -49,8 +57,8 @@ final class SyncLists extends BaseCommand {
*
* @param array $args
* @param array $options
* @throws \Aviat\Ion\Di\Exception\ContainerException
* @throws \Aviat\Ion\Di\Exception\NotFoundException
* @throws ContainerException
* @throws NotFoundException
* @throws \Throwable
*/
public function execute(array $args, array $options = []): void
@ -169,8 +177,8 @@ final class SyncLists extends BaseCommand {
* Format an Anilist anime list for comparison
*
* @return array
* @throws \Aviat\Ion\Di\Exception\ContainerException
* @throws \Aviat\Ion\Di\Exception\NotFoundException
* @throws ContainerException
* @throws NotFoundException
*/
protected function formatAnilistAnimeList(): array
{
@ -202,8 +210,8 @@ final class SyncLists extends BaseCommand {
* Format an Anilist manga list for comparison
*
* @return array
* @throws \Aviat\Ion\Di\Exception\ContainerException
* @throws \Aviat\Ion\Di\Exception\NotFoundException
* @throws ContainerException
* @throws NotFoundException
*/
protected function formatAnilistMangaList(): array
{
@ -596,6 +604,12 @@ final class SyncLists extends BaseCommand {
}
else if ($action === 'create')
{
$maybeRequest = $this->kitsuModel->createListItem($item);
if ($maybeRequest === NULL)
{
$this->echoBox("Skipped creating Kitsu {$type} due to missing id ¯\_(ツ)_/¯");
continue;
}
$requester->addRequest($this->kitsuModel->createListItem($item));
}
}
@ -676,7 +690,6 @@ final class SyncLists extends BaseCommand {
$responseData = Json::decode($response);
// $id = $itemsToUpdate[$key]['id'];
if ( ! array_key_exists('errors', $responseData))
{
$verb = ($action === 'update') ? 'updated' : 'created';

View File

@ -4,19 +4,20 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
namespace Aviat\AnimeClient\Command;
use Aviat\AnimeClient\API\JsonAPI;
use Aviat\AnimeClient\API\Kitsu\Model;
use Aviat\AnimeClient\Controller\Images;
/**
@ -26,7 +27,7 @@ use Aviat\AnimeClient\Controller\Images;
final class UpdateThumbnails extends ClearThumbnails {
/**
* Model for making requests to Kitsu API
* @var \Aviat\AnimeClient\API\Kitsu\Model
* @var Model
*/
protected $kitsuModel;
@ -62,7 +63,11 @@ final class UpdateThumbnails extends ClearThumbnails {
$this->echoBox('Finished regenerating all thumbnails');
}
public function getImageList()
/**
* @return array array-key[][]
* @psalm-return array{anime: list<array-key>, manga: list<array-key>}
*/
public function getImageList(): array
{
$mangaList = $this->kitsuModel->getFullRawMangaList();
$includes = JsonAPI::organizeIncludes($mangaList['included']);

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
@ -18,9 +18,19 @@ namespace Aviat\AnimeClient;
use function Aviat\Ion\_dir;
use Aura\Router\Generator;
use Aura\Session\Segment;
use Aviat\AnimeClient\API\Kitsu\Auth;
use Aviat\Ion\ConfigInterface;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Aviat\Ion\Di\{
ContainerAware,
ContainerInterface
ContainerInterface,
Exception\ContainerException,
Exception\NotFoundException
};
use Aviat\Ion\Exception\DoubleRenderException;
use Aviat\Ion\View\{HtmlView, HttpView, JsonView};
@ -35,31 +45,31 @@ class Controller {
/**
* The authentication object
* @var \Aviat\AnimeClient\API\Kitsu\Auth $auth ;
* @var Auth $auth ;
*/
protected $auth;
/**
* Cache manager
* @var \Psr\Cache\CacheItemPoolInterface
* @var CacheItemPoolInterface
*/
protected $cache;
/**
* The global configuration object
* @var \Aviat\Ion\ConfigInterface $config
* @var ConfigInterface $config
*/
public $config;
/**
* Request object
* @var \Psr\Http\Message\ServerRequestInterface $request
* @var ServerRequestInterface $request
*/
protected $request;
/**
* Response object
* @var \Psr\Http\Message\ResponseInterface $response
* @var ResponseInterface $response
*/
public $response;
@ -71,13 +81,13 @@ class Controller {
/**
* Aura url generator
* @var \Aura\Router\Generator
* @var Generator
*/
protected $url;
/**
* Session segment
* @var \Aura\Session\Segment
* @var Segment
*/
protected $session;
@ -91,8 +101,8 @@ class Controller {
* Controller constructor.
*
* @param ContainerInterface $container
* @throws \Aviat\Ion\Di\Exception\ContainerException
* @throws \Aviat\Ion\Di\Exception\NotFoundException
* @throws ContainerException
* @throws NotFoundException
*/
public function __construct(ContainerInterface $container)
{
@ -127,8 +137,8 @@ class Controller {
* Set the current url in the session as the target of a future redirect
*
* @param string|NULL $url
* @throws \Aviat\Ion\Di\Exception\ContainerException
* @throws \Aviat\Ion\Di\Exception\NotFoundException
* @throws ContainerException
* @throws NotFoundException
*/
public function setSessionRedirect(string $url = NULL): void
{
@ -151,7 +161,7 @@ class Controller {
return;
}
if (null === $url)
if (NULL === $url)
{
$url = $util->isViewPage()
? (string) $this->request->getUri()
@ -167,8 +177,8 @@ class Controller {
* If one is not set, redirect to default url
*
* @throws InvalidArgumentException
* @throws \Aviat\Ion\Di\Exception\ContainerException
* @throws \Aviat\Ion\Di\Exception\NotFoundException
* @throws ContainerException
* @throws NotFoundException
* @return void
*/
public function sessionRedirect(): void
@ -191,7 +201,6 @@ class Controller {
'Forbidden',
'You must <a href="/login">log in</a> to perform this action.'
);
die();
}
}
@ -202,8 +211,8 @@ class Controller {
* @param string $template
* @param array $data
* @throws InvalidArgumentException
* @throws \Aviat\Ion\Di\Exception\ContainerException
* @throws \Aviat\Ion\Di\Exception\NotFoundException
* @throws ContainerException
* @throws NotFoundException
* @return string
*/
protected function loadPartial($view, string $template, array $data = []): string
@ -236,8 +245,8 @@ class Controller {
* @param string $template
* @param array $data
* @throws InvalidArgumentException
* @throws \Aviat\Ion\Di\Exception\ContainerException
* @throws \Aviat\Ion\Di\Exception\NotFoundException
* @throws ContainerException
* @throws NotFoundException
* @return void
*/
protected function renderFullPage($view, string $template, array $data): void
@ -266,8 +275,8 @@ class Controller {
* @param string $title
* @param string $message
* @throws InvalidArgumentException
* @throws \Aviat\Ion\Di\Exception\ContainerException
* @throws \Aviat\Ion\Di\Exception\NotFoundException
* @throws ContainerException
* @throws NotFoundException
* @return void
*/
public function notFound(
@ -287,18 +296,18 @@ class Controller {
* @param int $httpCode
* @param string $title
* @param string $message
* @param string $long_message
* @param string $longMessage
* @throws InvalidArgumentException
* @throws \Aviat\Ion\Di\Exception\ContainerException
* @throws \Aviat\Ion\Di\Exception\NotFoundException
* @throws ContainerException
* @throws NotFoundException
* @return void
*/
public function errorPage(int $httpCode, string $title, string $message, string $long_message = ''): void
public function errorPage(int $httpCode, string $title, string $message, string $longMessage = ''): void
{
$this->outputHTML('error', [
'title' => $title,
'message' => $message,
'long_message' => $long_message
'long_message' => $longMessage
], NULL, $httpCode);
}
@ -342,7 +351,7 @@ class Controller {
/**
* Helper for consistent page titles
*
* @param string[] $parts Title segments
* @param string ...$parts Title segments
* @return string
*/
public function formatTitle(string ...$parts) : string
@ -357,8 +366,8 @@ class Controller {
* @param string $type
* @param string $message
* @throws InvalidArgumentException
* @throws \Aviat\Ion\Di\Exception\ContainerException
* @throws \Aviat\Ion\Di\Exception\NotFoundException
* @throws ContainerException
* @throws NotFoundException
* @return string
*/
protected function showMessage($view, string $type, string $message): string
@ -374,16 +383,16 @@ class Controller {
*
* @param string $template
* @param array $data
* @param HtmlView|null $view
* @param HtmlView|NULL $view
* @param int $code
* @throws InvalidArgumentException
* @throws \Aviat\Ion\Di\Exception\ContainerException
* @throws \Aviat\Ion\Di\Exception\NotFoundException
* @throws ContainerException
* @throws NotFoundException
* @return void
*/
protected function outputHTML(string $template, array $data = [], $view = NULL, int $code = 200): void
{
if (null === $view)
if (NULL === $view)
{
$view = new HtmlView($this->container);
}

View File

@ -4,26 +4,32 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
namespace Aviat\AnimeClient\Controller;
use Aura\Router\Exception\RouteNotFound;
use Aviat\AnimeClient\Controller as BaseController;
use Aviat\AnimeClient\API\Kitsu\Transformer\AnimeListTransformer;
use Aviat\AnimeClient\API\Enum\AnimeWatchingStatus\Kitsu as KitsuWatchingStatus;
use Aviat\AnimeClient\API\Mapping\AnimeWatchingStatus;
use Aviat\AnimeClient\Types\FormItem;
use Aviat\Ion\Di\ContainerInterface;
use Aviat\Ion\Di\Exception\ContainerException;
use Aviat\Ion\Di\Exception\NotFoundException;
use Aviat\Ion\Json;
use InvalidArgumentException;
use Throwable;
/**
* Controller for Anime-related pages
*/
@ -39,8 +45,8 @@ final class Anime extends BaseController {
* Constructor
*
* @param ContainerInterface $container
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws ContainerException
* @throws NotFoundException
*/
public function __construct(ContainerInterface $container)
{
@ -60,9 +66,10 @@ final 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
* @throws ContainerException
* @throws NotFoundException
* @throws InvalidArgumentException
* @throws Throwable
* @return void
*/
public function index($type = KitsuWatchingStatus::WATCHING, string $view = NULL): void
@ -104,10 +111,11 @@ final 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
* @throws ContainerException
* @throws NotFoundException
* @throws RouteNotFound
* @throws InvalidArgumentException
* @throws Throwable
* @return void
*/
public function addForm(): void
@ -128,8 +136,9 @@ final class Anime extends BaseController {
/**
* Add an anime to the list
*
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws ContainerException
* @throws NotFoundException
* @throws Throwable
* @return void
*/
public function add(): void
@ -168,6 +177,7 @@ final class Anime extends BaseController {
*
* @param string $id
* @param string $status
* @throws RouteNotFound
*/
public function edit(string $id, $status = 'all'): void
{
@ -204,8 +214,9 @@ final class Anime extends BaseController {
/**
* Update an anime item via a form submission
*
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws ContainerException
* @throws NotFoundException
* @throws Throwable
* @return void
*/
public function formUpdate(): void
@ -236,6 +247,7 @@ final class Anime extends BaseController {
/**
* Increase the watched count for an anime item
*
* @throws Throwable
* @return void
*/
public function increment(): void
@ -266,6 +278,7 @@ final class Anime extends BaseController {
/**
* Remove an anime from the list
*
* @throws Throwable
* @return void
*/
public function delete(): void
@ -292,9 +305,9 @@ final class Anime extends BaseController {
* View details of an anime
*
* @param string $animeId
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws \InvalidArgumentException
* @throws ContainerException
* @throws NotFoundException
* @throws InvalidArgumentException
* @return void
*/
public function details(string $animeId): void

View File

@ -4,24 +4,30 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
namespace Aviat\AnimeClient\Controller;
use Aura\Router\Exception\RouteNotFound;
use Aviat\AnimeClient\Controller as BaseController;
use Aviat\AnimeClient\Model\{
Anime as AnimeModel,
AnimeCollection as AnimeCollectionModel
};
use Aviat\Ion\Di\ContainerInterface;
use Aviat\Ion\Di\Exception\ContainerException;
use Aviat\Ion\Di\Exception\NotFoundException;
use Aviat\Ion\Exception\DoubleRenderException;
use InvalidArgumentException;
/**
* Controller for Anime collection pages
@ -44,8 +50,8 @@ final class AnimeCollection extends BaseController {
* Constructor
*
* @param ContainerInterface $container
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws ContainerException
* @throws NotFoundException
*/
public function __construct(ContainerInterface $container)
{
@ -69,7 +75,7 @@ final class AnimeCollection extends BaseController {
/**
* Search for anime
*
* @throws \Aviat\Ion\Exception\DoubleRenderException
* @throws DoubleRenderException
* @return void
*/
public function search(): void
@ -83,9 +89,9 @@ final class AnimeCollection extends BaseController {
* Show the anime collection page
*
* @param string $view
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws \InvalidArgumentException
* @throws ContainerException
* @throws NotFoundException
* @throws InvalidArgumentException
* @return void
*/
public function view($view): void
@ -108,10 +114,10 @@ final 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
* @throws ContainerException
* @throws NotFoundException
* @throws RouteNotFound
* @throws InvalidArgumentException
* @return void
*/
public function form($id = NULL): void
@ -138,9 +144,9 @@ final class AnimeCollection extends BaseController {
/**
* Update a collection item
*
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws \InvalidArgumentException
* @throws ContainerException
* @throws NotFoundException
* @throws InvalidArgumentException
* @return void
*/
public function edit(): void
@ -173,9 +179,9 @@ final class AnimeCollection extends BaseController {
/**
* Add a collection item
*
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws \InvalidArgumentException
* @throws ContainerException
* @throws NotFoundException
* @throws InvalidArgumentException
* @return void
*/
public function add(): void

View File

@ -4,22 +4,25 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
namespace Aviat\AnimeClient\Controller;
use Aviat\AnimeClient\API\Kitsu\Model;
use Aviat\AnimeClient\Controller as BaseController;
use Aviat\AnimeClient\API\Kitsu\Transformer\CharacterTransformer;
use Aviat\Ion\Di\ContainerInterface;
use Aviat\Ion\Di\Exception\ContainerException;
use Aviat\Ion\Di\Exception\NotFoundException;
/**
* Controller for character description pages
@ -27,7 +30,7 @@ use Aviat\Ion\Di\ContainerInterface;
class Character extends BaseController {
/**
* @var \Aviat\AnimeClient\API\Kitsu\Model
* @var Model
*/
private $model;
@ -35,8 +38,8 @@ class Character extends BaseController {
* Character constructor.
*
* @param ContainerInterface $container
* @throws \Aviat\Ion\Di\Exception\ContainerException
* @throws \Aviat\Ion\Di\Exception\NotFoundException
* @throws ContainerException
* @throws NotFoundException
*/
public function __construct(ContainerInterface $container)
{

View File

@ -4,24 +4,28 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
namespace Aviat\AnimeClient\Controller;
use Aviat\Ion\Di\Exception\{ContainerException, NotFoundException};
use function Amp\Promise\wait;
use function Aviat\AnimeClient\getResponse;
use function Aviat\AnimeClient\createPlaceholderImage;
use Aviat\AnimeClient\Controller as BaseController;
use Throwable;
/**
* Controller for handling routes that don't fit elsewhere
*/
@ -32,17 +36,14 @@ final class Images extends BaseController {
* @param string $type The category of image
* @param string $file The filename to look for
* @param bool $display Whether to output the image to the server
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws \InvalidArgumentException
* @throws \TypeError
* @throws \Error
* @throws \Throwable
* @return void
* @throws NotFoundException
* @throws Throwable
* @throws ContainerException
*/
public function cache(string $type, string $file, $display = TRUE): void
{
$currentUrl = $this->request->getUri()->__toString();
$currentUrl = (string)$this->request->getUri();
$kitsuUrl = 'https://media.kitsu.io/';
$fileName = str_replace('-original', '', $file);
@ -129,7 +130,7 @@ final class Images extends BaseController {
return;
}
$data = wait($response->getBody());
$data = wait($response->getBody()->buffer());
[$origWidth] = getimagesizefromstring($data);
$gdImg = imagecreatefromstring($data);

View File

@ -4,25 +4,30 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
namespace Aviat\AnimeClient\Controller;
use Aura\Router\Exception\RouteNotFound;
use Aviat\AnimeClient\Controller;
use Aviat\AnimeClient\API\Kitsu\Transformer\MangaListTransformer;
use Aviat\AnimeClient\API\Mapping\MangaReadingStatus;
use Aviat\AnimeClient\Model\Manga as MangaModel;
use Aviat\AnimeClient\Types\FormItem;
use Aviat\Ion\Di\ContainerInterface;
use Aviat\Ion\{Json, StringWrapper};
use Aviat\Ion\Di\Exception\{ContainerException, NotFoundException};
use Aviat\Ion\Json;
use InvalidArgumentException;
use Throwable;
/**
* Controller for manga list
@ -39,8 +44,8 @@ final class Manga extends Controller {
* Constructor
*
* @param ContainerInterface $container
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws ContainerException
* @throws NotFoundException
*/
public function __construct(ContainerInterface $container)
{
@ -59,9 +64,9 @@ final class Manga extends Controller {
*
* @param string $status
* @param string $view
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws \InvalidArgumentException
* @throws ContainerException
* @throws NotFoundException
* @throws InvalidArgumentException
* @return void
*/
public function index($status = 'all', $view = ''): void
@ -103,10 +108,10 @@ final 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
* @throws ContainerException
* @throws NotFoundException
* @throws RouteNotFound
* @throws InvalidArgumentException
* @return void
*/
public function addForm(): void
@ -129,9 +134,10 @@ final class Manga extends Controller {
/**
* Add an manga to the list
*
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @return void
* @throws NotFoundException
* @throws Throwable
* @throws ContainerException
*/
public function add(): void
{
@ -168,10 +174,10 @@ final 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
* @throws ContainerException
* @throws NotFoundException
* @throws RouteNotFound
* @throws InvalidArgumentException
* @return void
*/
public function edit($id, $status = 'All'): void
@ -210,9 +216,10 @@ final class Manga extends Controller {
/**
* Update an manga item via a form submission
*
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @return void
* @throws Throwable
* @throws NotFoundException
* @throws ContainerException
*/
public function formUpdate(): void
{
@ -228,7 +235,7 @@ final class Manga extends Controller {
if ($full_result['statusCode'] === 200)
{
$this->setFlashMessage("Successfully updated manga.", 'success');
$this->setFlashMessage('Successfully updated manga.', 'success');
$this->cache->clear();
}
else
@ -242,6 +249,7 @@ final class Manga extends Controller {
/**
* Increment the progress of a manga item
* @throws Throwable
*/
public function increment(): void
{
@ -265,8 +273,9 @@ final class Manga extends Controller {
/**
* Remove an manga from the list
*
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws ContainerException
* @throws NotFoundException
* @throws Throwable
* @return void
*/
public function delete(): void
@ -293,9 +302,10 @@ final 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
* @throws ContainerException
* @throws NotFoundException
* @throws InvalidArgumentException
* @throws Throwable
* @return void
*/
public function details($manga_id): void

View File

@ -4,25 +4,31 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
namespace Aviat\AnimeClient\Controller;
use Aura\Router\Exception\RouteNotFound;
use Aviat\AnimeClient\Controller as BaseController;
use Aviat\Ion\Di\Exception\ContainerException;
use Aviat\Ion\Di\Exception\NotFoundException;
use Aviat\Ion\Exception\DoubleRenderException;
use Aviat\AnimeClient\Model\{
Manga as MangaModel,
MangaCollection as MangaCollectionModel
};
use Aviat\Ion\Di\ContainerInterface;
use InvalidArgumentException;
/**
* Controller for manga collection pages
*/
@ -44,8 +50,8 @@ final class MangaCollection extends BaseController {
* Constructor
*
* @param ContainerInterface $container
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws ContainerException
* @throws NotFoundException
* @throws \InvalidArgumentException
*/
public function __construct(ContainerInterface $container)
@ -65,7 +71,7 @@ final class MangaCollection extends BaseController {
/**
* Search for manga
*
* @throws \Aviat\Ion\Exception\DoubleRenderException
* @throws DoubleRenderException
* @return void
*/
public function search(): void
@ -79,9 +85,9 @@ final class MangaCollection extends BaseController {
* Show the manga collection page
*
* @param string $view
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws \InvalidArgumentException
* @throws ContainerException
* @throws NotFoundException
* @throws InvalidArgumentException
* @return void
*/
public function index($view): void
@ -104,10 +110,10 @@ final 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
* @throws ContainerException
* @throws NotFoundException
* @throws RouteNotFound
* @throws InvalidArgumentException
* @return void
*/
public function form($id = NULL): void
@ -132,9 +138,9 @@ final class MangaCollection extends BaseController {
/**
* Update a collection item
*
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws \InvalidArgumentException
* @throws ContainerException
* @throws NotFoundException
* @throws InvalidArgumentException
* @return void
*/
public function edit(): void
@ -156,9 +162,9 @@ final class MangaCollection extends BaseController {
/**
* Add a collection item
*
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @throws \InvalidArgumentException
* @throws ContainerException
* @throws NotFoundException
* @throws InvalidArgumentException
* @return void
*/
public function add(): void

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/

View File

@ -4,22 +4,25 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
namespace Aviat\AnimeClient\Controller;
use Aviat\AnimeClient\API\Kitsu\Model;
use Aviat\AnimeClient\Controller as BaseController;
use Aviat\AnimeClient\API\Kitsu\Transformer\PersonTransformer;
use Aviat\Ion\Di\ContainerInterface;
use Aviat\Ion\Di\Exception\ContainerException;
use Aviat\Ion\Di\Exception\NotFoundException;
/**
* Controller for People pages
@ -27,7 +30,7 @@ use Aviat\Ion\Di\ContainerInterface;
final class People extends BaseController {
/**
* @var \Aviat\AnimeClient\API\Kitsu\Model
* @var Model
*/
private $model;
@ -35,8 +38,8 @@ final class People extends BaseController {
* People constructor.
*
* @param ContainerInterface $container
* @throws \Aviat\Ion\Di\Exception\ContainerException
* @throws \Aviat\Ion\Di\Exception\NotFoundException
* @throws ContainerException
* @throws NotFoundException
*/
public function __construct(ContainerInterface $container)
{

View File

@ -4,20 +4,24 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
namespace Aviat\AnimeClient\Controller;
use Aura\Router\Exception\RouteNotFound;
use Aviat\AnimeClient\API\Anilist\Model;
use Aviat\AnimeClient\Controller as BaseController;
use Aviat\Ion\Di\ContainerInterface;
use Aviat\Ion\Di\Exception\ContainerException;
use Aviat\Ion\Di\Exception\NotFoundException;
/**
* Controller for user settings
@ -25,7 +29,7 @@ use Aviat\Ion\Di\ContainerInterface;
final class Settings extends BaseController {
/**
* @var \Aviat\AnimeClient\API\Anilist\Model
* @var Model
*/
private $anilistModel;
@ -38,8 +42,8 @@ final class Settings extends BaseController {
* Settings constructor.
*
* @param ContainerInterface $container
* @throws \Aviat\Ion\Di\Exception\ContainerException
* @throws \Aviat\Ion\Di\Exception\NotFoundException
* @throws ContainerException
* @throws NotFoundException
*/
public function __construct(ContainerInterface $container)
{
@ -75,7 +79,7 @@ final class Settings extends BaseController {
/**
* Attempt to save the user's settings
*
* @throws \Aura\Router\Exception\RouteNotFound
* @throws RouteNotFound
*/
public function update(): void
{

View File

@ -4,22 +4,25 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
namespace Aviat\AnimeClient\Controller;
use Aviat\AnimeClient\API\Kitsu\Model;
use Aviat\AnimeClient\API\Kitsu\Transformer\UserTransformer;
use Aviat\AnimeClient\Controller as BaseController;
use Aviat\Ion\Di\ContainerInterface;
use Aviat\Ion\Di\Exception\ContainerException;
use Aviat\Ion\Di\Exception\NotFoundException;
/**
* Controller for handling routes that don't fit elsewhere
@ -27,7 +30,7 @@ use Aviat\Ion\Di\ContainerInterface;
final class User extends BaseController {
/**
* @var \Aviat\AnimeClient\API\Kitsu\Model
* @var Model
*/
private $kitsuModel;
@ -35,8 +38,8 @@ final class User extends BaseController {
* User constructor.
*
* @param ContainerInterface $container
* @throws \Aviat\Ion\Di\Exception\ContainerException
* @throws \Aviat\Ion\Di\Exception\NotFoundException
* @throws ContainerException
* @throws NotFoundException
*/
public function __construct(ContainerInterface $container)
{

View File

@ -4,13 +4,13 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
@ -18,13 +18,16 @@ namespace Aviat\AnimeClient;
use function Aviat\Ion\_dir;
use Aura\Router\{Matcher, Rule};
use Aura\Router\{Matcher, Route, Rule};
use Aviat\AnimeClient\API\FailedResponseException;
use Aviat\Ion\Di\ContainerInterface;
use Aviat\Ion\Friend;
use Aviat\Ion\StringWrapper;
use LogicException;
use ReflectionException;
/**
* Basic routing/ dispatch
*/
@ -74,7 +77,7 @@ final class Dispatcher extends RoutingBase {
/**
* Get the current route object, if one matches
*
* @return \Aura\Router\Route|false
* @return Route|false
*/
public function getRoute()
{
@ -109,6 +112,7 @@ final class Dispatcher extends RoutingBase {
*
* @param object|null $route
* @return void
* @throws ReflectionException
*/
public function __invoke($route = NULL): void
{
@ -125,14 +129,7 @@ final class Dispatcher extends RoutingBase {
}
}
if ($route)
{
$parsed = $this->processRoute(new Friend($route));
$controllerName = $parsed['controller_name'];
$actionMethod = $parsed['action_method'];
$params = $parsed['params'];
}
else
if ( ! $route)
{
// If not route was matched, return an appropriate http
// error message
@ -140,8 +137,15 @@ final class Dispatcher extends RoutingBase {
$controllerName = DEFAULT_CONTROLLER;
$actionMethod = $errorRoute['action_method'];
$params = $errorRoute['params'];
$this->call($controllerName, $actionMethod, $params);
return;
}
$parsed = $this->processRoute(new Friend($route));
$controllerName = $parsed['controller_name'];
$actionMethod = $parsed['action_method'];
$params = $parsed['params'];
$this->call($controllerName, $actionMethod, $params);
}
@ -149,20 +153,21 @@ final class Dispatcher extends RoutingBase {
* Parse out the arguments for the appropriate controller for
* the current route
*
* @param \Aura\Router\Route $route
* @throws \LogicException
* @param Route $route
* @throws LogicException
* @return array
*/
protected function processRoute($route): array
{
if ( ! array_key_exists('controller', $route->attributes))
{
throw new LogicException('Missing controller');
}
if (array_key_exists('controller', $route->attributes))
{
$controllerName = $route->attributes['controller'];
}
else
{
throw new \LogicException('Missing controller');
}
// Get the full namespace for a controller if a short name is given
if (strpos($controllerName, '\\') === FALSE)
@ -249,7 +254,7 @@ final class Dispatcher extends RoutingBase {
foreach ($classFiles as $file)
{
$rawClassName = basename(str_replace('.php', '', $file));
$path = $this->string($rawClassName)->dasherize()->__toString();
$path = (string)$this->string($rawClassName)->dasherize();
$className = trim($defaultNamespace . '\\' . $rawClassName, '\\');
$controllers[$path] = $className;
@ -296,7 +301,7 @@ final class Dispatcher extends RoutingBase {
/**
* Get the appropriate params for the error page
* pased on the failed route
* passed on the failed route
*
* @return array|false
*/
@ -388,9 +393,9 @@ final class Dispatcher extends RoutingBase {
if ( ! array_key_exists('tokens', $route))
{
$routes[] = $this->router->$add($name, $path)->defaults($route);
continue;
}
else
{
$tokens = $route['tokens'];
unset($route['tokens']);
@ -398,7 +403,6 @@ final class Dispatcher extends RoutingBase {
->defaults($route)
->tokens($tokens);
}
}
return $routes;
}

View File

@ -4,19 +4,22 @@
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
* PHP version 7.3
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.1
* @version 4.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
namespace Aviat\AnimeClient;
use Aura\Html\HelperLocator;
use Aviat\Ion\Di\ContainerInterface;
use Aviat\Ion\Di\Exception\ContainerException;
use Aviat\Ion\Di\Exception\NotFoundException;
/**
* Helper object to manage form generation, especially for config editing
@ -25,7 +28,7 @@ final class FormGenerator {
/**
* Html generation helper
*
* @var \Aura\Html\HelperLocator
* @var HelperLocator
*/
private $helper;
@ -33,8 +36,8 @@ final class FormGenerator {
* FormGenerator constructor.
*
* @param ContainerInterface $container
* @throws \Aviat\Ion\Di\Exception\ContainerException
* @throws \Aviat\Ion\Di\Exception\NotFoundException
* @throws ContainerException
* @throws NotFoundException
*/
public function __construct(ContainerInterface $container)
{
@ -51,19 +54,21 @@ final class FormGenerator {
public function generate(string $name, array $form): string
{
$type = $form['type'];
$display = $form['display'] ?? TRUE;
$value = $form['value'] ?? '';
if ($form['display'] === FALSE)
if ($display === FALSE)
{
return $this->helper->input([
return (string)$this->helper->input([
'type' => 'hidden',
'name' => $name,
'value' => $form['value'],
'value' => $value,
]);
}
$params = [
'name' => $name,
'value' => $form['value'],
'value' => $value,
'attribs' => [
'id' => $name,
],
@ -92,7 +97,7 @@ final class FormGenerator {
foreach (['readonly', 'disabled'] as $key)
{
if ($form[$key] !== FALSE)
if (array_key_exists($key, $form) && $form[$key] !== FALSE)
{
$params['attribs'][$key] = $form[$key];
}

Some files were not shown because too many files have changed in this diff Show More