Do you wish to register an account?
Browse Source

Merge remote-tracking branch 'origin/develop'

master
Timothy Warren 1 week ago
parent
commit
472f13ee62
16 changed files with 94 additions and 65 deletions
  1. +5
    -2
      Jenkinsfile
  2. +1
    -1
      index.php
  3. +1
    -0
      phpstan.neon
  4. +2
    -3
      src/AnimeClient/API/APIRequestBuilder.php
  5. +4
    -4
      src/AnimeClient/API/Anilist/ListItem.php
  6. +4
    -0
      src/AnimeClient/API/Anilist/Model.php
  7. +35
    -22
      src/AnimeClient/API/Anilist/RequestBuilder.php
  8. +2
    -1
      src/AnimeClient/API/CacheTrait.php
  9. +0
    -5
      src/AnimeClient/API/Kitsu/ListItem.php
  10. +7
    -8
      src/AnimeClient/API/Kitsu/Model.php
  11. +22
    -10
      src/AnimeClient/API/Kitsu/RequestBuilder.php
  12. +1
    -1
      src/AnimeClient/API/Kitsu/Transformer/AnimeTransformer.php
  13. +6
    -4
      src/AnimeClient/Command/SyncLists.php
  14. +2
    -2
      src/AnimeClient/Controller/Anime.php
  15. +1
    -1
      src/AnimeClient/Controller/AnimeCollection.php
  16. +1
    -1
      src/AnimeClient/Controller/Images.php

+ 5
- 2
Jenkinsfile View File

@ -37,8 +37,11 @@ pipeline {
stage('Code Cleanliness') {
agent any
steps {
sh "php8 ./vendor/bin/phpstan analyse -c phpstan.neon -n --no-ansi --no-progress --error-format=checkstyle | awk '{\$1=\$1;print}' > build/logs/checkstyle-result.xml"
recordIssues(tools: [checkStyle(reportEncoding: 'UTF-8')])
sh "php8 ./vendor/bin/phpstan analyse -c phpstan.neon -n --no-progress --no-ansi --error-format=checkstyle | awk '{\$1=\$1;print}' > build/logs/phpstan.log"
recordIssues(
failOnError: false,
tools: [phpStan(reportEncoding: 'UTF-8', pattern: 'build/logs/phpstan.log')]
)
}
}
stage('Coverage') {


+ 1
- 1
index.php View File

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


+ 1
- 0
phpstan.neon View File

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


+ 2
- 3
src/AnimeClient/API/APIRequestBuilder.php View File

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


+ 4
- 4
src/AnimeClient/API/Anilist/ListItem.php View File

@ -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 ?? []);
}
}

+ 4
- 0
src/AnimeClient/API/Anilist/Model.php View File

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


+ 35
- 22
src/AnimeClient/API/Anilist/RequestBuilder.php View File

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


+ 2
- 1
src/AnimeClient/API/CacheTrait.php View File

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


+ 0
- 5
src/AnimeClient/API/Kitsu/ListItem.php View File

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


+ 7
- 8
src/AnimeClient/API/Kitsu/Model.php View File

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


+ 22
- 10
src/AnimeClient/API/Kitsu/RequestBuilder.php View File

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


+ 1
- 1
src/AnimeClient/API/Kitsu/Transformer/AnimeTransformer.php View File

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


+ 6
- 4
src/AnimeClient/Command/SyncLists.php View File

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


+ 2
- 2
src/AnimeClient/Controller/Anime.php View File

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


+ 1
- 1
src/AnimeClient/Controller/AnimeCollection.php View File

@ -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) : []
]);
}


+ 1
- 1
src/AnimeClient/Controller/Images.php View File

@ -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…
Cancel
Save