Version 5.1 - All the GraphQL #32

Closed
timw4mail wants to merge 1160 commits from develop into master
103 changed files with 273 additions and 1088 deletions
Showing only changes of commit 496ba418c9 - Show all commits

View File

@ -70,9 +70,6 @@ abstract class APIRequestBuilder {
/**
* Do a basic minimal GET request
*
* @param string $uri
* @return Request
*/
public static function simpleRequest(string $uri): Request
{
@ -89,7 +86,6 @@ abstract class APIRequestBuilder {
*
* @param string $type The type of authorization, eg, basic, bearer, etc.
* @param string $value The authorization value
* @return self
*/
public function setAuth(string $type, string $value): self
{
@ -101,10 +97,6 @@ abstract class APIRequestBuilder {
/**
* Set a basic authentication header
*
* @param string $username
* @param string $password
* @return self
*/
public function setBasicAuth(string $username, string $password): self
{
@ -114,9 +106,6 @@ abstract class APIRequestBuilder {
/**
* Set the request body
*
* @param FormBody|string $body
* @return self
*/
public function setBody(FormBody|string $body): self
{
@ -128,7 +117,6 @@ abstract class APIRequestBuilder {
* Set body as form fields
*
* @param array $fields Mapping of field names to values
* @return self
*/
public function setFormFields(array $fields): self
{
@ -140,9 +128,6 @@ abstract class APIRequestBuilder {
/**
* Unset a request header
*
* @param string $name
* @return self
*/
public function unsetHeader(string $name): self
{
@ -153,9 +138,7 @@ abstract class APIRequestBuilder {
/**
* Set a request header
*
* @param string $name
* @param string|null $value
* @return self
*/
public function setHeader(string $name, string $value = NULL): self
{
@ -177,7 +160,6 @@ abstract class APIRequestBuilder {
* name => value
*
* @param array $headers
* @return self
*/
public function setHeaders(array $headers): self
{
@ -191,24 +173,18 @@ abstract class APIRequestBuilder {
/**
* Set the request body
*
* @param mixed $body
* @return self
*/
public function setJsonBody(mixed $body): self
{
$requestBody = ( ! is_string($body))
? Json::encode($body)
: $body;
$requestBody = ( is_string($body))
? $body
: Json::encode($body);
return $this->setBody($requestBody);
}
/**
* Append a query string in array format
*
* @param array $params
* @return self
*/
public function setQuery(array $params): self
{
@ -219,7 +195,6 @@ abstract class APIRequestBuilder {
/**
* Return the promise for the current request
*
* @return Request
* @throws \Throwable
*/
public function getFullRequest(): Request
@ -245,7 +220,6 @@ abstract class APIRequestBuilder {
/**
* Get the data from the response of the passed request
*
* @param Request $request
* @return mixed
* @throws \Error
* @throws \Throwable
@ -260,10 +234,7 @@ abstract class APIRequestBuilder {
/**
* Create a new http request
*
* @param string $type
* @param string $uri
* @throws InvalidArgumentException
* @return self
*/
public function newRequest(string $type, string $uri): self
{
@ -292,8 +263,6 @@ abstract class APIRequestBuilder {
/**
* Create the full request url
*
* @return Request
*/
private function buildUri(): Request
{
@ -313,10 +282,6 @@ abstract class APIRequestBuilder {
/**
* Reset the class state for a new request
*
* @param string|null $url
* @param string $type
* @return void
*/
private function resetState(?string $url, string $type = 'GET'): void
{

View File

@ -28,15 +28,11 @@ abstract class AbstractListItem {
* Create a list item
*
* @param array $data -
* @return Request
*/
abstract public function create(array $data): Request;
/**
* Create a full list item for syncing
*
* @param array $data
* @return Request
*/
abstract public function createFull(array $data): Request;
@ -44,16 +40,12 @@ abstract class AbstractListItem {
* Retrieve a list item
*
* @param string $id - The id of the list item
* @return array
* @return mixed[]
*/
abstract public function get(string $id): array;
/**
* Increase progress on a list item
*
* @param string $id
* @param FormItemData $data
* @return Request
*/
abstract public function increment(string $id, FormItemData $data): Request;
@ -62,7 +54,6 @@ abstract class AbstractListItem {
*
* @param string $id - The id of the list item to update
* @param FormItemData $data - The data with which to update the list item
* @return Request
*/
abstract public function update(string $id, FormItemData $data): Request;
@ -70,7 +61,6 @@ abstract class AbstractListItem {
* Delete a list item
*
* @param string $id - The id of the list item to delete
* @return Request|null
*/
abstract public function delete(string $id):?Request;
}

View File

@ -31,9 +31,6 @@ final class ListItem extends AbstractListItem {
/**
* Create a minimal list item
*
* @param array $data
* @return Request
*/
public function create(array $data): Request
{
@ -43,9 +40,6 @@ final class ListItem extends AbstractListItem {
/**
* Create a fleshed-out list item
*
* @param array $data
* @return Request
*/
public function createFull(array $data): Request
{
@ -55,10 +49,6 @@ final class ListItem extends AbstractListItem {
/**
* Delete a list item
*
* @param string $id
* @param string $type
* @return Request
*/
public function delete(string $id, string $type = 'anime'): Request
{
@ -67,9 +57,6 @@ final class ListItem extends AbstractListItem {
/**
* Get the data for a list item
*
* @param string $id
* @return array
*/
public function get(string $id): array
{
@ -78,10 +65,6 @@ final class ListItem extends AbstractListItem {
/**
* Increase the progress on the medium by 1
*
* @param string $id
* @param FormItemData $data
* @return Request
*/
public function increment(string $id, FormItemData $data): Request
{
@ -95,10 +78,6 @@ final class ListItem extends AbstractListItem {
/**
* Update a list item
*
* @param string $id
* @param FormItemData $data
* @return Request
*/
public function update(string $id, FormItemData $data): Request
{

View File

@ -36,32 +36,24 @@ use Throwable;
final class Model
{
use RequestBuilderTrait;
/**
* @var ListItem
*/
private ListItem $listItem;
/**
* Constructor
*
* @param ListItem $listItem
*/
public function __construct(ListItem $listItem)
public function __construct(private ListItem $listItem)
{
$this->listItem = $listItem;
}
// -------------------------------------------------------------------------
// ! Generic API calls
// -------------------------------------------------------------------------
/**
* Attempt to get an auth token
*
* @param string $code - The request token
* @param string $redirectUri - The oauth callback url
* @return array
* @throws Throwable
* @return mixed[]
*/
public function authenticate(string $code, string $redirectUri): array
{
@ -84,8 +76,6 @@ final class Model
/**
* Check auth status with simple API call
*
* @return array
*/
public function checkAuth(): array
{
@ -95,8 +85,6 @@ final class Model
/**
* Get user list data for syncing with Kitsu
*
* @param string $type
* @return array
* @throws ContainerException
* @throws NotFoundException
*/
@ -119,8 +107,6 @@ final class Model
/**
* Create a list item
*
* @param array $data
* @param string $type
* @return Request
*/
public function createListItem(array $data, string $type = 'anime'): ?Request
@ -159,10 +145,6 @@ final class Model
/**
* Create a list item with all the relevant data
*
* @param array $data
* @param string $type
* @return Request
*/
public function createFullListItem(array $data, string $type): Request
{
@ -185,7 +167,7 @@ final class Model
* @param string $malId - The unique identifier of that list item
* @param string $type - Them media type (anime/manga)
*
* @return array
* @return mixed[]
*/
public function getListItem(string $malId, string $type): array
{
@ -205,9 +187,7 @@ final class Model
/**
* Increase the watch count for the current list item
*
* @param FormItem $data
* @param string $type - Them media type (anime/manga)
* @return Request|null
*/
public function incrementListItem(FormItem $data, string $type): ?Request
{
@ -223,9 +203,7 @@ final class Model
/**
* Modify a list item
*
* @param FormItem $data
* @param string $type - Them media type (anime/manga)
* @return Request|null
*/
public function updateListItem(FormItem $data, string $type): ?Request
{
@ -244,7 +222,6 @@ final class Model
*
* @param string $malId - The id of the list item to remove
* @param string $type - Them media type (anime/manga)
* @return Request|null
*/
public function deleteListItem(string $malId, string $type): ?Request
{
@ -260,9 +237,7 @@ final class Model
/**
* Get the id of the specific list entry from the malId
*
* @param string $malId
* @param string $type - The media type (anime/manga)
* @return string|null
*/
public function getListIdFromMalId(string $malId, string $type): ?string
{
@ -279,9 +254,6 @@ final class Model
* Get the Anilist list item id from the media id from its MAL id
* this way is more accurate than getting the list item id
* directly from the MAL id
*
* @param string $mediaId
* @return string|null
*/
private function getListIdFromMediaId(string $mediaId): ?string
{
@ -303,10 +275,6 @@ final class Model
/**
* Get the Anilist media id from the malId
*
* @param string $malId
* @param string $type
* @return string|null
*/
private function getMediaIdFromMalId(string $malId, string $type = 'ANIME'): ?string
{

View File

@ -38,20 +38,16 @@ final class RequestBuilder extends APIRequestBuilder {
/**
* The base url for api requests
* @var string $base_url
*/
protected string $baseUrl = Anilist::BASE_URL;
/**
* Valid HTTP request methods
* @var array
*/
protected array $validMethods = ['POST'];
/**
* HTTP headers to send with every request
*
* @var array
*/
protected array $defaultHeaders = [
'Accept' => 'application/json',
@ -67,9 +63,6 @@ final class RequestBuilder extends APIRequestBuilder {
/**
* Create a request object
* @param string $url
* @param array $options
* @return Request
* @throws Throwable
*/
public function setUpRequest(string $url, array $options = []): Request
@ -111,10 +104,6 @@ final class RequestBuilder extends APIRequestBuilder {
/**
* Run a GraphQL API query
*
* @param string $name
* @param array $variables
* @return array
*/
public function runQuery(string $name, array $variables = []): array
{
@ -144,9 +133,6 @@ final class RequestBuilder extends APIRequestBuilder {
}
/**
* @param string $name
* @param array $variables
* @return Request
* @throws Throwable
*/
public function mutateRequest (string $name, array $variables = []): Request
@ -177,10 +163,8 @@ final class RequestBuilder extends APIRequestBuilder {
}
/**
* @param string $name
* @param array $variables
* @return array
* @throws Throwable
* @return mixed[]
*/
public function mutate (string $name, array $variables = []): array
{
@ -193,9 +177,6 @@ final class RequestBuilder extends APIRequestBuilder {
/**
* Make a request
*
* @param string $url
* @param array $options
* @return Response
* @throws Throwable
*/
private function getResponse(string $url, array $options = []): Response
@ -220,8 +201,6 @@ final class RequestBuilder extends APIRequestBuilder {
}
/**
* @param Request $request
* @return Response
* @throws Throwable
*/
public function getResponseFromRequest(Request $request): Response
@ -247,8 +226,6 @@ final class RequestBuilder extends APIRequestBuilder {
/**
* Remove some boilerplate for post requests
*
* @param array $options
* @return array
* @throws Throwable
*/
protected function postRequest(array $options = []): array

View File

@ -28,9 +28,6 @@ trait RequestBuilderTrait {
/**
* Set the request builder object
*
* @param RequestBuilder $requestBuilder
* @return self
*/
public function setRequestBuilder(RequestBuilder $requestBuilder): self
{

View File

@ -36,7 +36,6 @@ class AnimeListTransformer extends AbstractTransformer {
/**
* Transform Anilist list item to Kitsu form update format
*
* @param array $item
* @return FormItem
*/
public function untransform(array $item): FormItem

View File

@ -36,9 +36,6 @@ class MangaListTransformer extends AbstractTransformer {
/**
* Transform Anilist list item to Kitsu form update format
*
* @param array $item
* @return FormItem
*/
public function untransform(array $item): FormItem
{

View File

@ -22,15 +22,15 @@ class MediaListEntry extends AbstractType {
public int|string $id;
public ?string $notes;
public ?string $notes = null;
public ?bool $private;
public ?bool $private = null;
public int $progress;
public ?int $repeat;
public ?int $repeat = null;
public string $status;
public ?int $score;
public ?int $score = null;
}

View File

@ -23,16 +23,10 @@ use Psr\SimpleCache\CacheInterface;
*/
trait CacheTrait {
/**
* @var CacheInterface
*/
protected CacheInterface $cache;
/**
* Inject the cache object
*
* @param CacheInterface $cache
* @return self
*/
public function setCache(CacheInterface $cache): self
{
@ -42,8 +36,6 @@ trait CacheTrait {
/**
* Get the cache object if it exists
*
* @return CacheInterface
*/
public function getCache(): CacheInterface
{
@ -53,11 +45,6 @@ trait CacheTrait {
/**
* Get the cached value if it exists, otherwise set the cache value
* and return it.
*
* @param string $key
* @param callable $primer
* @param array|null $primeArgs
* @return mixed
*/
public function getCached(string $key, callable $primer, ?array $primeArgs = []): mixed
{

View File

@ -34,15 +34,11 @@ final class Auth {
/**
* Anime API Model
*
* @var Model
*/
private Model $model;
/**
* Session object
*
* @var Segment
*/
private Segment $segment;
@ -65,9 +61,6 @@ final class Auth {
/**
* Make the appropriate authentication call,
* and save the resulting auth token if successful
*
* @param string $password
* @return boolean
*/
public function authenticate(string $password): bool
{
@ -81,9 +74,6 @@ final class Auth {
/**
* Make the call to re-authenticate with the existing refresh token
*
* @param string|null $refreshToken
* @return boolean
*/
public function reAuthenticate(?string $refreshToken = NULL): bool
{
@ -101,8 +91,6 @@ final class Auth {
/**
* Check whether the current user is authenticated
*
* @return boolean
*/
public function isAuthenticated(): bool
{
@ -111,8 +99,6 @@ final class Auth {
/**
* Clear authentication values
*
* @return void
*/
public function logout(): void
{
@ -121,8 +107,6 @@ final class Auth {
/**
* Retrieve the authentication token from the session
*
* @return string|null
*/
public function getAuthToken(): ?string
{
@ -137,8 +121,6 @@ final class Auth {
/**
* Retrieve the refresh token
*
* @return string|null
*/
private function getRefreshToken(): ?string
{
@ -153,9 +135,6 @@ final class Auth {
/**
* Save the new authentication information
*
* @param array|false $auth
* @return bool
*/
private function storeAuth(array|false $auth): bool
{
@ -185,4 +164,5 @@ final class Auth {
return FALSE;
}
}
// End of KitsuAuth.php

View File

@ -31,8 +31,6 @@ final class ListItem extends AbstractListItem {
use RequestBuilderTrait;
/**
* @param array $data
* @return Request
* @throws Throwable
*/
public function create(array $data): Request
@ -90,8 +88,6 @@ final class ListItem extends AbstractListItem {
}
/**
* @param string $id
* @return Request
* @throws Throwable
*/
public function delete(string $id): Request
@ -102,9 +98,8 @@ final class ListItem extends AbstractListItem {
}
/**
* @param string $id
* @return array
* @throws Throwable
* @return mixed[]
*/
public function get(string $id): array
{
@ -115,10 +110,6 @@ final class ListItem extends AbstractListItem {
/**
* Increase the progress on the medium by 1
*
* @param string $id
* @param FormItemData $data
* @return Request
*/
public function increment(string $id, FormItemData $data): Request
{
@ -129,9 +120,6 @@ final class ListItem extends AbstractListItem {
}
/**
* @param string $id
* @param FormItemData $data
* @return Request
* @throws Throwable
*/
public function update(string $id, FormItemData $data): Request
@ -151,6 +139,7 @@ final class ListItem extends AbstractListItem {
{
$updateData['progress'] = (int)$data['progress'];
}
if ($data['ratingTwenty'] !== NULL)
{
$updateData['ratingTwenty'] = (int)$data['ratingTwenty'];

View File

@ -67,30 +67,17 @@ final class Model {
*/
protected MangaTransformer $mangaTransformer;
/**
* @var ListItem
*/
protected ListItem $listItem;
/**
* Constructor
*
* @param ListItem $listItem
*/
public function __construct(ListItem $listItem)
public function __construct(protected ListItem $listItem)
{
$this->animeTransformer = new AnimeTransformer();
$this->mangaTransformer = new MangaTransformer();
$this->listItem = $listItem;
}
/**
* Get the access token from the Kitsu API
*
* @param string $username
* @param string $password
* @return array|false
*/
public function authenticate(string $username, string $password): array|false
{
@ -113,7 +100,7 @@ final class Model {
if (array_key_exists('error', $data))
{
dump([
'method' => __CLASS__ . '\\' . __METHOD__,
'method' => self::class . '\\' . __METHOD__,
'error' => $data['error'],
'response' => $response,
]);
@ -130,9 +117,6 @@ final class Model {
/**
* Extend the current session with a refresh token
*
* @param string $token
* @return array|false
*/
public function reAuthenticate(string $token): array|false
{
@ -152,7 +136,7 @@ final class Model {
if (array_key_exists('error', $data))
{
dump([
'method' => __CLASS__ . '\\' . __METHOD__,
'method' => self::class . '\\' . __METHOD__,
'error' => $data['error'],
'response' => $response,
]);
@ -171,7 +155,6 @@ final class Model {
* Get the userid for a username from Kitsu
*
* @param string|null $username
* @return string
*/
public function getUserIdByUsername(string $username = NULL): string
{
@ -192,8 +175,7 @@ final class Model {
/**
* Get information about a character
*
* @param string $slug
* @return array
* @return mixed[]
*/
public function getCharacter(string $slug): array
{
@ -205,8 +187,7 @@ final class Model {
/**
* Get information about a person
*
* @param string $slug
* @return array
* @return mixed[]
*/
public function getPerson(string $slug): array
{
@ -218,8 +199,7 @@ final class Model {
/**
* Get profile information for the configured user
*
* @param string $username
* @return array
* @return mixed[]
*/
public function getUserData(string $username): array
{
@ -231,12 +211,8 @@ final class Model {
// -------------------------------------------------------------------------
// ! Anime-specific methods
// -------------------------------------------------------------------------
/**
* Get information about a particular anime
*
* @param string $slug
* @return Anime
*/
public function getAnime(string $slug): Anime
{
@ -269,9 +245,6 @@ final class Model {
/**
* Get information about a particular anime
*
* @param string $animeId
* @return Anime
*/
public function getAnimeById(string $animeId): Anime
{
@ -284,7 +257,7 @@ final class Model {
/**
* Retrieve the data for the anime watch history page
*
* @return array
* @return mixed[]
*/
public function getAnimeHistory(): array
{
@ -308,7 +281,7 @@ final class Model {
* Get the anime list for the configured user
*
* @param string $status - The watching status to filter the list with
* @return array
* @return mixed[]
*/
public function getAnimeList(string $status): array
{
@ -346,7 +319,6 @@ final class Model {
* Get the number of anime list items
*
* @param string $status - Optional status to filter by
* @return int
*/
public function getAnimeListCount(string $status = '') : int
{
@ -356,7 +328,7 @@ final class Model {
/**
* Get all the anime entries, that are organized for output to html
*
* @return array
* @return array<string, mixed[]>
*/
public function getFullOrganizedAnimeList(): array
{
@ -364,7 +336,7 @@ final class Model {
$statuses = KitsuWatchingStatus::getConstList();
foreach ($statuses as $key => $status)
foreach ($statuses as $status)
{
$mappedStatus = AnimeWatchingStatus::KITSU_TO_TITLE[$status];
$output[$mappedStatus] = $this->getAnimeList($status) ?? [];
@ -376,12 +348,8 @@ final class Model {
// -------------------------------------------------------------------------
// ! Manga-specific methods
// -------------------------------------------------------------------------
/**
* Get information about a particular manga
*
* @param string $slug
* @return MangaPage
*/
public function getManga(string $slug): MangaPage
{
@ -408,9 +376,6 @@ final class Model {
/**
* Get information about a particular manga
*
* @param string $mangaId
* @return MangaPage
*/
public function getMangaById(string $mangaId): MangaPage
{
@ -423,7 +388,7 @@ final class Model {
/**
* Retrieve the data for the manga read history page
*
* @return array
* @return mixed[]
*/
public function getMangaHistory(): array
{
@ -445,7 +410,7 @@ final class Model {
* Get the manga list for the configured user
*
* @param string $status - The reading status by which to filter the list
* @return array
* @return mixed[]
*/
public function getMangaList(string $status): array
{
@ -483,7 +448,6 @@ final class Model {
* Get the number of manga list items
*
* @param string $status - Optional status to filter by
* @return int
*/
public function getMangaListCount(string $status = '') : int
{
@ -493,7 +457,7 @@ final class Model {
/**
* Get all Manga lists
*
* @return array
* @return array<string, mixed[]>
*/
public function getFullOrganizedMangaList(): array
{
@ -511,13 +475,12 @@ final class Model {
// ------------------------------------------------------------------------
// Base methods
// ------------------------------------------------------------------------
/**
* Search for an anime or manga
*
* @param string $type - 'anime' or 'manga'
* @param string $query - name of the item to search for
* @return array
* @return array<int, array<string, mixed>>
*/
public function search(string $type, string $query): array
{
@ -563,9 +526,7 @@ final class Model {
/**
* Find a media item on Kitsu by its associated MAL id
*
* @param string $malId
* @param string $type "anime" or "manga"
* @return string|NULL
*/
public function getKitsuIdFromMALId(string $malId, string $type='anime'): ?string
{
@ -594,6 +555,9 @@ final class Model {
return (new LibraryEntryTransformer())->transform($baseData['data']['findLibraryEntryById']);
}
/**
* @return mixed[]
*/
public function getThumbList(string $type): array
{
$statuses = [
@ -624,7 +588,7 @@ final class Model {
* Get the data to sync Kitsu anime/manga list with another API
*
* @param string $type
* @return array
* @return mixed[]
*/
public function getSyncList(string $type): array
{
@ -654,7 +618,7 @@ final class Model {
/**
* Get the aggregated pages of anime or manga history
*
* @return array
* @return mixed[]
*/
protected function getHistoryList(): array
{
@ -666,9 +630,7 @@ final class Model {
/**
* Get the raw anime/manga list from GraphQL
*
* @param string $type
* @param string $status
* @return array
* @return mixed[]
*/
protected function getList(string $type, string $status = ''): array
{
@ -687,7 +649,7 @@ final class Model {
$cursor = '';
$username = $this->getUsername();
return new Amp\Producer(function (callable $emit) use ($type, $status, $cursor, $username) {
return new Amp\Producer(function (callable $emit) use ($type, $status, $cursor, $username): \Generator {
while (TRUE)
{
$vars = [
@ -698,6 +660,7 @@ final class Model {
{
$vars['status'] = $status;
}
if ($cursor !== '')
{
$vars['after'] = $cursor;
@ -738,7 +701,7 @@ final class Model {
$cursor = '';
$username = $this->getUsername();
return new Amp\Producer(function (callable $emit) use ($type, $status, $cursor, $username) {
return new Amp\Producer(function (callable $emit) use ($type, $status, $cursor, $username): \Generator {
while (TRUE)
{
$vars = [
@ -781,7 +744,7 @@ final class Model {
$cursor = '';
$username = $this->getUsername();
return new Amp\Producer(function (callable $emit) use ($type, $status, $cursor, $username) {
return new Amp\Producer(function (callable $emit) use ($type, $status, $cursor, $username): \Generator {
while (TRUE)
{
$vars = [
@ -843,8 +806,6 @@ final class Model {
/**
* Get the kitsu username from config
*
* @return string
*/
private function getUsername(): string
{

View File

@ -26,12 +26,8 @@ trait MutationTrait {
// -------------------------------------------------------------------------
// ! Generic API calls
// -------------------------------------------------------------------------
/**
* Create a list item
*
* @param array $data
* @return Request|null
*/
public function createListItem(array $data): ?Request
{
@ -46,9 +42,6 @@ trait MutationTrait {
/**
* Increase the progress count for a list item
*
* @param FormItem $data
* @return Request
*/
public function incrementListItem(FormItem $data): Request
{
@ -57,9 +50,6 @@ trait MutationTrait {
/**
* Modify a list item
*
* @param FormItem $data
* @return Request
*/
public function updateListItem(FormItem $data): Request
{
@ -70,7 +60,6 @@ trait MutationTrait {
* Remove a list item
*
* @param string $id - The id of the list item to remove
* @return Request
*/
public function deleteListItem(string $id): Request
{

View File

@ -40,20 +40,16 @@ final class RequestBuilder extends APIRequestBuilder {
/**
* The base url for api requests
* @var string $base_url
*/
protected string $baseUrl = K::GRAPHQL_ENDPOINT;
/**
* Where to look for GraphQL request files
* @var string
*/
protected string $filePath = __DIR__;
/**
* HTTP headers to send with every request
*
* @var array
*/
protected array $defaultHeaders = [
'User-Agent' => USER_AGENT,
@ -70,11 +66,6 @@ final class RequestBuilder extends APIRequestBuilder {
/**
* Create a request object
*
* @param string $type
* @param string $url
* @param array $options
* @return Request
*/
public function setUpRequest(string $type, string $url, array $options = []): Request
{
@ -131,9 +122,7 @@ final class RequestBuilder extends APIRequestBuilder {
/**
* Run a GraphQL API query
*
* @param string $name
* @param array $variables
* @return array
* @return mixed[]
*/
public function runQuery(string $name, array $variables = []): array
{
@ -156,9 +145,7 @@ final class RequestBuilder extends APIRequestBuilder {
/**
* Run a GraphQL mutation
*
* @param string $name
* @param array $variables
* @return array
* @return mixed[]
*/
public function mutate(string $name, array $variables = []): array
{
@ -180,11 +167,6 @@ final class RequestBuilder extends APIRequestBuilder {
/**
* Make a request
*
* @param string $type
* @param string $url
* @param array $options
* @return Response
*/
public function getResponse(string $type, string $url, array $options = []): Response
{
@ -205,10 +187,6 @@ final class RequestBuilder extends APIRequestBuilder {
/**
* Create a GraphQL query and return the Request object
*
* @param string $name
* @param array $variables
* @return Request
*/
public function queryRequest(string $name, array $variables = []): Request
{
@ -239,10 +217,6 @@ final class RequestBuilder extends APIRequestBuilder {
/**
* Create a GraphQL mutation request, and return the Request object
*
* @param string $name
* @param array $variables
* @return Request
*/
public function mutateRequest (string $name, array $variables = []): Request
{
@ -272,11 +246,6 @@ final class RequestBuilder extends APIRequestBuilder {
/**
* Make a request
*
* @param string $type
* @param string $url
* @param array $options
* @return array
*/
private function request(string $type, string $url, array $options = []): array
{
@ -305,7 +274,7 @@ final class RequestBuilder extends APIRequestBuilder {
{
return Json::decode($rawBody);
}
catch (JsonException $e)
catch (JsonException)
{
// dump($e);
dump($rawBody);

View File

@ -19,14 +19,12 @@ namespace Aviat\AnimeClient\API\Kitsu;
trait RequestBuilderTrait {
/**
* The request builder for the Kitsu API
* @var RequestBuilder
*/
protected RequestBuilder $requestBuilder;
/**
* Set the request builder object
*
* @param RequestBuilder $requestBuilder
* @return RequestBuilderTrait|ListItem|Model
*/
public function setRequestBuilder(RequestBuilder $requestBuilder): self

View File

@ -146,4 +146,5 @@ final class AnimeListTransformer extends AbstractTransformer {
return $untransformed;
}
}
// End of AnimeListTransformer.php

View File

@ -30,7 +30,6 @@ final class AnimeTransformer extends AbstractTransformer {
* logical and workable structure
*
* @param array|object $item API library item
* @return AnimePage
*/
public function transform(array|object $item): AnimePage
{
@ -47,7 +46,7 @@ final class AnimeTransformer extends AbstractTransformer {
$titles = Kitsu::getTitles($base['titles']);
$titles_more = Kitsu::filterLocalizedTitles($base['titles']);
if (count($base['characters']['nodes']) > 0)
if ((is_countable($base['characters']['nodes']) ? count($base['characters']['nodes']) : 0) > 0)
{
foreach ($base['characters']['nodes'] as $rawCharacter)
{
@ -80,7 +79,7 @@ final class AnimeTransformer extends AbstractTransformer {
krsort($characters);
}
if (count($base['staff']['nodes']) > 0)
if ((is_countable($base['staff']['nodes']) ? count($base['staff']['nodes']) : 0) > 0)
{
foreach ($base['staff']['nodes'] as $staffing)
{
@ -113,7 +112,7 @@ final class AnimeTransformer extends AbstractTransformer {
ksort($staff);
}
if (count($base['mappings']['nodes']) > 0)
if ((is_countable($base['mappings']['nodes']) ? count($base['mappings']['nodes']) : 0) > 0)
{
$links = Kitsu::mappingsToUrls($base['mappings']['nodes'], "https://kitsu.io/anime/{$base['slug']}");
}

View File

@ -27,10 +27,6 @@ use Locale;
*/
final class CharacterTransformer extends AbstractTransformer {
/**
* @param array|object $item
* @return Character
*/
public function transform(array|object $item): Character
{
$item = (array)$item;
@ -42,10 +38,7 @@ final class CharacterTransformer extends AbstractTransformer {
];
$names = array_unique(
array_merge(
[$data['names']['canonical']],
array_values($data['names']['localized'])
)
[...[$data['names']['canonical']], ...array_values($data['names']['localized'])]
);
$name = array_shift($names);
@ -66,6 +59,9 @@ final class CharacterTransformer extends AbstractTransformer {
]);
}
/**
* @return array<int, mixed[]>
*/
protected function organizeMediaAndVoices (array $data): array
{
if (empty($data))
@ -106,7 +102,7 @@ final class CharacterTransformer extends AbstractTransformer {
];
// And now, reorganize voice actor relationships
$rawVoices = array_filter($data, fn($item) => (! empty($item['voices'])) && count((array)$item['voices']['nodes']) > 0);
$rawVoices = array_filter($data, fn($item) => (! empty($item['voices'])) && (array)$item['voices']['nodes'] !== []);
if (empty($rawVoices))
{

View File

@ -51,13 +51,10 @@ abstract class HistoryTransformer {
/**
* @var array The mapping of api status to display status
*/
protected array $statusMap;
protected array $statusMap = [];
/**
* Convert raw history
*
* @param array $data
* @return array
*/
public function transform(array $data): array
{
@ -99,9 +96,6 @@ abstract class HistoryTransformer {
/**
* Combine consecutive 'progressed' events
*
* @param array $singles
* @return array
*/
protected function aggregate (array $singles): array
{
@ -143,6 +137,7 @@ abstract class HistoryTransformer {
$items[] = array_pop($progressItem);
$updated[] = $e['updated'];
}
$firstItem = min($items);
$lastItem = max($items);
$firstUpdate = min($updated);

View File

@ -140,4 +140,5 @@ final class MangaListTransformer extends AbstractTransformer {
return $map;
}
}
// End of MangaListTransformer.php

View File

@ -30,7 +30,6 @@ final class MangaTransformer extends AbstractTransformer {
* logical and workable structure
*
* @param array|object $item API library item
* @return MangaPage
*/
public function transform(array|object $item): MangaPage
{
@ -46,7 +45,7 @@ final class MangaTransformer extends AbstractTransformer {
$titles = Kitsu::getTitles($base['titles']);
$titles_more = Kitsu::filterLocalizedTitles($base['titles']);
if (count($base['characters']['nodes']) > 0)
if ((is_countable($base['characters']['nodes']) ? count($base['characters']['nodes']) : 0) > 0)
{
foreach ($base['characters']['nodes'] as $rawCharacter)
{
@ -79,7 +78,7 @@ final class MangaTransformer extends AbstractTransformer {
krsort($characters);
}
if (count($base['staff']['nodes']) > 0)
if ((is_countable($base['staff']['nodes']) ? count($base['staff']['nodes']) : 0) > 0)
{
foreach ($base['staff']['nodes'] as $staffing)
{
@ -112,7 +111,7 @@ final class MangaTransformer extends AbstractTransformer {
ksort($staff);
}
if (count($base['mappings']['nodes']) > 0)
if ((is_countable($base['mappings']['nodes']) ? count($base['mappings']['nodes']) : 0) > 0)
{
$links = Kitsu::mappingsToUrls($base['mappings']['nodes'], "https://kitsu.io/manga/{$base['slug']}");
}

View File

@ -25,10 +25,6 @@ use Aviat\Ion\Transformer\AbstractTransformer;
*/
final class PersonTransformer extends AbstractTransformer {
/**
* @param array|object $item
* @return Person
*/
public function transform(array|object $item): Person
{
$item = (array)$item;
@ -49,6 +45,9 @@ final class PersonTransformer extends AbstractTransformer {
]);
}
/**
* @return array<string, array<int|string, array<int|string, array<int|string, array<int|string, mixed>>>>>
*/
protected function organizeData(array $data): array
{
$output = [
@ -59,13 +58,14 @@ final class PersonTransformer extends AbstractTransformer {
$characters = [];
$staff = [];
if (count($data['mediaStaff']['nodes']) > 0)
if ((is_countable($data['mediaStaff']['nodes']) ? count($data['mediaStaff']['nodes']) : 0) > 0)
{
$roles = array_unique(array_column($data['mediaStaff']['nodes'], 'role'));
foreach ($roles as $role)
{
$staff[$role] = [];
}
ksort($staff);
foreach ($data['mediaStaff']['nodes'] as $staffing)
@ -94,7 +94,7 @@ final class PersonTransformer extends AbstractTransformer {
$output['staff'] = $staff;
}
if (count($data['voices']['nodes']) > 0)
if ((is_countable($data['voices']['nodes']) ? count($data['voices']['nodes']) : 0) > 0)
{
foreach ($data['voices']['nodes'] as $voicing)
{

View File

@ -56,8 +56,7 @@ final class UserTransformer extends AbstractTransformer {
/**
* Reorganize favorites data to be more useful
*
* @param array $rawFavorites
* @return array
* @return array<string, array<int|string, mixed>>
*/
private function organizeFavorites(array $rawFavorites): array
{
@ -72,6 +71,9 @@ final class UserTransformer extends AbstractTransformer {
return $output;
}
/**
* @return array<string, string>
*/
private function organizeStats(array $stats, array $data = []): array
{
$animeStats = [];

View File

@ -30,17 +30,11 @@ final class ParallelAPIRequest {
/**
* Set of requests to make in parallel
*
* @var array
*/
private array $requests = [];
/**
* Add a request
*
* @param string|Request $request
* @param string|int|null $key
* @return self
*/
public function addRequest(string|Request $request, string|int|null $key = NULL): self
{
@ -58,7 +52,6 @@ final class ParallelAPIRequest {
* Add multiple requests
*
* @param string[]|Request[] $requests
* @return self
*/
public function addRequests(array $requests): self
{
@ -69,8 +62,8 @@ final class ParallelAPIRequest {
/**
* Make the requests, and return the body for each
*
* @return array
* @throws Throwable
* @return mixed[]
*/
public function makeRequests(): array
{
@ -80,7 +73,7 @@ final class ParallelAPIRequest {
foreach ($this->requests as $key => $url)
{
$promises[$key] = call(static function () use ($client, $url) {
$promises[$key] = call(static function () use ($client, $url): \Generator {
$response = yield $client->request($url);
return yield $response->getBody()->buffer();
});
@ -92,8 +85,8 @@ final class ParallelAPIRequest {
/**
* Make the requests and return the response objects
*
* @return array
* @throws Throwable
* @return mixed[]
*/
public function getResponses(): array
{

View File

@ -34,13 +34,11 @@ use function Aviat\Ion\_dir;
// ----------------------------------------------------------------------------
//! TOML Functions
// ----------------------------------------------------------------------------
/**
* Load configuration options from .toml files
*
* @codeCoverageIgnore
* @param string $path - Path to load config
* @return array
*/
function loadConfig(string $path): array
{
@ -82,8 +80,6 @@ function loadConfig(string $path): array
* Load config from one specific TOML file
*
* @codeCoverageIgnore
* @param string $filename
* @return array
*/
function loadTomlFile(string $filename): array
{
@ -122,9 +118,6 @@ function _iterateToml(TomlBuilder $builder, iterable $data, mixed $parentKey = N
/**
* Serialize config data into a Toml file
*
* @param iterable $data
* @return string
*/
function arrayToToml(iterable $data): string
{
@ -137,9 +130,6 @@ function arrayToToml(iterable $data): string
/**
* Serialize toml back to an array
*
* @param string $toml
* @return array
*/
function tomlToArray(string $toml): array
{
@ -156,8 +146,6 @@ if ( ! function_exists('array_is_list'))
* Polyfill for PHP 8
*
* @see https://www.php.net/manual/en/function.array-is-list
* @param array $a
* @return bool
*/
function array_is_list(array $a): bool
{
@ -167,9 +155,6 @@ if ( ! function_exists('array_is_list'))
/**
* Is the array sequential, not associative?
*
* @param mixed $array
* @return bool
*/
function isSequentialArray(mixed $array): bool
{
@ -183,9 +168,6 @@ function isSequentialArray(mixed $array): bool
/**
* Check that folder permissions are correct for proper operation
*
* @param ConfigInterface $config
* @return array
*/
function checkFolderPermissions(ConfigInterface $config): array
{
@ -224,8 +206,6 @@ function checkFolderPermissions(ConfigInterface $config): array
/**
* Get an API Client, with better defaults
*
* @return HttpClient
*/
function getApiClient (): HttpClient
{
@ -242,8 +222,6 @@ function getApiClient (): HttpClient
/**
* Simplify making a request with Http\Client
*
* @param string|Request $request
* @return Response
* @throws Throwable
*/
function getResponse (Request|string $request): Response
@ -260,10 +238,6 @@ function getResponse (Request|string $request): Response
/**
* Generate the path for the cached image from the original image
*
* @param string $kitsuUrl
* @param bool $webp
* @return string
*/
function getLocalImg (string $kitsuUrl, bool $webp = TRUE): string
{
@ -297,11 +271,6 @@ function getLocalImg (string $kitsuUrl, bool $webp = TRUE): string
* Create a transparent placeholder image
*
* @codeCoverageIgnore
* @param string $path
* @param int $width
* @param int $height
* @param string $text
* @return bool
*/
function createPlaceholderImage (string $path, int $width = 200, int $height = 200, string $text = 'Image Unavailable'): bool
{
@ -322,22 +291,15 @@ function createPlaceholderImage (string $path, int $width = 200, int $height = 2
/**
* Check that there is a value for at least one item in a collection with the specified key
*
* @param array $search
* @param string $key
* @return bool
*/
function colNotEmpty(array $search, string $key): bool
{
$items = array_filter(array_column($search, $key), static fn ($x) => ( ! empty($x)));
return count($items) > 0;
return $items !== [];
}
/**
* Clear the cache, but save user auth data
*
* @param CacheInterface $cache
* @return bool
*/
function clearCache(CacheInterface $cache): bool
{
@ -350,9 +312,10 @@ function clearCache(CacheInterface $cache): bool
]);
$userData = array_filter((array)$userData, static fn ($value) => $value !== NULL);
$cleared = $cache->clear();
$saved = ( ! empty($userData)) ? $cache->setMultiple($userData) : TRUE;
$saved = ( empty($userData)) ? TRUE : $cache->setMultiple($userData);
return $cleared && $saved;
}
@ -361,9 +324,6 @@ function clearCache(CacheInterface $cache): bool
* Render a PHP code template as a string
*
* @codeCoverageIgnore
* @param string $path
* @param array $data
* @return string
*/
function renderTemplate(string $path, array $data): string
{

View File

@ -46,11 +46,6 @@ abstract class BaseCommand extends Command {
/**
* Echo text in a box
*
* @param string|array $message
* @param string|int|null $fgColor
* @param string|int|null $bgColor
* @return void
*/
public function echoBox(string|array $message, string|int|null $fgColor = NULL, string|int|null $bgColor = NULL): void
{
@ -63,6 +58,7 @@ abstract class BaseCommand extends Command {
{
$fgColor = (int)$fgColor;
}
if ($bgColor !== NULL)
{
$bgColor = (int)$bgColor;
@ -123,7 +119,7 @@ abstract class BaseCommand extends Command {
*/
public function setupContainer(): ContainerInterface
{
$APP_DIR = _dir(dirname(dirname(SRC_DIR)), 'app');
$APP_DIR = _dir(dirname(SRC_DIR, 2), 'app');
$APPCONF_DIR = _dir($APP_DIR, 'appConf');
$CONF_DIR = _dir($APP_DIR, 'config');
$baseConfig = require _dir($APPCONF_DIR, 'base_config.php');
@ -146,6 +142,7 @@ abstract class BaseCommand extends Command {
{
$fgColor = (int)$fgColor;
}
if ($bgColor !== NULL)
{
$bgColor = (int)$bgColor;
@ -168,6 +165,7 @@ abstract class BaseCommand extends Command {
$appLogger = new Logger('animeclient');
$appLogger->pushHandler(new RotatingFileHandler($APP_DIR . '/logs/app-cli.log', 2, Logger::WARNING));
$container->setLogger($appLogger);
foreach (['kitsu-request', 'anilist-request', 'anilist-request-cli', 'kitsu-request-cli'] as $channel)
@ -184,7 +182,7 @@ abstract class BaseCommand extends Command {
$container->set('config', fn () => new Config($configArray));
// Create Cache Object
$container->set('cache', static function($container) {
$container->set('cache', static function($container): \Aviat\Banker\Teller {
$logger = $container->getLogger();
$config = $container->get('config')->get('cache');
return new Teller($config, $logger);

View File

@ -27,11 +27,8 @@ final class CacheClear extends BaseCommand {
/**
* Clear the API cache
*
* @param array $args
* @param array $options
* @throws ContainerException
* @throws NotFoundException
* @return void
*/
public function execute(array $args, array $options = []): void
{

View File

@ -27,11 +27,8 @@ final class CachePrime extends BaseCommand {
/**
* Clear, then prime the API cache
*
* @param array $args
* @param array $options
* @throws ContainerException
* @throws NotFoundException
* @return void
*/
public function execute(array $args, array $options = []): void
{

View File

@ -124,8 +124,6 @@ final class SyncLists extends BaseCommand {
/**
* Get and display the count of items for each API
*
* @param string $type
*/
protected function fetchCount(string $type): void
{
@ -150,8 +148,7 @@ final class SyncLists extends BaseCommand {
/**
* Get the list data
*
* @param string $type
* @return array
* @return array<string, mixed[]>
*/
protected function fetch(string $type): array
{
@ -175,9 +172,7 @@ final class SyncLists extends BaseCommand {
/**
* Normalize the list data for comparison
*
* @param string $type
* @param array $data
* @return array
* @return array<string, mixed[]>
*/
protected function transform(string $type, array $data): array
{
@ -201,9 +196,7 @@ final class SyncLists extends BaseCommand {
/**
* Compare the lists data
*
* @param string $type
* @param array $data
* @return array
* @return array<string, mixed[]>
*/
protected function compare(string $type, array $data): array
{
@ -215,22 +208,20 @@ final class SyncLists extends BaseCommand {
/**
* Updated outdated list items
*
* @param string $type
* @param array $data
* @throws Throwable
*/
protected function update(string $type, array $data): void
{
if ( ! empty($data['addToAnilist']))
{
$count = count($data['addToAnilist']);
$count = is_countable($data['addToAnilist']) ? count($data['addToAnilist']) : 0;
$this->echoBox("Adding {$count} missing {$type} list items to Anilist");
$this->updateAnilistListItems($data['addToAnilist'], SyncAction::CREATE, $type);
}
if ( ! empty($data['updateAnilist']))
{
$count = count($data['updateAnilist']);
$count = is_countable($data['updateAnilist']) ? count($data['updateAnilist']) : 0;
$this->echoBox("Updating {$count} outdated Anilist {$type} list items");
$this->updateAnilistListItems($data['updateAnilist'], SyncAction::UPDATE, $type);
}
@ -239,14 +230,14 @@ final class SyncLists extends BaseCommand {
{
if ( ! empty($data['addToKitsu']))
{
$count = count($data['addToKitsu']);
$count = is_countable($data['addToKitsu']) ? count($data['addToKitsu']) : 0;
$this->echoBox("Adding {$count} missing {$type} list items to Kitsu");
$this->updateKitsuListItems($data['addToKitsu'], SyncAction::CREATE, $type);
}
if ( ! empty($data['updateKitsu']))
{
$count = count($data['updateKitsu']);
$count = is_countable($data['updateKitsu']) ? count($data['updateKitsu']) : 0;
$this->echoBox("Updating {$count} outdated Kitsu {$type} list items");
$this->updateKitsuListItems($data['updateKitsu'], SyncAction::UPDATE, $type);
}
@ -279,6 +270,9 @@ final class SyncLists extends BaseCommand {
return $count;
}
/**
* @return mixed[]
*/
private function fetchAnilist(string $type): array
{
static $list = [
@ -310,6 +304,9 @@ final class SyncLists extends BaseCommand {
return $this->kitsuModel->{"get{$uType}ListCount"}() ?? 0;
}
/**
* @return mixed[]
*/
private function fetchKitsu(string $type): array
{
return $this->kitsuModel->getSyncList($type);
@ -318,7 +315,9 @@ final class SyncLists extends BaseCommand {
// ------------------------------------------------------------------------
// Transform Helpers
// ------------------------------------------------------------------------
/**
* @return mixed[]
*/
private function transformKitsu(string $type, array $data): array
{
if (empty($data))
@ -335,6 +334,7 @@ final class SyncLists extends BaseCommand {
{
continue;
}
$malId = NULL;
foreach ($listItem['media']['mappings']['nodes'] as $mapping)
@ -375,6 +375,9 @@ final class SyncLists extends BaseCommand {
return $output;
}
/**
* @return array<int|string, mixed>
*/
private function transformAnilist(string $type, array $data): array
{
$uType = ucfirst($type);
@ -403,7 +406,9 @@ final class SyncLists extends BaseCommand {
// ------------------------------------------------------------------------
// Compare Helpers
// ------------------------------------------------------------------------
/**
* @return array<string, mixed[]>
*/
private function compareLists(string $type, array $anilistList, array $kitsuList): array
{
$itemsToAddToAnilist = [];
@ -486,10 +491,6 @@ final class SyncLists extends BaseCommand {
/**
* Compare two list items, and return the out of date one, if one exists
*
* @param array $kitsuItem
* @param array $anilistItem
* @return array|null
*/
private function compareListItems(array $kitsuItem, array $anilistItem): ?array
{
@ -708,13 +709,9 @@ final class SyncLists extends BaseCommand {
// ------------------------------------------------------------------------
// Update Helpers
// ------------------------------------------------------------------------
/**
* Create/Update list items on Kitsu
*
* @param array $itemsToUpdate
* @param string $action
* @param string $type
* @throws Throwable
*/
private function updateKitsuListItems(array $itemsToUpdate, string $action = SyncAction::UPDATE, string $type = MediaType::ANIME): void
@ -736,6 +733,7 @@ final class SyncLists extends BaseCommand {
$this->echoWarning("Skipped creating Kitsu {$type} due to missing id ¯\_(ツ)_/¯");
continue;
}
$requester->addRequest($maybeRequest);
}
}
@ -781,9 +779,6 @@ final class SyncLists extends BaseCommand {
/**
* Create/Update list items on Anilist
*
* @param array $itemsToUpdate
* @param string $action
* @param string $type
* @throws Throwable
*/
private function updateAnilistListItems(array $itemsToUpdate, string $action = SyncAction::UPDATE, string $type = MediaType::ANIME): void
@ -806,11 +801,11 @@ final class SyncLists extends BaseCommand {
{
$requester->addRequest($this->anilistModel->createFullListItem($item, $type));
}
catch (MissingIdException $e)
catch (MissingIdException)
{
// Case where there's a MAL mapping from Kitsu, but no equivalent Anlist item
$id = $item['mal_id'];
$this->echoWarning("Skipping Anilist ${type} with MAL id: {$id} due to missing mapping");
$this->echoWarning("Skipping Anilist {$type} with MAL id: {$id} due to missing mapping");
}
}
}

View File

@ -26,7 +26,6 @@ use Aviat\AnimeClient\Controller\Images;
final class UpdateThumbnails extends ClearThumbnails {
/**
* Model for making requests to Kitsu API
* @var KitsuModel
*/
protected KitsuModel $kitsuModel;

View File

@ -28,10 +28,6 @@ trait ComponentTrait {
/**
* Render a template with common container values
*
* @param string $path
* @param array $data
* @return string
*/
public function render(string $path, array $data): string
{

View File

@ -26,9 +26,6 @@ final class Tabs {
* 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
* @param bool $hasSectionWrapper
* @return string
*/
public function __invoke(
string $name,

View File

@ -26,8 +26,6 @@ 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(
string $name,

View File

@ -169,7 +169,6 @@ class Controller {
*
* @codeCoverageIgnore
* @throws InvalidArgumentException
* @return void
*/
public function sessionRedirect(): void
{
@ -200,9 +199,6 @@ class Controller {
*
* @codeCoverageIgnore
* @param HtmlView $view
* @param string $template
* @param array $data
* @return string
*/
protected function loadPartial(HtmlView $view, string $template, array $data = []): string
{
@ -232,8 +228,6 @@ class Controller {
*
* @codeCoverageIgnore
* @param HtmlView $view
* @param string $template
* @param array $data
* @return HtmlView
*/
protected function renderFullPage(HtmlView $view, string $template, array $data): HtmlView
@ -262,10 +256,7 @@ class Controller {
* 404 action
*
* @codeCoverageIgnore
* @param string $title
* @param string $message
* @throws InvalidArgumentException
* @return void
*/
public function notFound(
string $title = 'Sorry, page not found',
@ -283,12 +274,7 @@ class Controller {
* Display a generic error page
*
* @codeCoverageIgnore
* @param int $httpCode
* @param string $title
* @param string $message
* @param string $longMessage
* @throws InvalidArgumentException
* @return void
*/
public function errorPage(int $httpCode, string $title, string $message, string $longMessage = ''): void
{
@ -304,7 +290,6 @@ class Controller {
*
* @codeCoverageIgnore
* @throws InvalidArgumentException
* @return void
*/
public function redirectToDefaultRoute(): void
{
@ -317,9 +302,6 @@ class Controller {
* next page load
*
* @codeCoverageIgnore
* @param string $message
* @param string $type
* @return void
*/
public function setFlashMessage(string $message, string $type = 'info'): void
{
@ -342,7 +324,6 @@ class Controller {
* Helper for consistent page titles
*
* @param string ...$parts Title segments
* @return string
*/
public function formatTitle(string ...$parts) : string
{
@ -354,10 +335,7 @@ class Controller {
*
* @codeCoverageIgnore
* @param HtmlView $view
* @param string $type
* @param string $message
* @throws InvalidArgumentException
* @return string
*/
protected function showMessage(HtmlView $view, string $type, string $message): string
{
@ -371,11 +349,7 @@ class Controller {
* Output a template to HTML, using the provided data
*
* @codeCoverageIgnore
* @param string $template
* @param array $data
* @param HtmlView|NULL $view
* @param int $code
* @return void
*@throws InvalidArgumentException
*/
protected function outputHTML(string $template, array $data = [], HtmlView $view = NULL, int $code = 200): void
@ -393,10 +367,8 @@ class Controller {
* Output a JSON Response
*
* @codeCoverageIgnore
* @param mixed $data
* @param int $code - the http status code
* @throws DoubleRenderException
* @return void
*/
protected function outputJSON(mixed $data, int $code): void
{
@ -410,9 +382,6 @@ class Controller {
* Redirect to the selected page
*
* @codeCoverageIgnore
* @param string $url
* @param int $code
* @return void
*/
protected function redirect(string $url, int $code): void
{
@ -423,4 +392,5 @@ class Controller {
catch (\Throwable) {}
}
}
// End of BaseController.php

View File

@ -39,14 +39,12 @@ final class Anime extends BaseController {
/**
* The anime list model
* @var AnimeModel $model
*/
protected AnimeModel $model;
/**
* Constructor
*
* @param ContainerInterface $container
* @throws ContainerException
* @throws NotFoundException
*/
@ -68,7 +66,6 @@ final class Anime extends BaseController {
*
* @param int|string $status - The section of the list
* @param string|null $view - List or cover view
* @return void
* @throws InvalidArgumentException
* @throws Throwable
*/
@ -116,7 +113,6 @@ final class Anime extends BaseController {
* @throws RouteNotFound
* @throws InvalidArgumentException
* @throws Throwable
* @return void
*/
public function addForm(): void
{
@ -137,7 +133,6 @@ final class Anime extends BaseController {
* Add an anime to the list
*
* @throws Throwable
* @return void
*/
public function add(): void
{
@ -172,9 +167,6 @@ final class Anime extends BaseController {
/**
* Form to edit details about a series
*
* @param string $id
* @param string $status
*/
public function edit(string $id, string $status = 'all'): void
{
@ -198,8 +190,6 @@ final class Anime extends BaseController {
/**
* Search for anime
*
* @return void
*/
public function search(): void
{
@ -212,7 +202,6 @@ final class Anime extends BaseController {
* Update an anime item via a form submission
*
* @throws Throwable
* @return void
*/
public function formUpdate(): void
{
@ -243,7 +232,6 @@ final class Anime extends BaseController {
* Increase the watched count for an anime item
*
* @throws Throwable
* @return void
*/
public function increment(): void
{
@ -274,7 +262,6 @@ final class Anime extends BaseController {
* Remove an anime from the list
*
* @throws Throwable
* @return void
*/
public function delete(): void
{
@ -299,9 +286,7 @@ final class Anime extends BaseController {
/**
* View details of an anime
*
* @param string $id
* @throws InvalidArgumentException
* @return void
*/
public function details(string $id): void
{
@ -379,4 +364,5 @@ final class Anime extends BaseController {
}
}
}
// End of AnimeController.php

View File

@ -49,7 +49,6 @@ final class AnimeCollection extends BaseController {
/**
* Constructor
*
* @param ContainerInterface $container
* @throws ContainerException
* @throws NotFoundException
*/
@ -76,7 +75,6 @@ final class AnimeCollection extends BaseController {
* Search for anime
*
* @throws DoubleRenderException
* @return void
*/
public function search(): void
{
@ -88,11 +86,9 @@ final class AnimeCollection extends BaseController {
/**
* Show the anime collection page
*
* @param string|null $view
* @throws ContainerException
* @throws NotFoundException
* @throws InvalidArgumentException
* @return void
*/
public function view(?string $view = ''): void
{
@ -120,7 +116,6 @@ final class AnimeCollection extends BaseController {
* @throws NotFoundException
* @throws RouteNotFound
* @throws InvalidArgumentException
* @return void
*/
public function form($id = NULL): void
{
@ -149,7 +144,6 @@ final class AnimeCollection extends BaseController {
* @throws ContainerException
* @throws NotFoundException
* @throws InvalidArgumentException
* @return void
*/
public function edit(): void
{
@ -163,7 +157,6 @@ final class AnimeCollection extends BaseController {
* @throws ContainerException
* @throws NotFoundException
* @throws InvalidArgumentException
* @return void
*/
public function add(): void
{
@ -211,8 +204,6 @@ final class AnimeCollection extends BaseController {
/**
* Remove a collection item
*
* @return void
*/
public function delete(): void
{
@ -237,8 +228,6 @@ final class AnimeCollection extends BaseController {
/**
* Update a collection item
*
* @param array $data
*/
protected function update(array $data): void
{
@ -259,4 +248,5 @@ final class AnimeCollection extends BaseController {
$this->sessionRedirect();
}
}
// End of AnimeCollection.php

View File

@ -29,15 +29,11 @@ use Aviat\Ion\Di\Exception\NotFoundException;
*/
final class Character extends BaseController {
/**
* @var Model
*/
private Model $model;
/**
* Character constructor.
*
* @param ContainerInterface $container
* @throws ContainerException
* @throws NotFoundException
*/
@ -49,9 +45,6 @@ final class Character extends BaseController {
/**
* Show information about a character
*
* @param string $slug
* @return void
*/
public function index(string $slug): void
{

View File

@ -29,20 +29,17 @@ use Aviat\Ion\Di\Exception\NotFoundException;
final class History extends BaseController {
/**
* The anime list model
* @var AnimeModel
*/
protected AnimeModel $animeModel;
/**
* The manga list model
* @var MangaModel
*/
protected MangaModel $mangaModel;
/**
* Constructor
*
* @param ContainerInterface $container
* @throws ContainerException
* @throws NotFoundException
*/

View File

@ -34,7 +34,6 @@ 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
* @return void
* @throws Throwable
*/
public function cache(string $type, string $file, bool $display = TRUE): void
@ -123,6 +122,7 @@ final class Images extends BaseController {
{
createPlaceholderImage("{$baseSavePath}/{$type}", $width, $height);
}
return;
}
@ -177,14 +177,10 @@ final class Images extends BaseController {
/**
* Get a placeholder for a missing image
*
* @param string $path
* @param int|null $width
* @param int|null $height
*/
private function getPlaceholder (string $path, ?int $width = 200, ?int $height = NULL): void
{
$height = $height ?? $width;
$height ??= $width;
$filename = $path . '/placeholder.png';

View File

@ -36,14 +36,12 @@ final class Manga extends Controller {
/**
* The manga model
* @var MangaModel $model
*/
protected MangaModel $model;
/**
* Constructor
*
* @param ContainerInterface $container
* @throws ContainerException
* @throws NotFoundException
*/
@ -62,9 +60,7 @@ final class Manga extends Controller {
/**
* Get a section of the manga list
*
* @param string $status
* @param string $view
* @return void
*@throws InvalidArgumentException
*/
public function index(string $status = 'all', ?string $view = ''): void
@ -110,7 +106,6 @@ final class Manga extends Controller {
* @throws NotFoundException
* @throws RouteNotFound
* @throws InvalidArgumentException
* @return void
*/
public function addForm(): void
{
@ -132,7 +127,6 @@ final class Manga extends Controller {
/**
* Add an manga to the list
*
* @return void
* @throws Throwable
*/
public function add(): void
@ -168,13 +162,10 @@ final class Manga extends Controller {
/**
* Show the manga edit form
*
* @param string $id
* @param string $status
* @throws ContainerException
* @throws NotFoundException
* @throws RouteNotFound
* @throws InvalidArgumentException
* @return void
*/
public function edit(string $id, string $status = 'All'): void
{
@ -199,8 +190,6 @@ final class Manga extends Controller {
/**
* Search for a manga to add to the list
*
* @return void
*/
public function search(): void
{
@ -212,7 +201,6 @@ final class Manga extends Controller {
/**
* Update an manga item via a form submission
*
* @return void
* @throws Throwable
*/
public function formUpdate(): void
@ -270,7 +258,6 @@ final class Manga extends Controller {
* Remove an manga from the list
*
* @throws Throwable
* @return void
*/
public function delete(): void
{
@ -295,10 +282,8 @@ final class Manga extends Controller {
/**
* View details of an manga
*
* @param string $id
* @throws InvalidArgumentException
* @throws Throwable
* @return void
*/
public function details(string $id): void
{
@ -329,7 +314,6 @@ final class Manga extends Controller {
*
* @throws InvalidArgumentException
* @throws Throwable
* @return void
*/
public function random(): void
{
@ -355,4 +339,5 @@ final class Manga extends Controller {
]);
}
}
// End of MangaController.php

View File

@ -27,8 +27,6 @@ use Aviat\Ion\View\HtmlView;
final class Misc extends BaseController {
/**
* Purges the API cache
*
* @return void
*/
public function clearCache(): void
{
@ -43,9 +41,6 @@ final class Misc extends BaseController {
/**
* Show the login form
*
* @param string $status
* @return void
*/
public function login(string $status = ''): void
{
@ -69,8 +64,6 @@ final class Misc extends BaseController {
/**
* Attempt login authentication
*
* @return void
*/
public function loginAction(): void
{
@ -92,8 +85,6 @@ final class Misc extends BaseController {
/**
* Deauthorize the current user
*
* @return void
*/
public function logout(): void
{

View File

@ -29,15 +29,11 @@ use Aviat\Ion\Di\Exception\NotFoundException;
*/
final class People extends BaseController {
/**
* @var Model
*/
private Model $model;
/**
* People constructor.
*
* @param ContainerInterface $container
* @throws ContainerException
* @throws NotFoundException
*/
@ -49,9 +45,6 @@ final class People extends BaseController {
/**
* Show information about a person
*
* @param string $slug
* @return void
*/
public function index(string $slug): void
{

View File

@ -29,20 +29,13 @@ use Aviat\Ion\Di\Exception\NotFoundException;
*/
final class Settings extends BaseController {
/**
* @var AnilistModel
*/
private AnilistModel $anilistModel;
/**
* @var SettingsModel
*/
private SettingsModel $settingsModel;
/**
* Settings constructor.
*
* @param ContainerInterface $container
* @throws ContainerException
* @throws NotFoundException
*/
@ -147,6 +140,7 @@ final class Settings extends BaseController {
{
$newSettings[$key] = $value;
}
unset($newSettings['config']);
$saved = $this->settingsModel->saveSettingsFile($newSettings);

View File

@ -29,15 +29,11 @@ use Aviat\Ion\Di\Exception\NotFoundException;
*/
final class User extends BaseController {
/**
* @var Model
*/
private Model $kitsuModel;
/**
* User constructor.
*
* @param ContainerInterface $container
* @throws ContainerException
* @throws NotFoundException
*/
@ -58,9 +54,6 @@ final class User extends BaseController {
/**
* Show the user profile page
*
* @param string $username
* @return void
*/
public function about(string $username): void
{

View File

@ -53,26 +53,23 @@ final class Dispatcher extends RoutingBase {
/**
* Routing array
* @var array
*/
protected array $routes;
protected array $routes = [];
/**
* Routes added to router
* @var array $outputRoutes
*/
protected array $outputRoutes;
protected array $outputRoutes = [];
/**
* Constructor
*
* @param ContainerInterface $container
*/
public function __construct(ContainerInterface $container)
{
parent::__construct($container);
$router = $this->container->get('aura-router');
$this->router = $router->getMap();
$this->matcher = $router->getMatcher();
$this->routes = $this->config->get('routes');
$this->outputRoutes = $this->setupRoutes();
@ -104,7 +101,7 @@ final class Dispatcher extends RoutingBase {
/**
* Get list of routes applied
*
* @return array
* @return mixed[]
*/
public function getOutputRoutes(): array
{
@ -115,7 +112,6 @@ final class Dispatcher extends RoutingBase {
* Handle the current route
*
* @param object|null $route
* @return void
* @throws ReflectionException
*/
public function __invoke(object $route = NULL): void
@ -157,9 +153,8 @@ final class Dispatcher extends RoutingBase {
* Parse out the arguments for the appropriate controller for
* the current route
*
* @param Friend $route
* @throws LogicException
* @return array
* @return array<string, mixed>
*/
protected function processRoute(Friend $route): array
{
@ -193,6 +188,7 @@ final class Dispatcher extends RoutingBase {
}
}
}
$logger = $this->container->getLogger();
if ($logger !== NULL)
{
@ -208,8 +204,6 @@ final class Dispatcher extends RoutingBase {
/**
* Get the type of route, to select the current controller
*
* @return string
*/
public function getController(): string
{
@ -237,7 +231,7 @@ final class Dispatcher extends RoutingBase {
/**
* Get the list of controllers in the default namespace
*
* @return array
* @return mixed[]
*/
public function getControllerList(): array
{
@ -247,6 +241,7 @@ final class Dispatcher extends RoutingBase {
$path = str_replace($find, $replace, $defaultNamespace);
$path = trim($path, '/');
$actualPath = realpath(_dir(SRC_DIR, $path));
$classFiles = glob("{$actualPath}/*.php");
if ($classFiles === FALSE)
@ -273,9 +268,6 @@ final class Dispatcher extends RoutingBase {
* method
*
* @param string $controllerName - The full namespace of the controller class
* @param string $method
* @param array $params
* @return void
*/
protected function call(string $controllerName, string $method, array $params): void
{
@ -299,6 +291,7 @@ final class Dispatcher extends RoutingBase {
'API request timed out',
'Failed to retrieve data from API (╯°□°)╯︵ ┻━┻');
}
/* finally
{
// Log out on session/api token expiration
@ -312,6 +305,7 @@ final class Dispatcher extends RoutingBase {
/**
* Get the appropriate params for the error page
* passed on the failed route
* @return mixed[][]
*/
protected function getErrorParams(): array
{
@ -360,7 +354,7 @@ final class Dispatcher extends RoutingBase {
/**
* Select controller based on the current url, and apply its relevant routes
*
* @return array
* @return mixed[]
*/
protected function setupRoutes(): array
{
@ -415,4 +409,5 @@ final class Dispatcher extends RoutingBase {
return $routes;
}
}
// End of Dispatcher.php

View File

@ -27,15 +27,12 @@ use Aviat\Ion\Di\Exception\NotFoundException;
final class FormGenerator {
/**
* Html generation helper
*
* @var HelperLocator
*/
private HelperLocator $helper;
/**
* FormGenerator constructor.
*
* @param ContainerInterface $container
* @throws ContainerException
* @throws NotFoundException
*/
@ -46,9 +43,6 @@ final class FormGenerator {
/**
* Create a new FormGenerator
*
* @param ContainerInterface $container
* @return self
*/
public static function new(ContainerInterface $container): self
{
@ -57,10 +51,6 @@ final class FormGenerator {
/**
* Generate the html structure of the form
*
* @param string $name
* @param array $form
* @return string
*/
public function generate(string $name, array $form): string
{

View File

@ -29,8 +29,6 @@ final class Form {
/**
* Create the html for the specified form
*
* @param string $name
* @param array $form
* @return string
*/
public function __invoke(string $name, array $form)

View File

@ -29,13 +29,13 @@ final class Menu {
/**
* Create the html for the selected menu
*
* @param string $menuName
* @return string
*/
public function __invoke($menuName)
public function __invoke(string $menuName)
{
return MenuGenerator::new($this->container)->generate($menuName);
}
}
// End of Menu.php

View File

@ -35,12 +35,6 @@ final class Picture {
/**
* Create the html for an html picture element.
* Uses .webp images with fallback
*
* @param string $uri
* @param string $fallbackExt
* @param array $picAttrs
* @param array $imgAttrs
* @return string
*/
public function __invoke(string $uri, string $fallbackExt = 'jpg', array $picAttrs = [], array $imgAttrs = []): string
{
@ -119,4 +113,5 @@ final class Picture {
return $helper->elementRaw('picture', $sources, $picAttrs);
}
}
// End of Picture.php

View File

@ -44,7 +44,6 @@ final class Kitsu {
*
* @param string|null $startDate
* @param string|null $endDate
* @return string
*/
public static function getAiringStatus(string $startDate = NULL, string $endDate = NULL): string
{
@ -73,7 +72,6 @@ final class Kitsu {
*
* @param string|null $startDate
* @param string|null $endDate
* @return string
*/
public static function formatAirDates(string $startDate = NULL, string $endDate = NULL): string
{
@ -101,7 +99,7 @@ final class Kitsu {
if ($startDate === $endDate)
{
return "{$monthMap[$startMonth]} $startDay, $startYear";
return "{$monthMap[$startMonth]} {$startDay}, {$startYear}";
}
if (empty($endDate))
@ -113,7 +111,7 @@ final class Kitsu {
if ($startYear === $endYear)
{
return "{$monthMap[$startMonth]} - {$monthMap[$endMonth]} $startYear";
return "{$monthMap[$startMonth]} - {$monthMap[$endMonth]} {$startYear}";
}
return "{$monthMap[$startMonth]} {$startYear} - {$monthMap[$endMonth]} {$endYear}";
@ -141,6 +139,9 @@ final class Kitsu {
return MangaPublishingStatus::NOT_YET_PUBLISHED;
}
/**
* @return array<string, string>
*/
public static function mappingsToUrls(array $mappings, string $kitsuLink = ''): array
{
$output = [];
@ -212,8 +213,7 @@ final class Kitsu {
/**
* Reorganize streaming links
*
* @param array $nodes
* @return array
* @return mixed[]
*/
public static function parseStreamingLinks(array $nodes): array
{
@ -257,8 +257,7 @@ final class Kitsu {
/**
* Get the list of titles
*
* @param array $titles
* @return array
* @return mixed[]
*/
public static function getTitles(array $titles): array
{
@ -273,8 +272,7 @@ final class Kitsu {
/**
* Filter out duplicate and very similar titles from a GraphQL response
*
* @param array $titles
* @return array
* @return mixed[]
*/
public static function filterLocalizedTitles(array $titles): array
{
@ -304,8 +302,7 @@ final class Kitsu {
/**
* Filter out duplicate and very similar titles from a GraphQL response
*
* @param array $titles
* @return array
* @return mixed[]
*/
public static function getFilteredTitles(array $titles): array
{
@ -338,10 +335,6 @@ final class Kitsu {
/**
* Get the url of the posterImage from Kitsu, with fallbacks
*
* @param array $base
* @param int $size
* @return string
*/
public static function getPosterImage(array $base, int $size = 1): string
{
@ -351,14 +344,14 @@ final class Kitsu {
$parts = explode('?', $rawUrl);
return ( ! empty($parts)) ? $parts[0] : $rawUrl;
return ( empty($parts)) ? $rawUrl : $parts[0];
}
/**
* Get the name and logo for the streaming service of the current link
*
* @param string|null $hostname
* @return array
* @return string[]|bool[]
*/
protected static function getServiceMetaData(string $hostname = NULL): array
{
@ -433,9 +426,6 @@ final class Kitsu {
/**
* Convert a time in seconds to a more human-readable format
*
* @param int $seconds
* @return string
*/
public static function friendlyTime(int $seconds): string
{
@ -481,7 +471,7 @@ final class Kitsu {
if (empty($parts))
{
return ($last !== NULL) ? $last : '';
return $last ?? '';
}
return (count($parts) > 1)
@ -491,10 +481,6 @@ final class Kitsu {
/**
* Determine if an alternate title is unique enough to list
*
* @param string|null $title
* @param array $existingTitles
* @return bool
*/
protected static function titleIsUnique(?string $title = '', array $existingTitles = []): bool
{

View File

@ -31,22 +31,14 @@ final class MenuGenerator extends UrlGenerator {
/**
* Html generation helper
*
* @var HelperLocator
*/
protected HelperLocator $helper;
/**
* Request object
*
* @var ServerRequestInterface
*/
protected ServerRequestInterface $request;
/**
* @param ContainerInterface $container
* @return self
*/
public static function new(ContainerInterface $container): self
{
return new self($container);
@ -55,9 +47,7 @@ final class MenuGenerator extends UrlGenerator {
/**
* Generate the html structure of the menu selected
*
* @param string $menu
* @throws ConfigException
* @return string
*/
public function generate(string $menu) : string
{
@ -96,7 +86,6 @@ final class MenuGenerator extends UrlGenerator {
/**
* MenuGenerator constructor.
*
* @param ContainerInterface $container
* @throws ContainerException
* @throws NotFoundException
*/
@ -110,8 +99,7 @@ final class MenuGenerator extends UrlGenerator {
/**
* Generate the full menu structure from the config files
*
* @param array $menus
* @return array
* @return array<mixed, array<string, string>>
*/
private function parseConfig(array $menus) : array
{
@ -130,4 +118,5 @@ final class MenuGenerator extends UrlGenerator {
return $parsed;
}
}
// End of MenuGenerator.php

View File

@ -22,10 +22,6 @@ namespace Aviat\AnimeClient\Model;
abstract class API {
/**
* Sort the list entries by their title
*
* @param array $array
* @param string $sortKey
* @return void
*/
protected function sortByName(array &$array, string $sortKey): void
{

View File

@ -30,8 +30,7 @@ class Anime extends API {
/**
* Get a category out of the full list
*
* @param string $status
* @return array
* @return array<string, mixed>
*/
public function getList(string $status): array
{
@ -49,7 +48,7 @@ class Anime extends API {
/**
* Get data for the 'all' anime page
*
* @return array
* @return mixed[]
*/
public function getAllLists(): array
{
@ -65,9 +64,6 @@ class Anime extends API {
/**
* Get information about an anime from its slug
*
* @param string $slug
* @return AnimeType
*/
public function getAnime(string $slug): AnimeType
{
@ -76,8 +72,6 @@ class Anime extends API {
/**
* Get information about a random anime
*
* @return AnimeType
*/
public function getRandomAnime(): AnimeType
{
@ -86,9 +80,6 @@ class Anime extends API {
/**
* Get anime by its kitsu id
*
* @param string $animeId
* @return AnimeType
*/
public function getAnimeById(string $animeId): AnimeType
{
@ -98,7 +89,7 @@ class Anime extends API {
/**
* Get recent watch history
*
* @return array
* @return mixed[]
*/
public function getHistory(): array
{

View File

@ -28,14 +28,11 @@ final class AnimeCollection extends Collection {
/**
* Anime API Model
* @var Anime $animeModel
*/
protected Anime $animeModel;
/**
* Create the collection model
*
* @param ContainerInterface $container
*/
public function __construct(ContainerInterface $container)
{
@ -46,7 +43,7 @@ final class AnimeCollection extends Collection {
/**
* Get collection from the database, and organize by media type
*
* @return array
* @return mixed[]
*/
public function getCollection(): array
{
@ -77,7 +74,7 @@ final class AnimeCollection extends Collection {
/**
* Get the collection from the database
*
* @return array
* @return mixed[]
*/
public function getFlatCollection(): array
{
@ -123,7 +120,7 @@ final class AnimeCollection extends Collection {
/**
* Get list of media types
*
* @return array
* @return array<string, mixed[]>
*/
public function getMediaTypeList(): array
{
@ -173,9 +170,6 @@ final class AnimeCollection extends Collection {
/**
* Add an item to the anime collection
*
* @param mixed $data
* @return void
*/
public function add(mixed $data): void
{
@ -212,9 +206,6 @@ final class AnimeCollection extends Collection {
/**
* Verify that an item was added
*
* @param array $data
* @return bool
*/
public function wasAdded(array $data): bool
{
@ -230,9 +221,6 @@ final class AnimeCollection extends Collection {
/**
* Update a collection item
*
* @param array $data
* @return void
*/
public function update(array $data): void
{
@ -269,9 +257,7 @@ final class AnimeCollection extends Collection {
/**
* Verify that the collection item was updated
*
* @param array $data
*
* @return bool
*/
public function wasUpdated(array $data): bool
{
@ -300,9 +286,6 @@ final class AnimeCollection extends Collection {
/**
* Remove a collection item
*
* @param array $data
* @return void
*/
public function delete(array $data): void
{
@ -331,10 +314,6 @@ final class AnimeCollection extends Collection {
$this->db->commit();
}
/**
* @param array $data
* @return bool
*/
public function wasDeleted(array $data): bool
{
if ($this->db === NULL)
@ -348,8 +327,7 @@ final class AnimeCollection extends Collection {
/**
* Get the details of a collection item
*
* @param int|string $kitsuId
* @return array
* @return mixed[]
*/
public function get(int|string $kitsuId): array
{
@ -388,9 +366,6 @@ final class AnimeCollection extends Collection {
/**
* Does this anime already exist in the collection?
*
* @param int|string $kitsuId
* @return bool
*/
public function has(int|string $kitsuId): bool
{
@ -411,8 +386,7 @@ final class AnimeCollection extends Collection {
/**
* Get genres for anime collection items
*
* @param array $filter
* @return array
* @return mixed[]
*/
public function getGenreList(array $filter = []): array
{
@ -479,8 +453,7 @@ final class AnimeCollection extends Collection {
/**
* Get media for anime collection items
*
* @param array $filter
* @return array
* @return mixed[]
*/
public function getMediaList(array $filter = []): array
{
@ -537,7 +510,7 @@ final class AnimeCollection extends Collection {
}
}
}
catch (PDOException $e) {}
catch (PDOException) {}
$this->db->resetQuery();
@ -576,7 +549,6 @@ final class AnimeCollection extends Collection {
* Update genre information for selected anime
*
* @param string $animeId The current anime
* @return void
*/
private function updateGenres(string $animeId): void
{
@ -626,8 +598,6 @@ final class AnimeCollection extends Collection {
/**
* Add genres to the database
*
* @param array $genres
*/
private function addNewGenres(array $genres): void
{
@ -661,7 +631,7 @@ final class AnimeCollection extends Collection {
/**
* Get list of existing genres
*
* @return array
* @return array<string, mixed[]>
*/
private function getGenreData(): array
{
@ -671,6 +641,9 @@ final class AnimeCollection extends Collection {
];
}
/**
* @return mixed[]
*/
private function getExistingGenres(): array
{
if ($this->db === NULL)
@ -701,6 +674,9 @@ final class AnimeCollection extends Collection {
return $genres;
}
/**
* @return mixed[]
*/
private function getExistingGenreLinkEntries(): array
{
if ($this->db === NULL)
@ -740,7 +716,7 @@ final class AnimeCollection extends Collection {
/**
* Get full collection from the database
*
* @return array
* @return mixed[]
*/
private function getCollectionFromDatabase(): array
{
@ -782,4 +758,5 @@ final class AnimeCollection extends Collection {
return $rows;
}
}
// End of AnimeCollectionModel.php

View File

@ -29,14 +29,11 @@ class Collection extends DB {
/**
* The query builder object
* @var QueryBuilderInterface|null
*/
protected ?QueryBuilderInterface $db;
/**
* Create a new collection object
*
* @param ContainerInterface $container
*/
public function __construct(ContainerInterface $container)
{
@ -69,4 +66,5 @@ class Collection extends DB {
}
}
}
// End of Collection.php

View File

@ -26,7 +26,6 @@ abstract class DB {
/**
* The database connection information array
* @var array $dbConfig
*/
protected array $dbConfig = [];
@ -41,4 +40,5 @@ abstract class DB {
$this->setContainer($container);
}
}
// End of DB.php

View File

@ -35,8 +35,7 @@ class Manga extends API {
/**
* Get a category out of the full list
*
* @param string $status
* @return array
* @return mixed[]
*/
public function getList(string $status): array
{
@ -60,7 +59,6 @@ class Manga extends API {
/**
* Get the details of a manga
*
* @param string $manga_id
* @return MangaPage
*/
public function getManga(string $manga_id): MangaPage
@ -81,7 +79,6 @@ class Manga extends API {
/**
* Get anime by its kitsu id
*
* @param string $animeId
* @return MangaPage
*/
public function getMangaById(string $animeId): MangaPage
@ -92,7 +89,7 @@ class Manga extends API {
/**
* Get recent reading history
*
* @return array
* @return mixed[]
*/
public function getHistory(): array
{
@ -102,8 +99,7 @@ class Manga extends API {
/**
* Map transformed anime data to be organized by reading status
*
* @param array $data
* @return array
* @return array<string, mixed[]>
*/
private function mapByStatus(array $data): array
{
@ -126,4 +122,5 @@ class Manga extends API {
return $output;
}
}
// End of MangaModel.php

View File

@ -34,29 +34,21 @@ trait MediaTrait {
/**
* Is the Anilist API enabled?
*
* @var boolean
*/
protected bool $anilistEnabled;
/**
* Model for making requests to Anilist API
*
* @var Anilist\Model
*/
protected Anilist\Model $anilistModel;
/**
* Model for making requests to Kitsu API
*
* @var Kitsu\Model
*/
protected Kitsu\Model $kitsuModel;
/**
* Anime constructor.
*
* @param ContainerInterface $container
*/
public function __construct(ContainerInterface $container)
{
@ -70,9 +62,7 @@ trait MediaTrait {
/**
* Search for anime by name
*
* @param string $name
* @param bool $inCollection
* @return array
* @return mixed[]
*/
public function search(string $name, bool $inCollection = false): array
{
@ -89,9 +79,6 @@ trait MediaTrait {
/**
* Get information about a specific list item
* for editing/updating that item
*
* @param string $itemId
* @return AnimeListItem|MangaListItem
*/
public function getLibraryItem(string $itemId): AnimeListItem|MangaListItem
{
@ -101,8 +88,6 @@ trait MediaTrait {
/**
* Add an anime to your list
*
* @param array $data
* @return bool
* @throws Throwable
*/
public function createLibraryItem(array $data): bool
@ -128,15 +113,14 @@ trait MediaTrait {
$results = $requester->makeRequests();
return count($results) > 0;
return $results !== [];
}
/**
* Increment progress for the specified anime
*
* @param FormItem $data
* @return array
* @throws Throwable
* @return array<string, mixed>
*/
public function incrementLibraryItem(FormItem $data): array
{
@ -167,9 +151,8 @@ trait MediaTrait {
/**
* Update a list entry
*
* @param FormItem $data
* @return array
* @throws Throwable
* @return array<string, mixed>
*/
public function updateLibraryItem(FormItem $data): array
{
@ -200,9 +183,7 @@ trait MediaTrait {
/**
* Delete a list entry
*
* @param string $id
* @param string|null $malId
* @return bool
* @throws Throwable
*/
public function deleteLibraryItem(string $id, string $malId = NULL): bool
@ -222,6 +203,6 @@ trait MediaTrait {
$results = $requester->makeRequests();
return count($results) > 0;
return $results !== [];
}
}

View File

@ -33,13 +33,13 @@ use Aviat\Ion\Di\ContainerAware;
final class Settings {
use ContainerAware;
private ConfigInterface $config;
public function __construct(ConfigInterface $config)
public function __construct(private ConfigInterface $config)
{
$this->config = $config;
}
/**
* @return array<string, mixed>
*/
public function getSettings(): array
{
$settings = [
@ -65,13 +65,16 @@ final class Settings {
return $settings;
}
/**
* @return array<mixed, array<string, array<string[]|array<string, mixed>[]|class-string<\memcached>[]|class-string<\redis>[]|bool|float|int|string|null>>>
*/
public function getSettingsForm(): array
{
$output = [];
foreach($this->getSettings() as $file => $values)
{
$values = $values ?? [];
$values ??= [];
foreach(SETTINGS_MAP[$file] as $key => $value)
{
@ -121,6 +124,9 @@ final class Settings {
return $output;
}
/**
* @return mixed[]
*/
public function validateSettings(array $settings): array
{
$cfg = Config::check($settings);

View File

@ -29,43 +29,31 @@ use Psr\Http\Message\ServerRequestInterface;
*/
class RoutingBase {
/**
* Injection Container
* @var ContainerInterface $container
*/
protected ContainerInterface $container;
/**
* Config Object
* @var ConfigInterface
*/
protected ConfigInterface $config;
/**
* Class wrapper for input superglobals
* @var ServerRequestInterface
*/
protected ServerRequestInterface $request;
/**
* Constructor
*
* @param ContainerInterface $container
* @throws ContainerException
* @throws NotFoundException
* @throws ConfigException
*/
public function __construct(ContainerInterface $container)
public function __construct(protected ContainerInterface $container)
{
$this->container = $container;
$this->config = $container->get('config');
$this->request = $container->get('request');
}
/**
* Get the current url path
*
* @return string
*/
public function path(): string
{
@ -81,8 +69,6 @@ class RoutingBase {
/**
* Get the url segments
*
* @return array
*/
public function segments(): array
{
@ -93,9 +79,7 @@ class RoutingBase {
/**
* Get a segment of the current url
*
* @param int $num
*
* @return string|null
*/
public function getSegment(int $num): ?string
{
@ -105,8 +89,6 @@ class RoutingBase {
/**
* Retrieve the last url segment
*
* @return string
*/
public function lastSegment(): string
{

View File

@ -19,12 +19,9 @@ namespace Aviat\AnimeClient\Types;
use ArrayAccess;
use Countable;
abstract class AbstractType implements ArrayAccess, Countable {
abstract class AbstractType implements ArrayAccess, Countable, \Stringable {
/**
* Populate values for un-serializing data
*
* @param mixed $properties
* @return self
*/
public static function __set_state(mixed $properties): self
{
@ -33,9 +30,6 @@ abstract class AbstractType implements ArrayAccess, Countable {
/**
* Check the shape of the object, and return the array equivalent
*
* @param array $data
* @return array|null
*/
final public static function check(array $data = []): ?array
{
@ -51,9 +45,6 @@ abstract class AbstractType implements ArrayAccess, Countable {
/**
* Static constructor
*
* @param mixed $data
* @return static
*/
final public static function from(mixed $data): static
{
@ -62,8 +53,6 @@ abstract class AbstractType implements ArrayAccess, Countable {
/**
* Sets the properties by using the constructor
*
* @param mixed $data
*/
final private function __construct(mixed $data = [])
{
@ -86,9 +75,6 @@ abstract class AbstractType implements ArrayAccess, Countable {
/**
* See if a property is set
*
* @param string $name
* @return bool
*/
final public function __isset(string $name): bool
{
@ -97,10 +83,6 @@ abstract class AbstractType implements ArrayAccess, Countable {
/**
* Set a property on the type object
*
* @param string $name
* @param mixed $value
* @return void
*/
final public function __set(string $name, mixed $value): void
{
@ -114,9 +96,9 @@ abstract class AbstractType implements ArrayAccess, Countable {
if ( ! property_exists($this, $name))
{
$existing = json_encode($this);
$existing = json_encode($this, JSON_THROW_ON_ERROR);
throw new UndefinedPropertyException("Trying to set undefined property: '$name'. Existing properties: $existing");
throw new UndefinedPropertyException("Trying to set undefined property: '{$name}'. Existing properties: {$existing}");
}
$this->$name = $value;
@ -124,9 +106,6 @@ abstract class AbstractType implements ArrayAccess, Countable {
/**
* Get a property from the type object
*
* @param string $name
* @return mixed
*/
final public function __get(string $name): mixed
{
@ -137,8 +116,6 @@ abstract class AbstractType implements ArrayAccess, Countable {
/**
* Create a string representation of the object for debugging
*
* @return string
*/
public function __toString(): string
{
@ -147,9 +124,6 @@ abstract class AbstractType implements ArrayAccess, Countable {
/**
* Implementing ArrayAccess
*
* @param mixed $offset
* @return bool
*/
final public function offsetExists(mixed $offset): bool
{
@ -158,9 +132,6 @@ abstract class AbstractType implements ArrayAccess, Countable {
/**
* Implementing ArrayAccess
*
* @param mixed $offset
* @return mixed
*/
final public function offsetGet(mixed $offset): mixed
{
@ -169,9 +140,6 @@ abstract class AbstractType implements ArrayAccess, Countable {
/**
* Implementing ArrayAccess
*
* @param mixed $offset
* @param mixed $value
*/
final public function offsetSet(mixed $offset, mixed $value): void
{
@ -180,8 +148,6 @@ abstract class AbstractType implements ArrayAccess, Countable {
/**
* Implementing ArrayAccess
*
* @param mixed $offset
*/
final public function offsetUnset(mixed $offset): void
{
@ -194,8 +160,6 @@ abstract class AbstractType implements ArrayAccess, Countable {
/**
* Implementing Countable
*
* @return int
*/
final public function count(): int
{
@ -209,7 +173,6 @@ abstract class AbstractType implements ArrayAccess, Countable {
* Returns early on primitive values to work recursively.
*
* @param mixed $parent
* @return array
*/
final public function toArray(mixed $parent = null): array
{
@ -219,8 +182,6 @@ abstract class AbstractType implements ArrayAccess, Countable {
/**
* Determine whether the type has any properties set
*
* @return bool
*/
final public function isEmpty(): bool
{

View File

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

View File

@ -20,9 +20,9 @@ namespace Aviat\AnimeClient\Types;
* Type representing an anime watch list item
*/
final class AnimeListItem extends AbstractType {
public ?string $id;
public ?string $id = null;
public ?string $mal_id;
public ?string $mal_id = null;
public array $episodes = [
'length' => 0,
@ -36,9 +36,9 @@ final class AnimeListItem extends AbstractType {
'ended' => '',
];
public ?Anime $anime;
public ?Anime $anime = null;
public ?string $notes;
public ?string $notes = null;
public bool $private = FALSE;

View File

@ -22,15 +22,15 @@ namespace Aviat\AnimeClient\Types;
final class Character extends AbstractType {
public array $castings = [];
public ?string $description;
public ?string $description = null;
public string $id;
public ?Media $media;
public ?Media $media = null;
public string $image;
public ?string $name;
public ?string $name = null;
public array $names = [];

View File

@ -45,29 +45,27 @@ class Config extends AbstractType {
* Default Anime list status page, values are listed in
* Aviat\AnimeClient\API\Enum\AnimeWatchingStatus\Title
*/
public ?string $default_anime_list_path;
public ?string $default_anime_list_path = null;
/**
* The list to redirect to from the root url
* 'anime' or 'manga'
*
* @var string|null
*/
public ?string $default_list;
public ?string $default_list = null;
/**
* Default Manga list status page, values are listed in
* Aviat\AnimeClient\API\Enum\MangaReadingStatus\Title
*/
public ?string $default_manga_list_path;
public ?string $default_manga_list_path = null;
/**
* Default list view type
* 'cover_view' or 'list_view'
*/
public ?string $default_view_type;
public ?string $default_view_type = null;
public ?string $kitsu_username;
public ?string $kitsu_username = null;
public bool $secure_urls = TRUE;

View File

@ -21,15 +21,15 @@ use Aviat\AnimeClient\Types\AbstractType;
class Anilist extends AbstractType {
public bool|string $enabled = FALSE;
public ?string $client_id;
public ?string $client_id = null;
public ?string $client_secret;
public ?string $client_secret = null;
public ?string $access_token;
public ?string $access_token = null;
public int|string|null $access_token_expires;
public ?string $refresh_token;
public ?string $refresh_token = null;
public ?string $username;
public ?string $username = null;
}

View File

@ -21,13 +21,13 @@ use Aviat\AnimeClient\Types\AbstractType;
class Cache extends AbstractType {
public string $driver = 'null';
public ?string $host;
public ?string $host = null;
public string|int|null $port;
public ?string $database;
public ?string $database = null;
public array $connection = [];
public ?array $options;
public ?array $options = null;
}

View File

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

View File

@ -24,7 +24,7 @@ class FormItem extends AbstractType {
public string|int|null $mal_id;
public ?FormItemData $data;
public ?FormItemData $data = null;
public function setData(mixed $value): void
{

View File

@ -20,13 +20,13 @@ namespace Aviat\AnimeClient\Types;
* Type representing a Media object for editing/syncing
*/
class FormItemData extends AbstractType {
public ?string $notes;
public ?string $notes = null;
public ?bool $private = FALSE;
public ?int $progress = NULL;
public ?int $rating;
public ?int $rating = null;
public ?int $ratingTwenty = NULL;
@ -39,5 +39,5 @@ class FormItemData extends AbstractType {
/**
* W3C Format Date string
*/
public ?string $updatedAt;
public ?string $updatedAt = null;
}

View File

@ -23,7 +23,7 @@ final class MangaListItem extends AbstractType {
public string $id;
public ?string $mal_id;
public ?string $mal_id = null;
public array $chapters = [
'read' => 0,
@ -39,11 +39,11 @@ final class MangaListItem extends AbstractType {
public string $reading_status;
public ?string $notes;
public ?string $notes = null;
public bool $rereading = false;
public ?int $reread;
public ?int $reread = null;
public string|int|null $user_rating;
}

View File

@ -32,7 +32,7 @@ final class MangaListItemDetail extends AbstractType {
public array $titles;
public ?string $type;
public ?string $type = null;
public string $url;
}

View File

@ -22,15 +22,15 @@ use Aviat\AnimeClient\API\Kitsu\Enum\MangaPublishingStatus;
* Type representing an Anime object for display
*/
final class MangaPage extends AbstractType {
public ?string $age_rating;
public ?string $age_rating = null;
public ?string $age_rating_guide;
public ?string $age_rating_guide = null;
public array $characters;
public ?int $chapter_count;
public ?int $chapter_count = null;
public ?string $cover_image;
public ?string $cover_image = null;
public array $genres;
@ -57,5 +57,5 @@ final class MangaPage extends AbstractType {
public string $url;
public ?int $volume_count;
public ?int $volume_count = null;
}

View File

@ -23,13 +23,13 @@ final class Person extends AbstractType {
public string $id;
public ?string $name;
public ?string $name = null;
public string $image;
public array $names = [];
public ?string $description;
public ?string $description = null;
public array $characters = [];

View File

@ -20,21 +20,21 @@ namespace Aviat\AnimeClient\Types;
* Type representing a Kitsu user for display
*/
final class User extends AbstractType {
public ?string $about;
public ?string $about = null;
public ?string $avatar;
public ?string $avatar = null;
public ?array $favorites;
public ?array $favorites = null;
public ?string $location;
public ?string $location = null;
public ?string $name;
public ?string $name = null;
public ?string $slug;
public ?string $slug = null;
public ?array $stats;
public ?array $stats = null;
public ?array $waifu;
public ?array $waifu = null;
public ?string $website;
public ?string $website = null;
}

View File

@ -28,14 +28,12 @@ class UrlGenerator extends RoutingBase {
/**
* The current HTTP host
* @var string
*/
protected string $host;
/**
* Constructor
*
* @param ContainerInterface $container
* @throws ContainerException
* @throws NotFoundException
*/
@ -48,9 +46,6 @@ class UrlGenerator extends RoutingBase {
/**
* Get the base url for css/js/images
*
* @param string ...$args
* @return string
*/
public function assetUrl(string ...$args): string
{
@ -64,9 +59,6 @@ class UrlGenerator extends RoutingBase {
/**
* Generate a proper url from the path
*
* @param string $path
* @return string
*/
public function url(string $path): string
{
@ -89,6 +81,7 @@ class UrlGenerator extends RoutingBase {
$pathSegments[$i] = preg_replace('`{.*?}`', $segments[$i + 1], $pathSegments[$i] ?? '');
}
$path = implode('/', $pathSegments);
$scheme = $this->config->get('secure_urls') !== FALSE ? 'https:' : 'http:';
@ -99,9 +92,7 @@ class UrlGenerator extends RoutingBase {
/**
* Full default path for the list pages
*
* @param string $type
* @throws InvalidArgumentException
* @return string
*/
public function defaultUrl(string $type): string
{
@ -118,4 +109,5 @@ class UrlGenerator extends RoutingBase {
throw new InvalidArgumentException("Invalid default type: '{$type}'");
}
}
// End of UrlGenerator.php

View File

@ -28,7 +28,6 @@ class Util {
/**
* Routes that don't require a second navigation level
* @var array
*/
private static array $formPages = [
'edit',
@ -54,10 +53,6 @@ class Util {
/**
* Absolutely equal?
*
* @param mixed $left
* @param mixed $right
* @return bool
*/
public static function eq(mixed $left, mixed $right): bool
{
@ -66,9 +61,6 @@ class Util {
/**
* Set aria-current attribute based on a condition check
*
* @param bool $condition
* @return string
*/
public static function ariaCurrent(bool $condition): string
{
@ -80,7 +72,6 @@ class Util {
*
* @param string $left - First item to compare
* @param string $right - Second item to compare
* @return string
*/
public static function isSelected(string $left, string $right): string
{
@ -92,7 +83,6 @@ class Util {
*
* @param string $left - First item to compare
* @param string $right - Second item to compare
* @return string
*/
public static function isNotSelected(string $left, string $right): string
{
@ -104,7 +94,6 @@ class Util {
*
* @throws ContainerException
* @throws NotFoundException
* @return bool
*/
public function isViewPage(): bool
{
@ -122,7 +111,6 @@ class Util {
*
* @throws ContainerException
* @throws NotFoundException
* @return bool
*/
public function isFormPage(): bool
{

View File

@ -27,15 +27,11 @@ class Config implements ConfigInterface {
/**
* Config object
*
* @var ArrayType
*/
protected ArrayType $map;
/**
* Constructor
*
* @param array $configArray
*/
public function __construct(array $configArray = [])
{
@ -44,9 +40,6 @@ class Config implements ConfigInterface {
/**
* Does the config item exist?
*
* @param array|int|string $key
* @return bool
*/
public function has(array|int|string $key): bool
{
@ -57,7 +50,6 @@ class Config implements ConfigInterface {
* Get a config value
*
* @param array|string|null $key
* @return mixed
* @throws ConfigException
*/
public function get(array|string $key = NULL): mixed
@ -72,9 +64,6 @@ class Config implements ConfigInterface {
/**
* Remove a config value
*
* @param array|string $key
* @return void
*/
public function delete(array|string $key): void
{
@ -92,9 +81,6 @@ class Config implements ConfigInterface {
/**
* Set a config value
*
* @param array|integer|string $key
* @param mixed $value
* @return ConfigInterface
*@throws InvalidArgumentException
*/
public function set(array|int|string $key, mixed $value): ConfigInterface
@ -115,4 +101,5 @@ class Config implements ConfigInterface {
return $this;
}
}
// End of config.php

View File

@ -22,9 +22,6 @@ namespace Aviat\Ion;
interface ConfigInterface {
/**
* Does the config item exist?
*
* @param array|int|string $key
* @return bool
*/
public function has(array|int|string $key): bool;
@ -32,25 +29,18 @@ interface ConfigInterface {
* Get a config value
*
* @param array|string|null $key
* @return mixed
*/
public function get(array|string $key = NULL): mixed;
/**
* Set a config value
*
* @param array|integer|string $key
* @param mixed $value
* @return ConfigInterface
* @throws \InvalidArgumentException
*/
public function set(array|int|string $key, mixed $value): self;
/**
* Remove a config value
*
* @param array|string $key
* @return void
*/
public function delete(array|string $key): void;
}

View File

@ -92,7 +92,6 @@ class Container implements ContainerInterface {
* @param array|null $args - Optional arguments for the factory callable
* @throws NotFoundException - No entry was found for this identifier.
* @throws ContainerException - Error while retrieving the entry.
* @return mixed
*/
public function getNew(string $id, ?array $args = NULL): mixed
{
@ -113,9 +112,7 @@ class Container implements ContainerInterface {
/**
* Add a factory to the container
*
* @param string $id
* @param Callable $value - a factory callable for the item
* @return ContainerInterface
*/
public function set(string $id, Callable $value): ContainerInterface
{
@ -126,10 +123,7 @@ class Container implements ContainerInterface {
/**
* Set a specific instance in the container for an existing factory
*
* @param string $id
* @param mixed $value
* @throws NotFoundException - No entry was found for this identifier.
* @return ContainerInterface
*/
public function setInstance(string $id, mixed $value): ContainerInterface
{
@ -147,7 +141,6 @@ class Container implements ContainerInterface {
* Returns false otherwise.
*
* @param string $id Identifier of the entry to look for.
* @return boolean
*/
public function has(string $id): bool
{
@ -158,7 +151,6 @@ class Container implements ContainerInterface {
* Determine whether a logger channel is registered
*
* @param string $id The logger channel
* @return boolean
*/
public function hasLogger(string $id = 'default'): bool
{
@ -168,9 +160,7 @@ class Container implements ContainerInterface {
/**
* Add a logger to the Container
*
* @param LoggerInterface $logger
* @param string $id The logger 'channel'
* @return ContainerInterface
*/
public function setLogger(LoggerInterface $logger, string $id = 'default'): ContainerInterface
{
@ -182,7 +172,6 @@ class Container implements ContainerInterface {
* Retrieve a logger for the selected channel
*
* @param string $id The logger to retrieve
* @return LoggerInterface|null
*/
public function getLogger(string $id = 'default'): ?LoggerInterface
{
@ -195,9 +184,6 @@ class Container implements ContainerInterface {
* Check if object implements ContainerAwareInterface
* or uses ContainerAware trait, and if so, apply the container
* to that object
*
* @param mixed $obj
* @return mixed
*/
private function applyContainer(mixed $obj): mixed
{
@ -220,4 +206,5 @@ class Container implements ContainerInterface {
return $obj;
}
}
// End of Container.php

View File

@ -23,16 +23,11 @@ trait ContainerAware {
/**
* Di Container
*
* @var ContainerInterface
*/
protected ContainerInterface $container;
/**
* Set the container for the current object
*
* @param ContainerInterface $container
* @return self
*/
public function setContainer(ContainerInterface $container): self
{
@ -42,12 +37,11 @@ trait ContainerAware {
/**
* Get the container object
*
* @return ContainerInterface
*/
public function getContainer(): ContainerInterface
{
return $this->container;
}
}
// End of ContainerAware.php

View File

@ -24,17 +24,15 @@ interface ContainerAwareInterface {
/**
* Set the container for the current object
*
* @param ContainerInterface $container
* @return void
*/
public function setContainer(ContainerInterface $container);
/**
* Get the container object
*
* @return ContainerInterface
*/
public function getContainer(): ContainerInterface;
}
// End of ContainerAwareInterface.php

View File

@ -43,33 +43,23 @@ interface ContainerInterface {
* Returns false otherwise.
*
* @param string $id Identifier of the entry to look for.
* @return boolean
*/
public function has(string $id): bool;
/**
* Add a factory to the container
*
* @param string $id
* @param Callable $value - a factory callable for the item
* @return ContainerInterface
*/
public function set(string $id, Callable $value): ContainerInterface;
/**
* Set a specific instance in the container for an existing factory
*
* @param string $id
* @param mixed $value
* @return ContainerInterface
*/
public function setInstance(string $id, mixed $value): ContainerInterface;
/**
* Get a new instance of the specified item
*
* @param string $id
* @return mixed
*/
public function getNew(string $id): mixed;
@ -77,16 +67,13 @@ interface ContainerInterface {
* Determine whether a logger channel is registered
*
* @param string $id The logger channel
* @return boolean
*/
public function hasLogger(string $id = 'default'): bool;
/**
* Add a logger to the Container
*
* @param LoggerInterface $logger
* @param string $id The logger 'channel'
* @return ContainerInterface
*/
public function setLogger(LoggerInterface $logger, string $id = 'default'): ContainerInterface;
@ -94,7 +81,6 @@ interface ContainerInterface {
* Retrieve a logger for the selected channel
*
* @param string $id The logger to retrieve
* @return LoggerInterface|null
*/
public function getLogger(string $id = 'default'): ?LoggerInterface;
}

View File

@ -25,4 +25,5 @@ use Psr\Container\ContainerExceptionInterface;
class ContainerException extends Exception implements ContainerExceptionInterface {
}
// End of ContainerException.php

View File

@ -25,4 +25,5 @@ use Psr\Container\NotFoundExceptionInterface;
class NotFoundException extends ContainerException implements NotFoundExceptionInterface {
}
// End of NotFoundException.php

View File

@ -27,7 +27,6 @@ abstract class Enum {
/**
* Return the list of constant values for the Enum
*
* @return array
* @throws ReflectionException
*/
public static function getConstList(): array
@ -47,8 +46,6 @@ abstract class Enum {
/**
* Verify that a constant value is valid
*
* @param mixed $key
* @return boolean
* @throws ReflectionException
*/
public static function isValid(mixed $key): bool
@ -57,4 +54,5 @@ abstract class Enum {
return in_array($key, $values, TRUE);
}
}
// End of Enum.php

View File

@ -24,9 +24,6 @@ class Event {
/**
* Subscribe to an event
*
* @param string $eventName
* @param callable $handler
*/
public static function on(string $eventName, callable $handler): void
{
@ -40,9 +37,6 @@ class Event {
/**
* Fire off an event
*
* @param string $eventName
* @param array $args
*/
public static function emit(string $eventName, array $args = []): void
{

View File

@ -27,8 +27,6 @@ class DoubleRenderException extends LogicException {
/**
* DoubleRenderException constructor.
*
* @param string $message
* @param int $code
* @param Exception|null $previous
*/
public function __construct(string $message = 'A view can only be rendered once, because headers can only be sent once.', int $code = 0, Exception $previous = NULL)

View File

@ -29,20 +29,17 @@ class Friend {
/**
* Object to create a friend of
* @var mixed
*/
private mixed $_friend_;
/**
* Reflection class of the object
* @var ReflectionClass
*/
private ReflectionClass $_reflect_;
/**
* Create a friend object
*
* @param mixed $obj
* @throws InvalidArgumentException
* @throws \ReflectionException
*/
@ -59,9 +56,6 @@ class Friend {
/**
* Retrieve a friend's property
*
* @param string $key
* @return mixed
*/
public function __get(string $key): mixed
{
@ -80,9 +74,6 @@ class Friend {
/**
* See if a property exists on the friend
*
* @param string $name
* @return bool
*/
public function __isset(string $name): bool
{
@ -92,8 +83,6 @@ class Friend {
/**
* Set a friend's property
*
* @param string $key
* @param mixed $value
* @return void
*/
public function __set(string $key, mixed $value)
@ -112,8 +101,6 @@ class Friend {
/**
* Calls a protected or private method on the friend
*
* @param string $method
* @param array $args
* @return mixed
* @throws BadMethodCallException
* @throws \ReflectionException
@ -132,9 +119,6 @@ class Friend {
/**
* Iterates over parent classes to get a ReflectionProperty
*
* @param string $name
* @return ReflectionProperty|null
*/
private function _get_property(string $name): ?ReflectionProperty
{
@ -147,11 +131,13 @@ class Friend {
// Return NULL on any exception, so no further logic needed
// in the catch block
// @codeCoverageIgnoreStart
catch (\Exception $e)
catch (\Exception)
{
return NULL;
}
// @codeCoverageIgnoreEnd
}
}
// End of Friend.php

View File

@ -24,9 +24,7 @@ interface HttpViewInterface extends ViewInterface {
/**
* Set the status code of the request
*
* @param int $code
* @throws \InvalidArgumentException
* @return self
*/
public function setStatusCode(int $code): self;
}

View File

@ -26,11 +26,7 @@ class Json {
/**
* Encode data in json format
*
* @param mixed $data
* @param int $options
* @param int $depth
* @throws JsonException
* @return string
*/
public static function encode(mixed $data, int $options = 0, int $depth = 512): string
{
@ -43,12 +39,9 @@ class Json {
/**
* Encode data in json format and save to a file
*
* @param string $filename
* @param mixed $data
* @param int $jsonOptions - Options to pass to json_encode
* @param int $fileOptions - Options to pass to file_get_contents
* @throws JsonException
* @return bool
*/
public static function encodeFile(string $filename, mixed $data, int $jsonOptions = 0, int $fileOptions = 0): bool
{
@ -61,12 +54,7 @@ class Json {
/**
* Decode data from json
*
* @param string|null $json
* @param bool $assoc
* @param int $depth
* @param int $options
* @throws JsonException
* @return mixed
*/
public static function decode(?string $json, bool $assoc = TRUE, int $depth = 512, int $options = 0): mixed
{
@ -85,12 +73,7 @@ class Json {
/**
* Decode json data loaded from the passed filename
*
* @param string $filename
* @param bool $assoc
* @param int $depth
* @param int $options
* @throws JsonException
* @return mixed
*/
public static function decodeFile(string $filename, bool $assoc = TRUE, int $depth = 512, int $options = 0): mixed
{
@ -103,9 +86,7 @@ class Json {
/**
* Determines whether a string is valid json
*
* @param string $string
* @throws \InvalidArgumentException
* @return boolean
*/
public static function isJson(string $string): bool
{
@ -116,7 +97,6 @@ class Json {
* Call the json error functions to check for errors encoding/decoding
*
* @throws JsonException
* @return void
*/
protected static function check_json_error(): void
{
@ -141,4 +121,5 @@ class Json {
}
}
}
// End of JSON.php

View File

@ -24,4 +24,5 @@ use InvalidArgumentException;
class JsonException extends InvalidArgumentException {
}
// End of JsonException.php

View File

@ -21,4 +21,5 @@ namespace Aviat\Ion;
*/
class Model {
}
// End of Model.php

View File

@ -24,17 +24,11 @@ use BadMethodCallException;
abstract class AbstractTransformer implements TransformerInterface {
/**
* Mutate the data structure
*
* @param array|object $item
* @return mixed
*/
abstract public function transform(array|object $item): mixed;
/**
* Transform a set of structures
*
* @param iterable $collection
* @return array
*/
public function transformCollection(iterable $collection): array
{
@ -48,7 +42,6 @@ abstract class AbstractTransformer implements TransformerInterface {
* Requires an 'untransform' method in the extending class
*
* @param iterable $collection
* @return array
*/
public function untransformCollection(iterable $collection): array
{
@ -61,4 +54,5 @@ abstract class AbstractTransformer implements TransformerInterface {
return array_map([$this, 'untransform'], $list);
}
}
// End of AbstractTransformer.php

View File

@ -23,9 +23,6 @@ interface TransformerInterface {
/**
* Mutate the data structure
*
* @param array|object $item
* @return mixed
*/
public function transform(array|object $item): mixed;
}

View File

@ -29,15 +29,11 @@ class ArrayType {
/**
* The current array
*
* @var array
*/
protected array $arr;
protected array $arr = [];
/**
* Map generated methods to their native implementations
*
* @var array
*/
protected array $nativeMethods = [
'chunk' => 'array_chunk',
@ -61,8 +57,6 @@ class ArrayType {
/**
* Native methods that modify the passed in array
*
* @var array
*/
protected array $nativeInPlaceMethods = [
'shuffle' => 'shuffle',
@ -74,9 +68,6 @@ class ArrayType {
/**
* Create an ArrayType wrapper class from an array
*
* @param array $arr
* @return ArrayType
*/
public static function from(array $arr): ArrayType
{
@ -85,8 +76,6 @@ class ArrayType {
/**
* Create an ArrayType wrapper class
*
* @param array $arr
*/
private function __construct(array &$arr)
{
@ -96,9 +85,6 @@ class ArrayType {
/**
* Call one of the dynamically created methods
*
* @param string $method
* @param array $args
* @return mixed
* @throws InvalidArgumentException
*/
public function __call(string $method, array $args): mixed
@ -124,9 +110,6 @@ class ArrayType {
/**
* Does the passed key exist in the current array?
*
* @param int|string|array $key
* @return bool
*/
public function hasKey(int|string|array $key): bool
{
@ -153,10 +136,7 @@ class ArrayType {
/**
* Fill an array with the specified value
*
* @param int $start_index
* @param int $num
* @param mixed $value
* @return array
* @return mixed[]
*/
public function fill(int $start_index, int $num, mixed $value): array
{
@ -166,8 +146,7 @@ class ArrayType {
/**
* Call a callback on each item of the array
*
* @param callable $callback
* @return array
* @return mixed[]
*/
public function map(callable $callback): array
{
@ -176,10 +155,6 @@ class ArrayType {
/**
* Find an array key by its associated value
*
* @param mixed $value
* @param bool $strict
* @return false|integer|string|null
*/
public function search(mixed $value, bool $strict = TRUE): int|string|false|null
{
@ -188,10 +163,6 @@ class ArrayType {
/**
* Determine if the array has the passed value
*
* @param mixed $value
* @param bool $strict
* @return bool
*/
public function has(mixed $value, bool $strict = TRUE): bool
{
@ -200,9 +171,6 @@ class ArrayType {
/**
* Return the array, or a key
*
* @param string|integer|null $key
* @return mixed
*/
public function &get(string|int|null $key = NULL): mixed
{
@ -224,10 +192,6 @@ class ArrayType {
/**
* Set a key on the array
*
* @param mixed $key
* @param mixed $value
* @return ArrayType
*/
public function set(mixed $key, mixed $value): ArrayType
{
@ -242,7 +206,6 @@ class ArrayType {
* $val = $arr->getDeepKey([0, 'data', 'foo']);
* // returns 'bar'
* @param array $key An array of keys of the array
* @return mixed
*/
public function &getDeepKey(array $key): mixed
{
@ -259,6 +222,7 @@ class ArrayType {
$pos = NULL;
return $pos;
}
$pos =& $pos[$level];
}
@ -269,9 +233,7 @@ class ArrayType {
* Sets the value of an arbitrarily deep key in the array
* and returns the modified array
*
* @param array $key
* @param mixed $value
* @return array
* @return mixed[]
*/
public function setDeepKey(array $key, mixed $value): array
{
@ -286,6 +248,7 @@ class ArrayType {
$pos = [];
$pos[$level] = [];
}
$pos =& $pos[$level];
}
@ -294,4 +257,5 @@ class ArrayType {
return $this->arr;
}
}
// End of ArrayType.php

View File

@ -25,9 +25,6 @@ class StringType extends Stringy {
/**
* Alias for `create` static constructor
*
* @param string $str
* @return self
*/
public static function from(string $str): self
{
@ -38,9 +35,7 @@ class StringType extends Stringy {
* See if two strings match, despite being delimited differently,
* such as camelCase, PascalCase, kebab-case, or snake_case.
*
* @param string $strToMatch
* @throws \InvalidArgumentException
* @return boolean
*/
public function fuzzyCaseMatch(string $strToMatch): bool
{
@ -50,4 +45,5 @@ class StringType extends Stringy {
return $firstStr === $secondStr;
}
}
// End of StringType.php

View File

@ -29,15 +29,11 @@ class HtmlView extends HttpView {
/**
* Response mime type
*
* @var string
*/
protected string $contentType = 'text/html';
/**
* Create the Html View
*
* @param ContainerInterface $container
*/
public function __construct(ContainerInterface $container)
{
@ -50,9 +46,6 @@ class HtmlView extends HttpView {
/**
* Render a basic html Template
*
* @param string $path
* @param array $data
* @return string
* @throws \Throwable
*/
public function renderTemplate(string $path, array $data): string
@ -74,4 +67,5 @@ class HtmlView extends HttpView {
return preg_replace('/>\s+</', '> <', $buffer) ?? $buffer;
}
}
// End of HtmlView.php

View File

@ -74,7 +74,6 @@ class HttpView implements HttpViewInterface{
* and any attempts to call again will result in a DoubleRenderException
*
* @throws DoubleRenderException
* @return string
*/
public function __toString(): string
{
@ -82,6 +81,7 @@ class HttpView implements HttpViewInterface{
{
throw new DoubleRenderException();
}
$this->hasRendered = TRUE;
return $this->getOutput();
}
@ -89,9 +89,7 @@ class HttpView implements HttpViewInterface{
/**
* Add an http header
*
* @param string $name
* @param string|string[] $value
* @return HttpView
*/
public function addHeader(string $name, array|string $value): self
{
@ -101,9 +99,6 @@ class HttpView implements HttpViewInterface{
/**
* Set the output string
*
* @param mixed $string
* @return HttpViewInterface
*/
public function setOutput(mixed $string): HttpViewInterface
{
@ -115,9 +110,6 @@ class HttpView implements HttpViewInterface{
/**
* Append additional output.
*
* @param string $string
* @return HttpViewInterface
*/
public function appendOutput(string $string): HttpViewInterface
{
@ -127,8 +119,6 @@ class HttpView implements HttpViewInterface{
/**
* Get the current output as a string. Does not
* render view or send headers.
*
* @return string
*/
public function getOutput(): string
{
@ -138,11 +128,7 @@ class HttpView implements HttpViewInterface{
/**
* Do a redirect
*
* @param string $url
* @param int $code
* @param array $headers
* @throws \InvalidArgumentException
* @return self
*/
public function redirect(string $url, int $code = 302, array $headers = []): self
{
@ -153,9 +139,7 @@ class HttpView implements HttpViewInterface{
/**
* Set the status code of the request
*
* @param int $code
* @throws \InvalidArgumentException
* @return HttpView
*/
public function setStatusCode(int $code): self
{
@ -170,7 +154,6 @@ class HttpView implements HttpViewInterface{
*
* @throws DoubleRenderException
* @throws \InvalidArgumentException
* @return void
*/
public function send(): void
{
@ -183,7 +166,6 @@ class HttpView implements HttpViewInterface{
* @codeCoverageIgnore
* @throws DoubleRenderException
* @throws \InvalidArgumentException
* @return void
*/
protected function output(): void
{

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