Version 5.1 - All the GraphQL #32
@ -60,7 +60,7 @@ $checkedConfig = ConfigType::check($configArray);
|
||||
// First look in app config, then PHP config, and at last
|
||||
// resort, just set to UTC.
|
||||
$timezone = ini_get('date.timezone');
|
||||
if (array_key_exists('timezone', $checkedConfig) && ! empty($checkedConfig['timezone']))
|
||||
if (is_array($checkedConfig) && array_key_exists('timezone', $checkedConfig) && ! empty($checkedConfig['timezone']))
|
||||
{
|
||||
date_default_timezone_set($checkedConfig['timezone']);
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ parameters:
|
||||
- '#Function imagepalletetotruecolor not found#'
|
||||
- '#Call to an undefined method Aura\\\Html\\\HelperLocator::[a-zA-Z0-9_]+\(\)#'
|
||||
- '#Call to an undefined method Query\\QueryBuilderInterface::[a-zA-Z0-9_]+\(\)#'
|
||||
- '#Unable to resolve the template type TValue#'
|
||||
excludes_analyse:
|
||||
- tests/mocks.php
|
||||
- vendor
|
||||
|
@ -193,12 +193,11 @@ abstract class APIRequestBuilder {
|
||||
* Set the request body
|
||||
*
|
||||
* @param mixed $body
|
||||
* @throws \TypeError
|
||||
* @return self
|
||||
*/
|
||||
public function setJsonBody($body): self
|
||||
public function setJsonBody(mixed $body): self
|
||||
{
|
||||
$requestBody = ( ! is_scalar($body))
|
||||
$requestBody = ( ! is_string($body))
|
||||
? Json::encode($body)
|
||||
: $body;
|
||||
|
||||
|
@ -38,7 +38,7 @@ final class ListItem extends AbstractListItem {
|
||||
public function create(array $data): Request
|
||||
{
|
||||
$checkedData = Types\MediaListEntry::check($data);
|
||||
return $this->requestBuilder->mutateRequest('CreateMediaListEntry', $checkedData);
|
||||
return $this->requestBuilder->mutateRequest('CreateMediaListEntry', $checkedData ?? []);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -50,7 +50,7 @@ final class ListItem extends AbstractListItem {
|
||||
public function createFull(array $data): Request
|
||||
{
|
||||
$checkedData = Types\MediaListEntry::check($data);
|
||||
return $this->requestBuilder->mutateRequest('CreateFullMediaListEntry', $checkedData);
|
||||
return $this->requestBuilder->mutateRequest('CreateFullMediaListEntry', $checkedData ?? []);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,7 +90,7 @@ final class ListItem extends AbstractListItem {
|
||||
'progress' => $data->progress,
|
||||
]);
|
||||
|
||||
return $this->requestBuilder->mutateRequest('IncrementMediaListEntry', $checkedData);
|
||||
return $this->requestBuilder->mutateRequest('IncrementMediaListEntry', $checkedData ?? []);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -120,6 +120,6 @@ final class ListItem extends AbstractListItem {
|
||||
'notes' => $notes,
|
||||
]);
|
||||
|
||||
return $this->requestBuilder->mutateRequest('UpdateMediaListEntry', $updateData);
|
||||
return $this->requestBuilder->mutateRequest('UpdateMediaListEntry', $updateData ?? []);
|
||||
}
|
||||
}
|
@ -190,6 +190,10 @@ final class Model
|
||||
public function getListItem(string $malId, string $type): array
|
||||
{
|
||||
$id = $this->getListIdFromMalId($malId, $type);
|
||||
if ($id === NULL)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
$data = $this->listItem->get($id)['data'];
|
||||
|
||||
|
@ -205,13 +205,16 @@ final class RequestBuilder extends APIRequestBuilder {
|
||||
$request = $this->setUpRequest($url, $options);
|
||||
$response = getResponse($request);
|
||||
|
||||
$logger->debug('Anilist response', [
|
||||
'status' => $response->getStatus(),
|
||||
'reason' => $response->getReason(),
|
||||
'body' => $response->getBody(),
|
||||
'headers' => $response->getHeaders(),
|
||||
'requestHeaders' => $request->getHeaders(),
|
||||
]);
|
||||
if ($logger !== NULL)
|
||||
{
|
||||
$logger->debug('Anilist response', [
|
||||
'status' => $response->getStatus(),
|
||||
'reason' => $response->getReason(),
|
||||
'body' => $response->getBody(),
|
||||
'headers' => $response->getHeaders(),
|
||||
'requestHeaders' => $request->getHeaders(),
|
||||
]);
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
@ -227,13 +230,16 @@ final class RequestBuilder extends APIRequestBuilder {
|
||||
|
||||
$response = getResponse($request);
|
||||
|
||||
$logger->debug('Anilist response', [
|
||||
'status' => $response->getStatus(),
|
||||
'reason' => $response->getReason(),
|
||||
'body' => $response->getBody(),
|
||||
'headers' => $response->getHeaders(),
|
||||
'requestHeaders' => $request->getHeaders(),
|
||||
]);
|
||||
if ($logger !== NULL)
|
||||
{
|
||||
$logger->debug('Anilist response', [
|
||||
'status' => $response->getStatus(),
|
||||
'reason' => $response->getReason(),
|
||||
'body' => $response->getBody(),
|
||||
'headers' => $response->getHeaders(),
|
||||
'requestHeaders' => $request->getHeaders(),
|
||||
]);
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
@ -251,17 +257,24 @@ final class RequestBuilder extends APIRequestBuilder {
|
||||
$validResponseCodes = [200, 201];
|
||||
|
||||
$logger = $this->container->getLogger('anilist-request');
|
||||
$logger->debug('Anilist response', [
|
||||
'status' => $response->getStatus(),
|
||||
'reason' => $response->getReason(),
|
||||
'body' => $response->getBody(),
|
||||
'headers' => $response->getHeaders(),
|
||||
//'requestHeaders' => $request->getHeaders(),
|
||||
]);
|
||||
if ($logger !== NULL)
|
||||
{
|
||||
$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))
|
||||
{
|
||||
$logger->warning('Non 200 response for POST api call', (array)$response->getBody());
|
||||
if ($logger !== NULL)
|
||||
{
|
||||
$logger->warning('Non 200 response for POST api call', (array)$response->getBody());
|
||||
}
|
||||
}
|
||||
|
||||
$rawBody = wait($response->getBody()->buffer());
|
||||
|
@ -62,10 +62,11 @@ trait CacheTrait {
|
||||
*/
|
||||
public function getCached(string $key, callable $primer, ?array $primeArgs = []): mixed
|
||||
{
|
||||
$value = $this->cache->get($key, NULL);
|
||||
$value = $this->cache->get($key);
|
||||
|
||||
if ($value === NULL)
|
||||
{
|
||||
$primeArgs ??= [];
|
||||
$value = $primer(...$primeArgs);
|
||||
if ($value === NULL)
|
||||
{
|
||||
|
@ -166,11 +166,6 @@ final class ListItem extends AbstractListItem {
|
||||
return $this->requestBuilder->mutateRequest('UpdateLibraryItem', $updateData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool|string
|
||||
* @throws ContainerException
|
||||
* @throws NotFoundException
|
||||
*/
|
||||
private function getAuthHeader(): ?string
|
||||
{
|
||||
$auth = $this->getContainer()->get('auth');
|
||||
|
@ -89,9 +89,9 @@ final class Model {
|
||||
*
|
||||
* @param string $username
|
||||
* @param string $password
|
||||
* @return bool|array
|
||||
* @return array|false
|
||||
*/
|
||||
public function authenticate(string $username, string $password)
|
||||
public function authenticate(string $username, string $password): array|false
|
||||
{
|
||||
// K::AUTH_URL
|
||||
$response = $this->requestBuilder->getResponse('POST', K::AUTH_URL, [
|
||||
@ -131,9 +131,9 @@ final class Model {
|
||||
* Extend the current session with a refresh token
|
||||
*
|
||||
* @param string $token
|
||||
* @return bool|array
|
||||
* @return array|false
|
||||
*/
|
||||
public function reAuthenticate(string $token)
|
||||
public function reAuthenticate(string $token): array|false
|
||||
{
|
||||
$response = $this->requestBuilder->getResponse('POST', K::AUTH_URL, [
|
||||
'headers' => [
|
||||
@ -617,6 +617,7 @@ final class Model {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Get the data to sync Kitsu anime/manga list with another API
|
||||
*
|
||||
* @param string $type
|
||||
@ -708,11 +709,9 @@ final class Model {
|
||||
$page = $data['pageInfo'];
|
||||
if (empty($data))
|
||||
{
|
||||
// @TODO Proper Error logging
|
||||
dump($rawData);
|
||||
die();
|
||||
|
||||
// @TODO Error logging
|
||||
break;
|
||||
}
|
||||
|
||||
$cursor = $page['endCursor'];
|
||||
@ -812,7 +811,7 @@ final class Model {
|
||||
});
|
||||
}
|
||||
|
||||
private function getPages(callable $method, mixed ...$args): ?Generator
|
||||
private function getPages(callable $method, mixed ...$args): Generator
|
||||
{
|
||||
$items = $method(...$args);
|
||||
|
||||
|
@ -144,7 +144,10 @@ final class RequestBuilder extends APIRequestBuilder {
|
||||
if ( ! \in_array($response->getStatus(), $validResponseCodes, TRUE))
|
||||
{
|
||||
$logger = $this->container->getLogger('kitsu-graphql');
|
||||
$logger->warning('Non 200 response for GraphQL call', (array)$response->getBody());
|
||||
if ($logger !== NULL)
|
||||
{
|
||||
$logger->warning('Non 200 response for GraphQL call', (array)$response->getBody());
|
||||
}
|
||||
}
|
||||
|
||||
return Json::decode(wait($response->getBody()->buffer()));
|
||||
@ -166,7 +169,10 @@ final class RequestBuilder extends APIRequestBuilder {
|
||||
if ( ! \in_array($response->getStatus(), $validResponseCodes, TRUE))
|
||||
{
|
||||
$logger = $this->container->getLogger('kitsu-graphql');
|
||||
$logger->warning('Non 200 response for GraphQL call', (array)$response->getBody());
|
||||
if ($logger !== NULL)
|
||||
{
|
||||
$logger->warning('Non 200 response for GraphQL call', (array)$response->getBody());
|
||||
}
|
||||
}
|
||||
|
||||
return Json::decode(wait($response->getBody()->buffer()));
|
||||
@ -186,13 +192,16 @@ final class RequestBuilder extends APIRequestBuilder {
|
||||
$request = $this->setUpRequest($type, $url, $options);
|
||||
$response = getResponse($request);
|
||||
|
||||
$logger->debug('Kitsu API Response', [
|
||||
'status' => $response->getStatus(),
|
||||
'reason' => $response->getReason(),
|
||||
'body' => $response->getBody(),
|
||||
'headers' => $response->getHeaders(),
|
||||
'requestHeaders' => $request->getHeaders(),
|
||||
]);
|
||||
if ($logger !== NULL)
|
||||
{
|
||||
$logger->debug('Kitsu API Response', [
|
||||
'status' => $response->getStatus(),
|
||||
'reason' => $response->getReason(),
|
||||
'body' => $response->getBody(),
|
||||
'headers' => $response->getHeaders(),
|
||||
'requestHeaders' => $request->getHeaders(),
|
||||
]);
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
@ -289,7 +298,10 @@ final class RequestBuilder extends APIRequestBuilder {
|
||||
// Any other type of failed request
|
||||
if ($statusCode > 299 || $statusCode < 200)
|
||||
{
|
||||
$logger->warning('Non 2xx response for api call', (array)$response);
|
||||
if ($logger !== NULL)
|
||||
{
|
||||
$logger->warning('Non 2xx response for api call', (array)$response);
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
|
@ -43,7 +43,7 @@ final class AnimeTransformer extends AbstractTransformer {
|
||||
|
||||
sort($genres);
|
||||
|
||||
$title = $base['titles']['canonical'];
|
||||
$title = $base['titles']['canonical'] ?? '';
|
||||
$titles = Kitsu::getTitles($base['titles']);
|
||||
$titles_more = Kitsu::filterLocalizedTitles($base['titles']);
|
||||
|
||||
|
@ -727,7 +727,7 @@ final class SyncLists extends BaseCommand {
|
||||
$this->echoWarning("Skipped creating Kitsu {$type} due to missing id ¯\_(ツ)_/¯");
|
||||
continue;
|
||||
}
|
||||
$requester->addRequest($this->kitsuModel->createListItem($item));
|
||||
$requester->addRequest($maybeRequest);
|
||||
}
|
||||
}
|
||||
|
||||
@ -785,9 +785,11 @@ final class SyncLists extends BaseCommand {
|
||||
{
|
||||
if ($action === SyncAction::UPDATE)
|
||||
{
|
||||
$requester->addRequest(
|
||||
$this->anilistModel->updateListItem(FormItem::from($item), $type)
|
||||
);
|
||||
$maybeRequest = $this->anilistModel->updateListItem(FormItem::from($item), $type);
|
||||
if ($maybeRequest !== NULL)
|
||||
{
|
||||
$requester->addRequest($maybeRequest);
|
||||
}
|
||||
}
|
||||
else if ($action === SyncAction::CREATE)
|
||||
{
|
||||
|
@ -329,7 +329,7 @@ final class Anime extends BaseController {
|
||||
'title' => $this->formatTitle(
|
||||
$this->config->get('whose_list') . "'s Anime List",
|
||||
'Anime',
|
||||
$data->title
|
||||
$data->title ?? ''
|
||||
),
|
||||
'data' => $data,
|
||||
]);
|
||||
@ -367,7 +367,7 @@ final class Anime extends BaseController {
|
||||
'title' => $this->formatTitle(
|
||||
$this->config->get('whose_list') . "'s Anime List",
|
||||
'Anime',
|
||||
$data->title
|
||||
$data->title ?? ''
|
||||
),
|
||||
'data' => $data,
|
||||
]);
|
||||
|
@ -139,7 +139,7 @@ final class AnimeCollection extends BaseController {
|
||||
$action
|
||||
),
|
||||
'media_items' => $this->animeCollectionModel->getMediaTypeList(),
|
||||
'item' => ($action === 'Edit') ? $this->animeCollectionModel->get($id) : []
|
||||
'item' => ($action === 'Edit' && $id !== NULL) ? $this->animeCollectionModel->get($id) : []
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -166,7 +166,7 @@ final class Images extends BaseController {
|
||||
{
|
||||
$contentType = ($ext === 'webp')
|
||||
? 'image/webp'
|
||||
: $response->getHeader('content-type')[0];
|
||||
: $response->getHeader('content-type')[0] ?? 'image/jpeg';
|
||||
|
||||
$outputFile = (str_contains($file, '-original'))
|
||||
? "{$filePrefix}-original.{$ext}"
|
||||
|
Loading…
Reference in New Issue
Block a user