Do you wish to register an account?
Browse Source

Refactor, increase test coverage

pull/36/head
Timothy Warren 2 months ago
parent
commit
292d9bbaaf
44 changed files with 200 additions and 415 deletions
  1. +2
    -2
      RoboFile.php
  2. +9
    -9
      app/appConf/routes.php
  3. +1
    -1
      src/AnimeClient/API/Anilist/Model.php
  4. +1
    -1
      src/AnimeClient/API/Anilist/RequestBuilder.php
  5. +1
    -2
      src/AnimeClient/API/Anilist/RequestBuilderTrait.php
  6. +0
    -18
      src/AnimeClient/API/Anilist/Types/MediaListEntry.php
  7. +5
    -5
      src/AnimeClient/API/Kitsu/Model.php
  8. +1
    -1
      src/AnimeClient/Anilist.php
  9. +2
    -2
      src/AnimeClient/AnimeClient.php
  10. +35
    -34
      src/AnimeClient/Command/SyncLists.php
  11. +2
    -2
      src/AnimeClient/Command/UpdateThumbnails.php
  12. +1
    -0
      src/AnimeClient/Component/VerticalTabs.php
  13. +0
    -8
      src/AnimeClient/Controller.php
  14. +12
    -12
      src/AnimeClient/Controller/Anime.php
  15. +1
    -1
      src/AnimeClient/Controller/AnimeCollection.php
  16. +3
    -13
      src/AnimeClient/Controller/Manga.php
  17. +4
    -2
      src/AnimeClient/Enum/API.php
  18. +2
    -2
      src/AnimeClient/Enum/MediaType.php
  19. +2
    -1
      src/AnimeClient/Helper/Picture.php
  20. +5
    -5
      src/AnimeClient/Kitsu.php
  21. +1
    -0
      src/AnimeClient/Model/AnimeCollection.php
  22. +1
    -1
      src/AnimeClient/Model/DB.php
  23. +0
    -52
      src/AnimeClient/Types/Anime.php
  24. +1
    -30
      src/AnimeClient/Types/AnimeListItem.php
  25. +0
    -9
      src/AnimeClient/Types/AnimePage.php
  26. +0
    -21
      src/AnimeClient/Types/Character.php
  27. +0
    -6
      src/AnimeClient/Types/Characters.php
  28. +2
    -51
      src/AnimeClient/Types/Config.php
  29. +13
    -34
      src/AnimeClient/Types/Config/Anilist.php
  30. +8
    -5
      src/AnimeClient/Types/Config/Cache.php
  31. +12
    -12
      src/AnimeClient/Types/Config/Database.php
  32. +1
    -7
      src/AnimeClient/Types/FormItem.php
  33. +0
    -11
      src/AnimeClient/Types/FormItemData.php
  34. +9
    -9
      src/AnimeClient/Types/HistoryItem.php
  35. +0
    -6
      src/AnimeClient/Types/Media.php
  36. +0
    -27
      src/AnimeClient/Types/User.php
  37. +1
    -1
      src/Ion/Event.php
  38. +1
    -1
      src/Ion/Friend.php
  39. +1
    -0
      src/Ion/View/HttpView.php
  40. +6
    -0
      tests/AnimeClient/UtilTest.php
  41. +29
    -0
      tests/Ion/EventTest.php
  42. +1
    -1
      tests/Ion/View/HtmlViewTest.php
  43. +21
    -7
      tests/Ion/View/HttpViewTest.php
  44. +3
    -3
      tests/Ion/View/JsonViewTest.php

+ 2
- 2
RoboFile.php View File

