Version 5.1 - All the GraphQL #32

Closed
timw4mail wants to merge 1160 commits from develop into master
35 changed files with 83 additions and 134 deletions
Showing only changes of commit 73a69e42d3 - Show all commits

View File

@ -9,8 +9,8 @@ use ConsoleKit\Console;
$GLOBALS['_SERVER']['HTTP_HOST'] = 'localhost';
define('APP_DIR', __DIR__ . '/app');
define('TEMPLATE_DIR', APP_DIR . '/templates');
const APP_DIR = __DIR__ . '/app';
const TEMPLATE_DIR = APP_DIR . '/templates';
// -----------------------------------------------------------------------------
// Start console script

View File

@ -25,7 +25,7 @@ setlocale(LC_CTYPE, 'en_US');
// Load composer autoloader
require_once __DIR__ . '/vendor/autoload.php';
Debugger::$strictMode = E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED; // all errors except deprecated notices
Debugger::$strictMode = E_ALL & ~E_DEPRECATED; // all errors except deprecated notices
Debugger::$showBar = false;
Debugger::enable(Debugger::DEVELOPMENT, __DIR__ . '/app/logs');

View File

@ -154,7 +154,7 @@ abstract class APIRequestBuilder {
* Set a request header
*
* @param string $name
* @param string $value
* @param string|null $value
* @return self
*/
public function setHeader(string $name, string $value = NULL): self

View File

@ -70,7 +70,7 @@ abstract class AbstractListItem {
* Delete a list item
*
* @param string $id - The id of the list item to delete
* @return Request
* @return Request|null
*/
abstract public function delete(string $id):?Request;
}

View File

@ -207,7 +207,7 @@ final class Model
*
* @param FormItem $data
* @param string $type - Them media type (anime/manga)
* @return Request
* @return Request|null
*/
public function incrementListItem(FormItem $data, string $type): ?Request
{
@ -225,7 +225,7 @@ final class Model
*
* @param FormItem $data
* @param string $type - Them media type (anime/manga)
* @return Request
* @return Request|null
*/
public function updateListItem(FormItem $data, string $type): ?Request
{
@ -244,7 +244,7 @@ final class Model
*
* @param string $malId - The id of the list item to remove
* @param string $type - Them media type (anime/manga)
* @return Request
* @return Request|null
*/
public function deleteListItem(string $malId, string $type): ?Request
{
@ -262,7 +262,7 @@ final class Model
*
* @param string $malId
* @param string $type - The media type (anime/manga)
* @return string
* @return string|null
*/
public function getListIdFromMalId(string $malId, string $type): ?string
{
@ -306,7 +306,7 @@ final class Model
*
* @param string $malId
* @param string $type
* @return string
* @return string|null
*/
private function getMediaIdFromMalId(string $malId, string $type = 'ANIME'): ?string
{

View File

@ -257,24 +257,18 @@ final class RequestBuilder extends APIRequestBuilder {
$validResponseCodes = [200, 201];
$logger = $this->container->getLogger('anilist-request');
if ($logger !== NULL)
{
$logger->debug('Anilist response', [
'status' => $response->getStatus(),
'reason' => $response->getReason(),
'body' => $response->getBody(),
'headers' => $response->getHeaders(),
//'requestHeaders' => $request->getHeaders(),
]);
}
$logger?->debug('Anilist response', [
'status' => $response->getStatus(),
'reason' => $response->getReason(),
'body' => $response->getBody(),
'headers' => $response->getHeaders(),
//'requestHeaders' => $request->getHeaders(),
]);
if ( ! \in_array($response->getStatus(), $validResponseCodes, TRUE))
{
if ($logger !== NULL)
{
$logger->warning('Non 200 response for POST api call', (array)$response->getBody());
}
$logger?->warning('Non 200 response for POST api call', (array)$response->getBody());
}
$rawBody = wait($response->getBody()->buffer());

View File

@ -24,6 +24,7 @@ use Aviat\AnimeClient\Types\{AnimeListItem, FormItem};
use Aviat\Ion\Transformer\AbstractTransformer;
use DateTime;
use DateTimeInterface;
class AnimeListTransformer extends AbstractTransformer {
@ -57,7 +58,7 @@ class AnimeListTransformer extends AbstractTransformer {
: AnimeWatchingStatus::ANILIST_TO_KITSU[$item['status']],
'updatedAt' => (new DateTime())
->setTimestamp($item['updatedAt'])
->format(DateTime::W3C)
->format(DateTimeInterface::W3C)
],
]);
}

View File

@ -25,6 +25,7 @@ use Aviat\AnimeClient\Types\FormItem;
use Aviat\Ion\Transformer\AbstractTransformer;
use DateTime;
use DateTimeInterface;
class MangaListTransformer extends AbstractTransformer {
@ -58,7 +59,7 @@ class MangaListTransformer extends AbstractTransformer {
: MangaReadingStatus::ANILIST_TO_KITSU[$item['status']],
'updatedAt' => (new DateTime())
->setTimestamp($item['updatedAt'])
->format(DateTime::W3C),
->format(DateTimeInterface::W3C),
]
]);
}

View File

@ -19,10 +19,8 @@ namespace Aviat\AnimeClient\API\Anilist\Types;
use Aviat\AnimeClient\Types\AbstractType;
class MediaListEntry extends AbstractType {
/**
* @var int|string
*/
public $id;
public int|string $id;
public ?string $notes;

View File

@ -17,7 +17,6 @@
namespace Aviat\AnimeClient\API;
use Psr\SimpleCache\CacheInterface;
use Psr\SimpleCache\InvalidArgumentException;
/**
* Helper methods for dealing with the Cache

View File

@ -23,7 +23,6 @@ use const Aviat\AnimeClient\SESSION_SEGMENT;
use Aviat\AnimeClient\Kitsu as K;
use Aviat\AnimeClient\API\CacheTrait;
use Aviat\Ion\Di\{ContainerAware, ContainerInterface};
use Aviat\Ion\Di\Exception\{ContainerException, NotFoundException};
use Aviat\Ion\Event;
/**
@ -129,11 +128,11 @@ final class Auth {
{
if (PHP_SAPI === 'cli')
{
return $this->segment->get('auth_token', NULL)
?? $this->cache->get(K::AUTH_TOKEN_CACHE_KEY, NULL);
return $this->segment->get('auth_token')
?? $this->cache->get(K::AUTH_TOKEN_CACHE_KEY);
}
return $this->segment->get('auth_token', NULL);
return $this->segment->get('auth_token');
}
/**
@ -146,7 +145,7 @@ final class Auth {
if (PHP_SAPI === 'cli')
{
return $this->segment->get('refresh_token')
?? $this->cache->get(K::AUTH_TOKEN_REFRESH_CACHE_KEY, NULL);
?? $this->cache->get(K::AUTH_TOKEN_REFRESH_CACHE_KEY);
}
return $this->segment->get('refresh_token');

View File

@ -16,17 +16,10 @@
namespace Aviat\AnimeClient\API\Kitsu;
use Aviat\Ion\Di\Exception\ContainerException;
use Aviat\Ion\Di\Exception\NotFoundException;
use function Amp\Promise\wait;
use function Aviat\AnimeClient\getResponse;
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;

View File

@ -18,7 +18,6 @@ namespace Aviat\AnimeClient\API\Kitsu;
use Amp\Http\Client\Request;
use Aviat\AnimeClient\Types\FormItem;
use Aviat\Banker\Exception\InvalidArgumentException;
/**
* Kitsu API calls that mutate data, C/U/D parts of CRUD

View File

@ -192,16 +192,13 @@ final class RequestBuilder extends APIRequestBuilder {
$request = $this->setUpRequest($type, $url, $options);
$response = getResponse($request);
if ($logger !== NULL)
{
$logger->debug('Kitsu API Response', [
'status' => $response->getStatus(),
'reason' => $response->getReason(),
'body' => $response->getBody(),
'headers' => $response->getHeaders(),
'requestHeaders' => $request->getHeaders(),
]);
}
$logger?->debug('Kitsu API Response', [
'status' => $response->getStatus(),
'reason' => $response->getReason(),
'body' => $response->getBody(),
'headers' => $response->getHeaders(),
'requestHeaders' => $request->getHeaders(),
]);
return $response;
}

View File

@ -27,7 +27,7 @@ trait RequestBuilderTrait {
* Set the request builder object
*
* @param RequestBuilder $requestBuilder
* @return $this
* @return RequestBuilderTrait|ListItem|Model
*/
public function setRequestBuilder(RequestBuilder $requestBuilder): self
{

View File

@ -16,7 +16,6 @@
namespace Aviat\AnimeClient\Command;
use Aviat\AnimeClient\Kitsu;
use Aviat\Ion\Di\Exception\ContainerException;
use Aviat\Ion\Di\Exception\NotFoundException;
use function Aviat\AnimeClient\clearCache;

View File

@ -203,7 +203,7 @@ final class SyncLists extends BaseCommand {
*
* @param string $type
* @param array $data
* @return array|array[]
* @return array
*/
protected function compare(string $type, array $data): array
{

View File

@ -375,10 +375,10 @@ class Controller {
* @param array $data
* @param HtmlView|NULL $view
* @param int $code
* @throws InvalidArgumentException
* @return void
*@throws InvalidArgumentException
*/
protected function outputHTML(string $template, array $data = [], $view = NULL, int $code = 200): void
protected function outputHTML(string $template, array $data = [], HtmlView $view = NULL, int $code = 200): void
{
if (NULL === $view)
{

View File

@ -66,15 +66,13 @@ final class Anime extends BaseController {
/**
* Show a portion, or all of the anime list
*
* @param string|int $status - The section of the list
* @param int|string $status - The section of the list
* @param string|null $view - List or cover view
* @throws ContainerException
* @throws NotFoundException
* @return void
* @throws InvalidArgumentException
* @throws Throwable
* @return void
*/
public function index($status = KitsuWatchingStatus::WATCHING, ?string $view = NULL): void
public function index(int|string $status = KitsuWatchingStatus::WATCHING, ?string $view = NULL): void
{
if ( ! in_array($status, [
'all',
@ -178,7 +176,7 @@ final class Anime extends BaseController {
* @param string $id
* @param string $status
*/
public function edit(string $id, $status = 'all'): void
public function edit(string $id, string $status = 'all'): void
{
$this->checkAuth();

View File

@ -239,8 +239,6 @@ final class AnimeCollection extends BaseController {
* Update a collection item
*
* @param array $data
* @throws ContainerException
* @throws NotFoundException
*/
protected function update(array $data): void
{

View File

@ -78,8 +78,6 @@ final class History extends BaseController {
'url_type' => 'anime',
]);
// $this->outputJSON($this->animeModel->getHistory());
// return;
$this->outputHTML('history', [
'title' => $this->formatTitle(
$this->config->get('whose_list') . "'s Anime List",
@ -98,8 +96,6 @@ final class History extends BaseController {
'url_type' => 'manga',
]);
// $this->outputJSON($this->mangaModel->getHistory());
// return;
$this->outputHTML('history', [
'title' => $this->formatTitle(
$this->config->get('whose_list') . "'s Manga List",

View File

@ -16,8 +16,6 @@
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;
@ -39,7 +37,7 @@ final class Images extends BaseController {
* @return void
* @throws Throwable
*/
public function cache(string $type, string $file, $display = TRUE): void
public function cache(string $type, string $file, bool $display = TRUE): void
{
$currentUrl = (string)$this->request->getUri();

View File

@ -64,10 +64,10 @@ final class Manga extends Controller {
*
* @param string $status
* @param string $view
* @throws InvalidArgumentException
* @return void
*@throws InvalidArgumentException
*/
public function index($status = 'all', $view = ''): void
public function index(string $status = 'all', string $view = ''): void
{
if ( ! in_array($status, [
'all',

View File

@ -52,8 +52,6 @@ final class People extends BaseController {
*
* @param string $slug
* @return void
* @throws ContainerException
* @throws NotFoundException
*/
public function index(string $slug): void
{

View File

@ -16,6 +16,8 @@
namespace Aviat\AnimeClient;
use Aviat\AnimeClient\Enum\EventType;
use Aviat\Ion\Event;
use Aviat\Ion\Json;
use Aura\Router\{
Map,
@ -27,7 +29,6 @@ use Aviat\AnimeClient\API\FailedResponseException;
use Aviat\Ion\Di\ContainerInterface;
use Aviat\Ion\Friend;
use Aviat\Ion\Type\StringType;
use JetBrains\PhpStorm\ArrayShape;
use LogicException;
use ReflectionException;
@ -117,7 +118,7 @@ final class Dispatcher extends RoutingBase {
* @return void
* @throws ReflectionException
*/
public function __invoke($route = NULL): void
public function __invoke(object $route = NULL): void
{
$logger = $this->container->getLogger();
@ -136,7 +137,7 @@ final class Dispatcher extends RoutingBase {
{
// If not route was matched, return an appropriate http
// error message
$errorRoute = (array)$this->getErrorParams();
$errorRoute = $this->getErrorParams();
$controllerName = DEFAULT_CONTROLLER;
$actionMethod = $errorRoute['action_method'];
$params = $errorRoute['params'];
@ -278,17 +279,14 @@ final class Dispatcher extends RoutingBase {
*/
protected function call(string $controllerName, string $method, array $params): void
{
$logger = $this->container->getLogger('default');
$logger = $this->container->getLogger();
try
{
$controller = new $controllerName($this->container);
// Run the appropriate controller method
if ($logger !== NULL)
{
$logger->debug('Dispatcher - controller arguments', $params);
}
$logger?->debug('Dispatcher - controller arguments', $params);
$params = array_values($params);
$controller->$method(...$params);
@ -360,7 +358,7 @@ final class Dispatcher extends RoutingBase {
}
/**
* Select controller based on the current url, and apply its relevent routes
* Select controller based on the current url, and apply its relevant routes
*
* @return array
*/

View File

@ -16,17 +16,8 @@
namespace Aviat\AnimeClient\Model;
use Aviat\AnimeClient\API\ParallelAPIRequest;
use Aviat\AnimeClient\API\Mapping\AnimeWatchingStatus;
use Aviat\AnimeClient\Types\{
Anime as AnimeType,
FormItem,
AnimeListItem
};
use Aviat\Ion\Json;
use Throwable;
use function is_array;
use Aviat\AnimeClient\Types\Anime as AnimeType;
/**
* Model for handling requests dealing with the anime list
@ -64,7 +55,7 @@ class Anime extends API {
{
$data = $this->kitsuModel->getFullOrganizedAnimeList();
foreach($data as $section => &$list)
foreach($data as &$list)
{
$this->sortByName($list, 'anime');
}

View File

@ -578,7 +578,7 @@ final class AnimeCollection extends Collection {
* @param string $animeId The current anime
* @return void
*/
private function updateGenres($animeId): void
private function updateGenres(string $animeId): void
{
if ($this->db === NULL)
{

View File

@ -46,8 +46,6 @@ class Util {
* Set up the Util class
*
* @param ContainerInterface $container
* @throws ContainerException
* @throws NotFoundException
*/
public function __construct(ContainerInterface $container)
{

View File

@ -45,10 +45,10 @@ class Config implements ConfigInterface {
/**
* Does the config item exist?
*
* @param string|int|array $key
* @param array|int|string $key
* @return bool
*/
public function has($key): bool
public function has(array|int|string $key): bool
{
return $this->map->hasKey($key);
}
@ -60,7 +60,7 @@ class Config implements ConfigInterface {
* @return mixed
* @throws ConfigException
*/
public function get($key = NULL)
public function get(array|string $key = NULL): mixed
{
if (\is_array($key))
{
@ -73,10 +73,10 @@ class Config implements ConfigInterface {
/**
* Remove a config value
*
* @param string|array $key
* @param array|string $key
* @return void
*/
public function delete($key): void
public function delete(array|string $key): void
{
if (\is_array($key))
{
@ -92,12 +92,12 @@ class Config implements ConfigInterface {
/**
* Set a config value
*
* @param integer|string|array $key
* @param mixed $value
* @throws InvalidArgumentException
* @param array|integer|string $key
* @param mixed $value
* @return ConfigInterface
*@throws InvalidArgumentException
*/
public function set($key, $value): ConfigInterface
public function set(array|int|string $key, mixed $value): ConfigInterface
{
if (\is_array($key))
{

View File

@ -23,10 +23,10 @@ interface ConfigInterface {
/**
* Does the config item exist?
*
* @param string|int|array $key
* @param array|int|string $key
* @return bool
*/
public function has($key): bool;
public function has(array|int|string $key): bool;
/**
* Get a config value
@ -34,23 +34,23 @@ interface ConfigInterface {
* @param array|string|null $key
* @return mixed
*/
public function get($key = NULL);
public function get(array|string $key = NULL): mixed;
/**
* Set a config value
*
* @param integer|string|array $key
* @param array|integer|string $key
* @param mixed $value
* @throws \InvalidArgumentException
* @return ConfigInterface
* @throws \InvalidArgumentException
*/
public function set($key, $value): self;
public function set(array|int|string $key, mixed $value): self;
/**
* Remove a config value
*
* @param string|array $key
* @param array|string $key
* @return void
*/
public function delete($key): void;
public function delete(array|string $key): void;
}

View File

@ -51,7 +51,7 @@ abstract class Enum {
* @return boolean
* @throws ReflectionException
*/
public static function isValid($key): bool
public static function isValid(mixed $key): bool
{
$values = array_values(static::getConstList());
return in_array($key, $values, TRUE);

View File

@ -31,7 +31,7 @@ class Friend {
* Object to create a friend of
* @var mixed
*/
private $_friend_;
private mixed $_friend_;
/**
* Reflection class of the object
@ -46,7 +46,7 @@ class Friend {
* @throws InvalidArgumentException
* @throws \ReflectionException
*/
public function __construct($obj)
public function __construct(mixed $obj)
{
if ( ! \is_object($obj))
{
@ -63,7 +63,7 @@ class Friend {
* @param string $key
* @return mixed
*/
public function __get(string $key)
public function __get(string $key): mixed
{
if ($this->__isset($key))
{
@ -96,7 +96,7 @@ class Friend {
* @param mixed $value
* @return void
*/
public function __set(string $key, $value)
public function __set(string $key, mixed $value)
{
if ($this->__isset($key))
{

View File

@ -93,7 +93,7 @@ class HttpView implements HttpViewInterface{
* @param string|string[] $value
* @return HttpView
*/
public function addHeader(string $name, $value): self
public function addHeader(string $name, array|string $value): self
{
$this->response = $this->response->withHeader($name, $value);
return $this;
@ -105,7 +105,7 @@ class HttpView implements HttpViewInterface{
* @param mixed $string
* @return HttpViewInterface
*/
public function setOutput($string): HttpViewInterface
public function setOutput(mixed $string): HttpViewInterface
{
$this->response->getBody()->write($string);

View File

@ -37,7 +37,7 @@ interface ViewInterface {
* @param mixed $string
* @return ViewInterface
*/
public function setOutput($string): self;
public function setOutput(mixed $string): self;
/**
* Append additional output.
@ -54,7 +54,7 @@ interface ViewInterface {
* @param string|string[] $value
* @return ViewInterface
*/
public function addHeader(string $name, $value): self;
public function addHeader(string $name, array|string $value): self;
/**
* Get the current output as a string. Does not

View File

@ -20,7 +20,7 @@ use Aviat\Ion\Config;
class ConfigTest extends IonTestCase {
protected $config;
protected Config $config;
public function setUp(): void
{
@ -66,12 +66,6 @@ class ConfigTest extends IonTestCase {
$this->assertEquals('great', $this->config->get(['apple', 'sauce', 'is']), "Array argument get for config failed.");
}
public function testConfigBadSet(): void
{
$this->expectException('InvalidArgumentException');
$this->config->set(NULL, FALSE);
}
public function dataConfigDelete(): array
{
return [