@ -30,7 +30,7 @@ class RoboFile extends Tasks {
*
* @var array
*/
protected $taskDirs = [
protected array $taskDirs = [
'build/logs',
'build/pdepend',
'build/phpdox',
@ -41,7 +41,7 @@ class RoboFile extends Tasks {
*
* @var array
*/
protected $cleanDirs = [
protected array $cleanDirs = [
'coverage',
'docs',
'phpdoc',


+ 9
- 9
app/appConf/routes.php View File

@ -255,6 +255,13 @@ $routes = [
'path' => '/logout',
'action' => 'logout',
],
'history' => [
'controller' => 'history',
'path' => '/history/{type}',
'tokens' => [
'type' => SLUG_PATTERN
]
],
'increment' => [
'path' => '/{controller}/increment',
'action' => 'increment',
@ -288,19 +295,12 @@ $routes = [
],
],
'list' => [
'path' => '/{controller}/{type}{/view}',
'path' => '/{controller}/{status}{/view}',
'tokens' => [
'type' => ALPHA_SLUG_PATTERN,
'status' => ALPHA_SLUG_PATTERN,
'view' => ALPHA_SLUG_PATTERN,
],
],
'history' => [
'controller' => 'history',
'path' => '/history/{type}',
'tokens' => [
'type' => SLUG_PATTERN
]
],
'index_redirect' => [
'path' => '/',
'action' => 'redirectToDefaultRoute',


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

@ -21,7 +21,7 @@ use function Amp\Promise\wait;
use InvalidArgumentException;
use Amp\Http\Client\Request;
use Aviat\AnimeClient\API\Anilist;
use Aviat\AnimeClient\Anilist;
use Aviat\AnimeClient\API\Mapping\{AnimeWatchingStatus, MangaReadingStatus};
use Aviat\AnimeClient\Types\FormItem;
use Aviat\Ion\Json;


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

@ -18,7 +18,7 @@ namespace Aviat\AnimeClient\API\Anilist;
use Amp\Http\Client\Request;
use Amp\Http\Client\Response;
use Aviat\AnimeClient\API\Anilist;
use Aviat\AnimeClient\Anilist;
use Aviat\Ion\Di\ContainerAware;
use Aviat\Ion\Di\ContainerInterface;
use Aviat\Ion\Json;


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

@ -23,7 +23,6 @@ trait RequestBuilderTrait {
/**
* The request builder for the Anilist API
* @var RequestBuilder
*/
protected RequestBuilder $requestBuilder;
@ -33,7 +32,7 @@ trait RequestBuilderTrait {
* @param RequestBuilder $requestBuilder
* @return self
*/
public function setRequestBuilder($requestBuilder): self
public function setRequestBuilder(RequestBuilder $requestBuilder): self
{
$this->requestBuilder = $requestBuilder;
return $this;


+ 0
- 18
src/AnimeClient/API/Anilist/Types/MediaListEntry.php View File

@ -24,33 +24,15 @@ class MediaListEntry extends AbstractType {
*/
public $id;
/**
* @var string|null
*/
public ?string $notes;
/**
* @var bool
*/
public ?bool $private;
/**
* @var int
*/
public int $progress;
/**
* @var int
*/
public ?int $repeat;
/**
* @var string
*/
public string $status;
/**
* @var int
*/
public ?int $score;
}

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

@ -33,7 +33,7 @@ use Aviat\AnimeClient\API\Kitsu\Transformer\{
MangaListTransformer,
MangaTransformer
};
use Aviat\AnimeClient\Enum\ListType;
use Aviat\AnimeClient\Enum\MediaType;
use Aviat\AnimeClient\Kitsu as K;
use Aviat\AnimeClient\Types\Anime;
use Aviat\AnimeClient\Types\MangaPage;
@ -319,7 +319,7 @@ final class Model {
if ($list === NULL)
{
$data = $this->getList(ListType::ANIME, $status) ?? [];
$data = $this->getList(MediaType::ANIME, $status) ?? [];
// Bail out on no data
if (empty($data))
@ -352,7 +352,7 @@ final class Model {
*/
public function getAnimeListCount(string $status = '') : int
{
return $this->getListCount(ListType::ANIME, $status);
return $this->getListCount(MediaType::ANIME, $status);
}
/**
@ -462,7 +462,7 @@ final class Model {
if ($list === NULL)
{
$data = $this->getList(ListType::MANGA, $status) ?? [];
$data = $this->getList(MediaType::MANGA, $status) ?? [];
// Bail out on no data
if (empty($data))
@ -495,7 +495,7 @@ final class Model {
*/
public function getMangaListCount(string $status = '') : int
{
return $this->getListCount(ListType::MANGA, $status);
return $this->getListCount(MediaType::MANGA, $status);
}
/**


src/AnimeClient/API/Anilist.php → src/AnimeClient/Anilist.php View File

@ -14,7 +14,7 @@
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
namespace Aviat\AnimeClient\API;
namespace Aviat\AnimeClient;
use Aviat\AnimeClient\API\Enum\{
AnimeWatchingStatus\Kitsu as KAWS,

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

@ -250,7 +250,7 @@ function getResponse ($request): Response
* @param bool $webp
* @return string
*/
function getLocalImg ($kitsuUrl, $webp = TRUE): string
function getLocalImg (string $kitsuUrl, $webp = TRUE): string
{
if (empty($kitsuUrl) || ( ! is_string($kitsuUrl)))
{
@ -360,7 +360,7 @@ function clearCache(CacheInterface $cache): bool
Kitsu::AUTH_TOKEN_REFRESH_CACHE_KEY,
], NULL);
$userData = array_filter((array)$userData, fn ($value) => $value !== NULL);
$userData = array_filter((array)$userData, static fn ($value) => $value !== NULL);
$cleared = $cache->clear();
$saved = ( ! empty($userData))


+ 35
- 34
src/AnimeClient/Command/SyncLists.php View File

@ -25,7 +25,8 @@ use Aviat\AnimeClient\API\{
use Aviat\AnimeClient\API;
use Aviat\AnimeClient\API\Anilist;
use Aviat\AnimeClient\API\Mapping\{AnimeWatchingStatus, MangaReadingStatus};
use Aviat\AnimeClient\Enum\{ListType, SyncAction};
use Aviat\AnimeClient\Enum;
use Aviat\AnimeClient\Enum\{MediaType, SyncAction};
use Aviat\AnimeClient\Types\FormItem;
use Aviat\Ion\Di\Exception\ContainerException;
use Aviat\Ion\Di\Exception\NotFoundException;
@ -73,7 +74,7 @@ final class SyncLists extends BaseCommand {
{
$this->init();
foreach ([ListType::ANIME, ListType::MANGA] as $type)
foreach ([MediaType::ANIME, MediaType::MANGA] as $type)
{
// Main Sync flow
$this->fetchCount($type);
@ -100,7 +101,7 @@ final class SyncLists extends BaseCommand {
$this->setCache($this->container->get('cache'));
$config = $this->container->get('config');
$anilistEnabled = $config->get([API::ANILIST, 'enabled']);
$anilistEnabled = $config->get([Enum\API::ANILIST, 'enabled']);
// We can't sync kitsu against itself!
if ( ! $anilistEnabled)
@ -165,8 +166,8 @@ final class SyncLists extends BaseCommand {
$this->clearLine();
return [
API::ANILIST => $anilist,
API::KITSU => $kitsu,
Enum\API::ANILIST => $anilist,
Enum\API::KITSU => $kitsu,
];
}
@ -182,17 +183,17 @@ final class SyncLists extends BaseCommand {
$this->echo('Normalizing List Data');
$progress = new Widgets\ProgressBar($this->getConsole(), 2, 50, FALSE);
$kitsu = $this->transformKitsu($type, $data[API::KITSU]);
$kitsu = $this->transformKitsu($type, $data[Enum\API::KITSU]);
$progress->incr();
$anilist = $this->transformAnilist($type, $data[API::ANILIST]);
$anilist = $this->transformAnilist($type, $data[Enum\API::ANILIST]);
$progress->incr();
$this->clearLine();
return [
API::ANILIST => $anilist,
API::KITSU => $kitsu,
Enum\API::ANILIST => $anilist,
Enum\API::KITSU => $kitsu,
];
}
@ -207,7 +208,7 @@ final class SyncLists extends BaseCommand {
{
$this->echo('Comparing List Items');
return $this->compareLists($type, $data[API::ANILIST], $data[API::KITSU]);
return $this->compareLists($type, $data[Enum\API::ANILIST], $data[Enum\API::KITSU]);
}
/**
@ -280,8 +281,8 @@ final class SyncLists extends BaseCommand {
private function fetchAnilist(string $type): array
{
static $list = [
ListType::ANIME => NULL,
ListType::MANGA => NULL,
MediaType::ANIME => NULL,
MediaType::MANGA => NULL,
];
// This uses a static so I don't have to fetch this list twice for a count
@ -435,12 +436,12 @@ final class SyncLists extends BaseCommand {
continue;
}
if (in_array(API::KITSU, $item['updateType'], TRUE))
if (in_array(Enum\API::KITSU, $item['updateType'], TRUE))
{
$kitsuUpdateItems[] = $item['data'];
}
if (in_array(API::ANILIST, $item['updateType'], TRUE))
if (in_array(Enum\API::ANILIST, $item['updateType'], TRUE))
{
$anilistUpdateItems[] = $item['data'];
}
@ -448,7 +449,7 @@ final class SyncLists extends BaseCommand {
continue;
}
$statusMap = ($type === ListType::ANIME) ? AnimeWatchingStatus::class : MangaReadingStatus::class;
$statusMap = ($type === MediaType::ANIME) ? AnimeWatchingStatus::class : MangaReadingStatus::class;
// Looks like this item only exists on Kitsu
$kItem = $kitsuItem['data'];
@ -528,7 +529,7 @@ final class SyncLists extends BaseCommand {
if ($kitsuItem['data']['status'] === 'completed' && $kitsuItem['data']['reconsuming'] === TRUE)
{
$update['data']['reconsuming'] = FALSE;
$return['updateType'][] = API::KITSU;
$return['updateType'][] = Enum\API::KITSU;
}
// If status is the same, and progress count is different, use greater progress
@ -537,12 +538,12 @@ final class SyncLists extends BaseCommand {
if ($diff['progress'] === self::KITSU_GREATER)
{
$update['data']['progress'] = $kitsuItem['data']['progress'];
$return['updateType'][] = API::ANILIST;
$return['updateType'][] = Enum\API::ANILIST;
}
else if($diff['progress'] === self::ANILIST_GREATER)
{
$update['data']['progress'] = $anilistItem['data']['progress'];
$return['updateType'][] = API::KITSU;
$return['updateType'][] = Enum\API::KITSU;
}
}
@ -552,12 +553,12 @@ final class SyncLists extends BaseCommand {
if ($dateDiff === self::KITSU_GREATER)
{
$update['data']['status'] = $kitsuItem['data']['status'];
$return['updateType'][] = API::ANILIST;
$return['updateType'][] = Enum\API::ANILIST;
}
else if ($dateDiff === self::ANILIST_GREATER)
{
$update['data']['status'] = $anilistItem['data']['status'];
$return['updateType'][] = API::KITSU;
$return['updateType'][] = Enum\API::KITSU;
}
}
@ -574,7 +575,7 @@ final class SyncLists extends BaseCommand {
$update['data']['progress'] = $kitsuItem['data']['progress'];
}
$return['updateType'][] = API::ANILIST;
$return['updateType'][] = Enum\API::ANILIST;
}
else if($dateDiff === self::ANILIST_GREATER)
{
@ -585,7 +586,7 @@ final class SyncLists extends BaseCommand {
$update['data']['progress'] = $kitsuItem['data']['progress'];
}
$return['updateType'][] = API::KITSU;
$return['updateType'][] = Enum\API::KITSU;
}
}
@ -599,12 +600,12 @@ final class SyncLists extends BaseCommand {
)
{
$update['data']['ratingTwenty'] = $kitsuItem['data']['ratingTwenty'];
$return['updateType'][] = API::ANILIST;
$return['updateType'][] = Enum\API::ANILIST;
}
else if($dateDiff === self::ANILIST_GREATER && $anilistItem['data']['rating'] !== 0)
{
$update['data']['ratingTwenty'] = $anilistItem['data']['rating'] * 2;
$return['updateType'][] = API::KITSU;
$return['updateType'][] = Enum\API::KITSU;
}
}
@ -614,12 +615,12 @@ final class SyncLists extends BaseCommand {
if ( ! empty($kitsuItem['data']['notes']))
{
$update['data']['notes'] = $kitsuItem['data']['notes'];
$return['updateType'][] = API::ANILIST;
$return['updateType'][] = Enum\API::ANILIST;
}
else
{
$update['data']['notes'] = $anilistItem['data']['notes'];
$return['updateType'][] = API::KITSU;
$return['updateType'][] = Enum\API::KITSU;
}
}
@ -629,12 +630,12 @@ final class SyncLists extends BaseCommand {
if ($diff['reconsumeCount'] === self::KITSU_GREATER)
{
$update['data']['reconsumeCount'] = $kitsuItem['data']['reconsumeCount'];
$return['updateType'][] = API::ANILIST;
$return['updateType'][] = Enum\API::ANILIST;
}
else if ($diff['reconsumeCount'] === self::ANILIST_GREATER)
{
$update['data']['reconsumeCount'] = $anilistItem['data']['reconsumeCount'];
$return['updateType'][] = API::KITSU;
$return['updateType'][] = Enum\API::KITSU;
}
}
@ -645,8 +646,8 @@ final class SyncLists extends BaseCommand {
}
$return['meta'] = [
API::KITSU => $kitsuItem['data'],
API::ANILIST => $anilistItem['data'],
Enum\API::KITSU => $kitsuItem['data'],
Enum\API::ANILIST => $anilistItem['data'],
'dateDiff' => $dateDiff,
'diff' => $diff,
];
@ -656,7 +657,7 @@ final class SyncLists extends BaseCommand {
// Fill in missing data values for update
// so I don't have to create a really complex graphql query
// to handle each combination of fields
if ($return['updateType'][0] === API::ANILIST)
if ($return['updateType'][0] === Enum\API::ANILIST)
{
// Anilist GraphQL expects a rating from 1-100
$prevData = [
@ -673,7 +674,7 @@ final class SyncLists extends BaseCommand {
$return['data']['data'] = array_merge($prevData, $return['data']['data']);
}
else if ($return['updateType'][0] === API::KITSU)
else if ($return['updateType'][0] === Enum\API::KITSU)
{
$prevData = [
'notes' => $anilistItem['data']['notes'],
@ -707,7 +708,7 @@ final class SyncLists extends BaseCommand {
* @param string $type
* @throws Throwable
*/
private function updateKitsuListItems(array $itemsToUpdate, string $action = SyncAction::UPDATE, string $type = ListType::ANIME): void
private function updateKitsuListItems(array $itemsToUpdate, string $action = SyncAction::UPDATE, string $type = MediaType::ANIME): void
{
$requester = new ParallelAPIRequest();
foreach($itemsToUpdate as $item)
@ -776,7 +777,7 @@ final class SyncLists extends BaseCommand {
* @param string $type
* @throws Throwable
*/
private function updateAnilistListItems(array $itemsToUpdate, string $action = SyncAction::UPDATE, string $type = ListType::ANIME): void
private function updateAnilistListItems(array $itemsToUpdate, string $action = SyncAction::UPDATE, string $type = MediaType::ANIME): void
{
$requester = new ParallelAPIRequest();


+ 2
- 2
src/AnimeClient/Command/UpdateThumbnails.php View File

@ -69,11 +69,11 @@ final class UpdateThumbnails extends ClearThumbnails {
public function getImageList(): array
{
$animeIds = array_map(
fn ($item) => $item['media']['id'],
static fn ($item) => $item['media']['id'],
$this->kitsuModel->getThumbList('ANIME')
);
$mangaIds = array_map(
fn ($item) => $item['media']['id'],
static fn ($item) => $item['media']['id'],
$this->kitsuModel->getThumbList('MANGA')
);


+ 1
- 0
src/AnimeClient/Component/VerticalTabs.php View File

@ -26,6 +26,7 @@ final class VerticalTabs {
* also used to generate id attributes
* @param array $tabData The data used to create the tab content, indexed by the tab label
* @param callable $cb The function to generate the tab content
* @param string $className
* @return string
*/
public function __invoke(


+ 0
- 8
src/AnimeClient/Controller.php View File

@ -46,49 +46,41 @@ class Controller {
/**
* The authentication object
* @var Auth $auth ;
*/
protected Auth $auth;
/**
* Cache manager
* @var CacheInterface
*/
protected CacheInterface $cache;
/**
* The global configuration object
* @var ConfigInterface $config
*/
public ConfigInterface $config;
/**
* Request object
* @var ServerRequestInterface $request
*/
protected ServerRequestInterface $request;
/**
* Url generation class
* @var UrlGenerator
*/
protected UrlGenerator $urlGenerator;
/**
* Aura url generator
* @var Generator
*/
protected Generator $url;
/**
* Session segment
* @var Segment
*/
protected Segment $session;
/**
* Common data to be sent to views
* @var array
*/
protected array $baseData = [];


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

@ -66,17 +66,17 @@ final class Anime extends BaseController {
/**
* Show a portion, or all of the anime list
*
* @param string|int $type - The section of the list
* @param string $view - List or cover view
* @param string|int $status - The section of the list
* @param string|null $view - List or cover view
* @throws ContainerException
* @throws NotFoundException
* @throws InvalidArgumentException
* @throws Throwable
* @return void
*/
public function index($type = KitsuWatchingStatus::WATCHING, string $view = NULL): void
public function index($status = KitsuWatchingStatus::WATCHING, ?string $view = NULL): void
{
if ( ! in_array($type, [
if ( ! in_array($status, [
'all',
'watching',
'plan_to_watch',
@ -88,10 +88,10 @@ final class Anime extends BaseController {
$this->errorPage(404, 'Not Found', 'Page not found');
}
$title = array_key_exists($type, AnimeWatchingStatus::ROUTE_TO_TITLE)
$title = array_key_exists($status, AnimeWatchingStatus::ROUTE_TO_TITLE)
? $this->formatTitle(
$this->config->get('whose_list') . "'s Anime List",
AnimeWatchingStatus::ROUTE_TO_TITLE[$type]
AnimeWatchingStatus::ROUTE_TO_TITLE[$status]
)
: '';
@ -100,8 +100,8 @@ final class Anime extends BaseController {
'list' => 'list'
];
$data = ($type !== 'all')
? $this->model->getList(AnimeWatchingStatus::ROUTE_TO_KITSU[$type])
$data = ($status !== 'all')
? $this->model->getList(AnimeWatchingStatus::ROUTE_TO_KITSU[$status])
: $this->model->getAllLists();
$this->outputHTML('anime/' . $viewMap[$view], [
@ -305,17 +305,17 @@ final class Anime extends BaseController {
/**
* View details of an anime
*
* @param string $animeId
* @param string $id
* @throws ContainerException
* @throws NotFoundException
* @throws InvalidArgumentException
* @return void
*/
public function details(string $animeId): void
public function details(string $id): void
{
try
{
$data = $this->model->getAnime($animeId);
$data = $this->model->getAnime($id);
if ($data->isEmpty())
{
@ -349,7 +349,7 @@ final class Anime extends BaseController {
}
}
public function random()
public function random(): void
{
try
{


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

@ -94,7 +94,7 @@ final class AnimeCollection extends BaseController {
* @throws InvalidArgumentException
* @return void
*/
public function view($view): void
public function view(string $view = ''): void
{
$viewMap = [
'' => 'cover',


+ 3
- 13
src/AnimeClient/Controller/Manga.php View File

@ -303,19 +303,16 @@ final class Manga extends Controller {
/**
* View details of an manga
*
* @param string $manga_id
* @param string $id
* @throws ContainerException
* @throws NotFoundException
* @throws InvalidArgumentException
* @throws Throwable
* @return void
*/
public function details($manga_id): void
public function details(string $id): void
{
$data = $this->model->getManga($manga_id);
$staff = [];
$characters = [];
$data = $this->model->getManga($id);
if ($data->isEmpty())
{
$this->notFound(
@ -333,9 +330,7 @@ final class Manga extends Controller {
'Manga',
$data['title']
),
'characters' => $characters,
'data' => $data,
'staff' => $staff,
]);
}
@ -351,9 +346,6 @@ final class Manga extends Controller {
public function random(): void
{
$data = $this->model->getRandomManga();
$staff = [];
$characters = [];
if ($data->isEmpty())
{
$this->notFound(
@ -371,9 +363,7 @@ final class Manga extends Controller {
'Manga',
$data['title']
),
'characters' => $characters,
'data' => $data,
'staff' => $staff,
]);
}
}


src/AnimeClient/API.php → src/AnimeClient/Enum/API.php View File

@ -14,9 +14,11 @@
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
namespace Aviat\AnimeClient;
namespace Aviat\AnimeClient\Enum;
class API {
use Aviat\Ion\Enum;
final class API extends Enum {
public const ANILIST = 'anilist';
public const KITSU = 'kitsu';
}

src/AnimeClient/Enum/ListType.php → src/AnimeClient/Enum/MediaType.php View File

@ -19,9 +19,9 @@ namespace Aviat\AnimeClient\Enum;
use Aviat\Ion\Enum as BaseEnum;
/**
* Types of lists
* Types of media
*/
final class ListType extends BaseEnum {
final class MediaType extends BaseEnum {
public const ANIME = 'anime';
public const DRAMA = 'drama';
public const MANGA = 'manga';

+ 2
- 1
src/AnimeClient/Helper/Picture.php View File

@ -49,7 +49,8 @@ final class Picture {
];
/**
* Create the html for an html picture element
* Create the html for an html picture element.
* Uses .webp images with fallback
*
* @param string $uri
* @param string $fallbackExt


+ 5
- 5
src/AnimeClient/Kitsu.php View File

@ -187,14 +187,14 @@ final class Kitsu {
$host = parse_url($url, \PHP_URL_HOST);
$links[] = [
'meta' => static::getServiceMetaData($host),
'meta' => self::getServiceMetaData($host),
'link' => $streamingLink['url'],
'subs' => $streamingLink['subs'],
'dubs' => $streamingLink['dubs']
];
}
usort($links, fn ($a, $b) => $a['meta']['name'] <=> $b['meta']['name']);
usort($links, static fn ($a, $b) => $a['meta']['name'] <=> $b['meta']['name']);
return $links;
}
@ -282,7 +282,7 @@ final class Kitsu {
*/
protected static function getServiceMetaData(string $hostname = NULL): array
{
$hostname = str_replace('www.', '', $hostname);
$hostname = str_replace('www.', '', $hostname ?? '');
$serviceMap = [
'animelab.com' => [
@ -412,11 +412,11 @@ final class Kitsu {
/**
* Determine if an alternate title is unique enough to list
*
* @param string $title
* @param string|null $title
* @param array $existingTitles
* @return bool
*/
private static function titleIsUnique(string $title = NULL, array $existingTitles = []): bool
private static function titleIsUnique(?string $title = NULL, array $existingTitles = []): bool
{
if (empty($title))
{


+ 1
- 0
src/AnimeClient/Model/AnimeCollection.php View File

@ -134,6 +134,7 @@ final class AnimeCollection extends Collection {
}
// Organize the media types into groups
// @TODO: make this more database-driven, rather than hardcoded
return [
'Common' => [
2 => $flatList[2], // Blu-ray


+ 1
- 1
src/AnimeClient/Model/DB.php View File

@ -28,7 +28,7 @@ abstract class DB {
* The database connection information array
* @var array $dbConfig
*/
protected $dbConfig = [];
protected array $dbConfig = [];
/**
* Constructor


+ 0
- 52
src/AnimeClient/Types/Anime.php View File

@ -22,34 +22,16 @@ use Aviat\AnimeClient\API\Kitsu\Enum\AnimeAiringStatus;
* Type representing an anime within a watch list
*/
class Anime extends AbstractType {
/**
* @var string
*/
public ?string $age_rating;
/**
* @var string
*/
public ?string $age_rating_guide;
/**
* @var string
*/
public ?string $cover_image;
/**
* @var string|int
*/
public ?int $episode_count;
/**
* @var string|int
*/
public ?int $episode_length;
/**
* @var array
*/
public array $genres = [];
/**
@ -57,67 +39,33 @@ class Anime extends AbstractType {
*/
public $id = '';
/**
* @var array
*/
public array $included = [];
/**
* @var string
*/
public ?string $show_type;
/**
* @var string
*/
public ?string $slug;
/**
* @var AnimeAiringStatus
*/
public string $status = AnimeAiringStatus::FINISHED_AIRING;
/**
* @var array
*/
public ?array $streaming_links = [];
/**
* @var string
*/
public ?string $synopsis;
/**
* @var string
*/
public ?string $title;
/**
* @var array
*/
public array $titles = [];
/**
* @var array
*/
public array $titles_more = [];
/**
* @var string
*/
public ?string $trailer_id;
/**
* Length of the entire series in seconds
*
* @var int|null
*/
public ?int $total_length;
/**
* Kitsu detail page url
*
* @var string
*/
public ?string $url;
}

+ 1
- 30
src/AnimeClient/Types/AnimeListItem.php View File

@ -20,14 +20,8 @@ namespace Aviat\AnimeClient\Types;
* Type representing an anime watch list item
*/
final class AnimeListItem extends AbstractType {
/**
* @var string
*/
public ?string $id;
/**
* @var string
*/
public ?string $mal_id;
/**
@ -35,47 +29,26 @@ final class AnimeListItem extends AbstractType {
*/
public $anilist_item_id;
/**
* @var array
*/
public array $episodes = [
'length' => 0,
'total' => 0,
'watched' => '',
];
/**
* @var array
*/
public array $airing = [
'status' => '',
'started' => '',
'ended' => '',
];
/**
* @var Anime
*/
public ?Anime $anime;
/**
* @var string
*/
public ?string $notes;
/**
* @var bool
*/
public bool $private = FALSE;
/**
* @var bool
*/
public bool $rewatching = FALSE;
/**
* @var int
*/
public int $rewatched = 0;
/**
@ -85,10 +58,8 @@ final class AnimeListItem extends AbstractType {
/**
* One of Aviat\AnimeClient\API\Enum\AnimeWatchingStatus
*
* @var string
*/
public $watching_status;
public string $watching_status;
public function setAnime($anime): void
{


+ 0
- 9
src/AnimeClient/Types/AnimePage.php View File

@ -20,18 +20,9 @@ namespace Aviat\AnimeClient\Types;
* Type representing an Anime object for a detail page
*/
final class AnimePage extends Anime {
/**
* @var array
*/
public array $characters = [];
/**
* @var array
*/
public array $links = [];
/**
* @var array
*/
public array $staff = [];
}

+ 0
- 21
src/AnimeClient/Types/Character.php View File

@ -20,14 +20,8 @@ namespace Aviat\AnimeClient\Types;
* Type representing a character for display
*/
final class Character extends AbstractType {
/**
* @var array
*/
public array $castings = [];
/**
* @var string
*/
public ?string $description;
/**
@ -35,29 +29,14 @@ final class Character extends AbstractType {
*/
public $id;
/**
* @var array
*/
public array $included = [];
/**
* @var Media
*/
public ?Media $media;
/**
* @var string
*/
public ?string $name;
/**
* @var array
*/
public array $names = [];
/**
* @var array
*/
public array $otherNames = [];
public function setMedia ($media): void


+ 0
- 6
src/AnimeClient/Types/Characters.php View File

@ -17,13 +17,7 @@
namespace Aviat\AnimeClient\Types;
final class Characters extends AbstractType {
/**
* @var array
*/
public array $main = [];
/**
* @var array
*/
public array $supporting = [];
}

+ 2
- 51
src/AnimeClient/Types/Config.php View File

@ -22,28 +22,16 @@ class Config extends AbstractType {
// Config files/namespaces
// ------------------------------------------------------------------------
/**
* @var Config\Anilist
*/
public ?Config\Anilist $anilist;
/**
* @var Config\Cache
*/
public ?Config\Cache $cache;
/**
* @var Config\Database
*/
public ?Config\Database $database;
// ------------------------------------------------------------------------
// Settings in config.toml
// ------------------------------------------------------------------------
/**
* @var string
*/
public ?string $asset_path; // Path to public folder for urls
/**
@ -60,8 +48,6 @@ class Config extends AbstractType {
/**
* Default Anime list status page, values are listed in
* Aviat\AnimeClient\API\Enum\AnimeWatchingStatus\Title
*
* @var string
*/
public ?string $default_anime_list_path;
@ -75,8 +61,6 @@ class Config extends AbstractType {
/**
* Default Manga list status page, values are listed in
* Aviat\AnimeClient\API\Enum\MangaReadingStatus\Title
*
* @var string
*/
public ?string $default_manga_list_path;
@ -85,25 +69,13 @@ class Config extends AbstractType {
*/
public ?string $default_view_type;
/**
* @var string
*/
public ?string $kitsu_username;
/**
* @var bool
*/
public bool $secure_urls = TRUE;
/**
* @var bool
*/
public $show_anime_collection = FALSE;
public bool $show_anime_collection = FALSE;
/**
* @var bool
*/
public $show_manga_collection = FALSE;
public bool $show_manga_collection = FALSE;
/**
* CSS theme: light, dark, or auto-switching
@ -112,9 +84,6 @@ class Config extends AbstractType {
*/
public ?string $theme;
/**
* @var string
*/
public ?string $whose_list;
// ------------------------------------------------------------------------
@ -135,34 +104,16 @@ class Config extends AbstractType {
// Generated config values
// ------------------------------------------------------------------------
/**
* @var string
*/
public ?string $asset_dir; // Path to public folder for local files
/**
* @var string
*/
public ?string $base_config_dir;
/**
* @var string
*/
public ?string $config_dir;
/**
* @var string
*/
public ?string $data_cache_path;
/**
* @var string
*/
public ?string $img_cache_path;
/**
* @var string
*/
public ?string $view_path;
public function setAnilist ($data): void


+ 13
- 34
src/AnimeClient/Types/Config/Anilist.php View File

@ -19,38 +19,17 @@ namespace Aviat\AnimeClient\Types\Config;
use Aviat\AnimeClient\Types\AbstractType;
class Anilist extends AbstractType {
/**
* @var bool
*/
public $enabled = FALSE;
/**
* @var string
*/
public $client_id;
/**
* @var string
*/
public $client_secret;
/**
* @var string
*/
public $access_token;
/**
* @var string
*/
public $access_token_expires;
/**
* @var string
*/
public $refresh_token;
/**
* @var string
*/
public $username;
public bool $enabled = FALSE;
public ?string $client_id;
public ?string $client_secret;
public ?string $access_token;
public ?int $access_token_expires;
public ?string $refresh_token;
public ?string $username;
}

+ 8
- 5
src/AnimeClient/Types/Config/Cache.php View File

@ -22,21 +22,24 @@ class Cache extends AbstractType {
/**
* @var string
*/
public $driver;
public string $driver = 'null';
public $host;
public ?string $host;
/**
* @var string|int|null
*/
public $port;
public $database;
public ?string $database;
/**
* @var array
*/
public $connection = [];
public array $connection = [];
/**
* @var array
*/
public $options = [];
public array $options = [];
}

+ 12
- 12
src/AnimeClient/Types/Config/Database.php View File

@ -22,35 +22,35 @@ class Database extends AbstractType {
/**
* @var string
*/
public $type;
public string $type = 'sqlite';
/**
* @var string
* @var string|null
*/
public $host;
public ?string $host;
/**
* @var string
* @var string|null
*/
public $user;
public ?string $user;
/**
* @var string
* @var string|null
*/
public $pass;
public ?string $pass;
/**
* @var string|int
* @var string|int|null
*/
public $port;
/**
* @var string
* @var string|null
*/
public $database;
public ?string $database;
/**
* @var string
* @var string|null
*/
public $file;
public ?string $file;
}

+ 1
- 7
src/AnimeClient/Types/FormItem.php View File

@ -25,19 +25,13 @@ class FormItem extends AbstractType {
*/
public $id;
/**
* @var string
*/
public ?string $anilist_item_id;
/**
* @var string|int
*/
public $mal_id;
public $mal_id;
/**
* @var FormItemData
*/
public ?FormItemData $data;
public function setData($value): void


+ 0
- 11
src/AnimeClient/Types/FormItemData.php View File

@ -20,14 +20,8 @@ namespace Aviat\AnimeClient\Types;
* Type representing a Media object for editing/syncing
*/
class FormItemData extends AbstractType {
/**
* @var string
*/
public ?string $notes;
/**
* @var bool
*/
public ?bool $private = FALSE;
/**
@ -50,9 +44,6 @@ class FormItemData extends AbstractType {
*/
public $reconsumeCount;
/**
* @var bool
*/
public bool $reconsuming = FALSE;
/**
@ -62,8 +53,6 @@ class FormItemData extends AbstractType {
/**
* W3C Format Date string
*
* @var string
*/
public ?string $updatedAt;
}

+ 9
- 9
src/AnimeClient/Types/HistoryItem.php View File

@ -20,47 +20,47 @@ use DateTimeImmutable;
class HistoryItem extends AbstractType {
/**
* @var string Title of the anime/manga
* Title of the anime/manga
*/
public string $title = '';
/**
* @var string The url of the cover image
* The url of the cover image
*/
public string $coverImg = '';
/**
* @var string The type of action done
* The type of action done
*/
public string $action = '';
/**
* @var bool Is this item a combination of items?
* Is this item a combination of items?
*/
public bool $isAggregate = FALSE;
/**
* @var string The kind of history event
* The kind of history event
*/
public string $kind = '';
/**
* @var DateTimeImmutable When the item was last updated
* When the item was last updated
*/
public ?DateTimeImmutable $updated = NULL;
/**
* @var array Range of updated times for the aggregated item
* Range of updated times for the aggregated item
*/
public array $dateRange = [];
/**
* @var string Url to details page
* Url to details page
*/
public string $url = '';
/**
* @var array The item before transformation
* The item before transformation
*/
public array $original = [];
}

+ 0
- 6
src/AnimeClient/Types/Media.php View File

@ -17,13 +17,7 @@
namespace Aviat\AnimeClient\Types;
final class Media extends AbstractType {
/**
* @var array
*/
public array $anime = [];
/**
* @var array
*/
public array $manga = [];
}

+ 0
- 27
src/AnimeClient/Types/User.php View File

@ -20,48 +20,21 @@ namespace Aviat\AnimeClient\Types;
* Type representing a Kitsu user for display
*/
final class User extends AbstractType {
/**
* @var string
*/
public ?string $about;
/**
* @var string
*/
public ?string $avatar;
/**
* @var array
*/