Fix a bunch more phpstan errors
Some checks failed
timw4mail/HummingBirdAnimeClient/pipeline/head There was a failure building this commit

This commit is contained in:
Timothy Warren 2021-02-12 13:09:57 -05:00
parent e7ec57eec5
commit be74cfaceb
19 changed files with 54 additions and 75 deletions

View File

@ -9,6 +9,7 @@ parameters:
- index.php - index.php
ignoreErrors: ignoreErrors:
- "#Offset 'fields' does not exist on array#" - "#Offset 'fields' does not exist on array#"
- '#Function imagepalletetotruecolor not found#'
- '#Call to an undefined method Aura\\\Html\\\HelperLocator::[a-zA-Z0-9_]+\(\)#' - '#Call to an undefined method Aura\\\Html\\\HelperLocator::[a-zA-Z0-9_]+\(\)#'
- '#Call to an undefined method Query\\QueryBuilderInterface::[a-zA-Z0-9_]+\(\)#' - '#Call to an undefined method Query\\QueryBuilderInterface::[a-zA-Z0-9_]+\(\)#'
excludes_analyse: excludes_analyse:

View File

@ -116,10 +116,9 @@ abstract class APIRequestBuilder {
* Set the request body * Set the request body
* *
* @param FormBody|string $body * @param FormBody|string $body
* @throws \TypeError
* @return self * @return self
*/ */
public function setBody($body): self public function setBody(FormBody|string $body): self
{ {
$this->request->setBody($body); $this->request->setBody($body);
return $this; return $this;
@ -129,7 +128,6 @@ abstract class APIRequestBuilder {
* Set body as form fields * Set body as form fields
* *
* @param array $fields Mapping of field names to values * @param array $fields Mapping of field names to values
* @throws \TypeError
* @return self * @return self
*/ */
public function setFormFields(array $fields): self public function setFormFields(array $fields): self

View File

@ -27,7 +27,7 @@ use DateTime;
class AnimeListTransformer extends AbstractTransformer { class AnimeListTransformer extends AbstractTransformer {
public function transform($item): AnimeListItem public function transform(array|object $item): AnimeListItem
{ {
return AnimeListItem::from([]); return AnimeListItem::from([]);
} }

View File

@ -28,7 +28,7 @@ use DateTime;
class MangaListTransformer extends AbstractTransformer { class MangaListTransformer extends AbstractTransformer {
public function transform($item) public function transform(array|object $item): MangaListItem
{ {
return MangaListItem::from([]); return MangaListItem::from([]);
} }

View File

@ -58,10 +58,9 @@ trait CacheTrait {
* @param string $key * @param string $key
* @param callable $primer * @param callable $primer
* @param array|null $primeArgs * @param array|null $primeArgs
* @return mixed|null * @return mixed
* @throws InvalidArgumentException
*/ */
public function getCached(string $key, callable $primer, ?array $primeArgs = []) public function getCached(string $key, callable $primer, ?array $primeArgs = []): mixed
{ {
$value = $this->cache->get($key, NULL); $value = $this->cache->get($key, NULL);

View File

@ -37,12 +37,11 @@ use Aviat\AnimeClient\Enum\MediaType;
use Aviat\AnimeClient\Kitsu as K; use Aviat\AnimeClient\Kitsu as K;
use Aviat\AnimeClient\Types\Anime; use Aviat\AnimeClient\Types\Anime;
use Aviat\AnimeClient\Types\MangaPage; use Aviat\AnimeClient\Types\MangaPage;
use Aviat\Banker\Exception\InvalidArgumentException;
use Aviat\Ion\{ use Aviat\Ion\{
Di\ContainerAware, Di\ContainerAware,
Json Json
}; };
use Throwable; use Generator;
use function Amp\Promise\wait; use function Amp\Promise\wait;
use function Aviat\AnimeClient\getApiClient; use function Aviat\AnimeClient\getApiClient;
@ -91,7 +90,6 @@ final class Model {
* @param string $username * @param string $username
* @param string $password * @param string $password
* @return bool|array * @return bool|array
* @throws Throwable
*/ */
public function authenticate(string $username, string $password) public function authenticate(string $username, string $password)
{ {
@ -134,7 +132,6 @@ final class Model {
* *
* @param string $token * @param string $token
* @return bool|array * @return bool|array
* @throws Throwable
*/ */
public function reAuthenticate(string $token) public function reAuthenticate(string $token)
{ {
@ -174,7 +171,6 @@ final class Model {
* *
* @param string|null $username * @param string|null $username
* @return string * @return string
* @throws \Psr\SimpleCache\InvalidArgumentException
*/ */
public function getUserIdByUsername(string $username = NULL): string public function getUserIdByUsername(string $username = NULL): string
{ {
@ -210,7 +206,6 @@ final class Model {
* *
* @param string $slug * @param string $slug
* @return array * @return array
* @throws InvalidArgumentException
*/ */
public function getPerson(string $slug): array public function getPerson(string $slug): array
{ {
@ -289,8 +284,6 @@ final class Model {
* Retrieve the data for the anime watch history page * Retrieve the data for the anime watch history page
* *
* @return array * @return array
* @throws InvalidArgumentException
* @throws Throwable
*/ */
public function getAnimeHistory(): array public function getAnimeHistory(): array
{ {
@ -315,7 +308,6 @@ final class Model {
* *
* @param string $status - The watching status to filter the list with * @param string $status - The watching status to filter the list with
* @return array * @return array
* @throws InvalidArgumentException
*/ */
public function getAnimeList(string $status): array public function getAnimeList(string $status): array
{ {
@ -354,7 +346,6 @@ final class Model {
* *
* @param string $status - Optional status to filter by * @param string $status - Optional status to filter by
* @return int * @return int
* @throws InvalidArgumentException
*/ */
public function getAnimeListCount(string $status = '') : int public function getAnimeListCount(string $status = '') : int
{ {
@ -365,8 +356,6 @@ final class Model {
* Get all the anime entries, that are organized for output to html * Get all the anime entries, that are organized for output to html
* *
* @return array * @return array
* @throws ReflectionException
* @throws InvalidArgumentException
*/ */
public function getFullOrganizedAnimeList(): array public function getFullOrganizedAnimeList(): array
{ {
@ -434,8 +423,6 @@ final class Model {
* Retrieve the data for the manga read history page * Retrieve the data for the manga read history page
* *
* @return array * @return array
* @throws InvalidArgumentException
* @throws Throwable
*/ */
public function getMangaHistory(): array public function getMangaHistory(): array
{ {
@ -458,7 +445,6 @@ final class Model {
* *
* @param string $status - The reading status by which to filter the list * @param string $status - The reading status by which to filter the list
* @return array * @return array
* @throws InvalidArgumentException
*/ */
public function getMangaList(string $status): array public function getMangaList(string $status): array
{ {
@ -497,7 +483,6 @@ final class Model {
* *
* @param string $status - Optional status to filter by * @param string $status - Optional status to filter by
* @return int * @return int
* @throws InvalidArgumentException
*/ */
public function getMangaListCount(string $status = '') : int public function getMangaListCount(string $status = '') : int
{ {
@ -508,8 +493,6 @@ final class Model {
* Get all Manga lists * Get all Manga lists
* *
* @return array * @return array
* @throws ReflectionException
* @throws InvalidArgumentException
*/ */
public function getFullOrganizedMangaList(): array public function getFullOrganizedMangaList(): array
{ {
@ -638,8 +621,6 @@ final class Model {
* *
* @param string $type * @param string $type
* @return array * @return array
* @throws InvalidArgumentException
* @throws Throwable
*/ */
public function getSyncList(string $type): array public function getSyncList(string $type): array
{ {
@ -831,7 +812,7 @@ final class Model {
}); });
} }
private function getPages(callable $method, ...$args): ?\Generator private function getPages(callable $method, mixed ...$args): ?Generator
{ {
$items = $method(...$args); $items = $method(...$args);

View File

@ -26,7 +26,6 @@ use Amp\Http\Client\Request;
use Amp\Http\Client\Response; use Amp\Http\Client\Response;
use Aviat\AnimeClient\Kitsu as K; use Aviat\AnimeClient\Kitsu as K;
use Aviat\AnimeClient\API\APIRequestBuilder; use Aviat\AnimeClient\API\APIRequestBuilder;
use Aviat\AnimeClient\API\FailedResponseException;
use Aviat\AnimeClient\Enum\EventType; use Aviat\AnimeClient\Enum\EventType;
use Aviat\Ion\Di\ContainerAware; use Aviat\Ion\Di\ContainerAware;
use Aviat\Ion\Di\ContainerInterface; use Aviat\Ion\Di\ContainerInterface;
@ -157,7 +156,6 @@ final class RequestBuilder extends APIRequestBuilder {
* @param string $name * @param string $name
* @param array $variables * @param array $variables
* @return array * @return array
* @throws Throwable
*/ */
public function mutate(string $name, array $variables = []): array public function mutate(string $name, array $variables = []): array
{ {
@ -181,7 +179,6 @@ final class RequestBuilder extends APIRequestBuilder {
* @param string $url * @param string $url
* @param array $options * @param array $options
* @return Response * @return Response
* @throws \Throwable
*/ */
public function getResponse(string $type, string $url, array $options = []): Response public function getResponse(string $type, string $url, array $options = []): Response
{ {
@ -210,7 +207,7 @@ final class RequestBuilder extends APIRequestBuilder {
public function queryRequest(string $name, array $variables = []): Request public function queryRequest(string $name, array $variables = []): Request
{ {
$file = realpath("{$this->filePath}/Queries/{$name}.graphql"); $file = realpath("{$this->filePath}/Queries/{$name}.graphql");
if ( ! file_exists($file)) if ($file === FALSE || ! file_exists($file))
{ {
throw new LogicException('GraphQL query file does not exist.'); throw new LogicException('GraphQL query file does not exist.');
} }
@ -240,12 +237,11 @@ final class RequestBuilder extends APIRequestBuilder {
* @param string $name * @param string $name
* @param array $variables * @param array $variables
* @return Request * @return Request
* @throws Throwable
*/ */
public function mutateRequest (string $name, array $variables = []): Request public function mutateRequest (string $name, array $variables = []): Request
{ {
$file = "{$this->filePath}/Mutations/{$name}.graphql"; $file = realpath("{$this->filePath}/Mutations/{$name}.graphql");
if ( ! file_exists($file)) if ($file === FALSE || ! file_exists($file))
{ {
throw new LogicException('GraphQL mutation file does not exist.'); throw new LogicException('GraphQL mutation file does not exist.');
} }
@ -274,9 +270,6 @@ final class RequestBuilder extends APIRequestBuilder {
* @param string $type * @param string $type
* @param string $url * @param string $url
* @param array $options * @param array $options
* @throws JsonException
* @throws FailedResponseException
* @throws Throwable
* @return array * @return array
*/ */
private function request(string $type, string $url, array $options = []): array private function request(string $type, string $url, array $options = []): array

View File

@ -33,11 +33,12 @@ final class AnimeListTransformer extends AbstractTransformer {
* Convert raw api response to a more * Convert raw api response to a more
* logical and workable structure * logical and workable structure
* *
* @param array $item API library item * @param array|object $item API library item
* @return AnimeListItem * @return AnimeListItem
*/ */
public function transform($item): AnimeListItem public function transform(array|object $item): AnimeListItem
{ {
$item = (array)$item;
$animeId = $item['media']['id']; $animeId = $item['media']['id'];
$anime = $item['media']; $anime = $item['media'];
@ -115,7 +116,7 @@ final class AnimeListTransformer extends AbstractTransformer {
* @param array $item Transformed library item * @param array $item Transformed library item
* @return FormItem API library item * @return FormItem API library item
*/ */
public function untransform($item): FormItem public function untransform(array $item): FormItem
{ {
$privacy = (array_key_exists('private', $item) && $item['private']); $privacy = (array_key_exists('private', $item) && $item['private']);
$rewatching = (array_key_exists('rewatching', $item) && $item['rewatching']); $rewatching = (array_key_exists('rewatching', $item) && $item['rewatching']);

View File

@ -29,11 +29,12 @@ final class AnimeTransformer extends AbstractTransformer {
* Convert raw api response to a more * Convert raw api response to a more
* logical and workable structure * logical and workable structure
* *
* @param array $item API library item * @param array|object $item API library item
* @return AnimePage * @return AnimePage
*/ */
public function transform($item): AnimePage public function transform(array|object $item): AnimePage
{ {
$item = (array)$item;
$base = $item['data']['findAnimeBySlug'] ?? $item['data']['findAnimeById'] ?? $item['data']['randomMedia']; $base = $item['data']['findAnimeBySlug'] ?? $item['data']['findAnimeById'] ?? $item['data']['randomMedia'];
$characters = []; $characters = [];
$links = []; $links = [];

View File

@ -28,12 +28,13 @@ use Locale;
final class CharacterTransformer extends AbstractTransformer { final class CharacterTransformer extends AbstractTransformer {
/** /**
* @param array $characterData * @param array|object $item
* @return Character * @return Character
*/ */
public function transform($characterData): Character public function transform(array|object $item): Character
{ {
$data = $characterData['data']['findCharacterBySlug'] ?? []; $item = (array)$item;
$data = $item['data']['findCharacterBySlug'] ?? [];
$castings = []; $castings = [];
$media = [ $media = [
'anime' => [], 'anime' => [],

View File

@ -65,7 +65,7 @@ abstract class HistoryTransformer {
foreach ($base as $entry) foreach ($base as $entry)
{ {
if ( ! (strtolower($entry['media']['__typename']) === $this->type)) if (strtolower($entry['media']['__typename']) !== $this->type)
{ {
continue; continue;
} }
@ -210,7 +210,7 @@ abstract class HistoryTransformer {
]); ]);
} }
protected function transformUpdated($entry): HistoryItem protected function transformUpdated(array $entry): HistoryItem
{ {
$id = $entry['media']['id']; $id = $entry['media']['id'];
$data = $entry['media']; $data = $entry['media'];
@ -242,7 +242,7 @@ abstract class HistoryTransformer {
]); ]);
} }
return $entry; return HistoryItem::from($entry);
} }
protected function linkTitle (array $data): string protected function linkTitle (array $data): string
@ -257,6 +257,11 @@ abstract class HistoryTransformer {
$date $date
); );
if ($dateTime === FALSE)
{
return new DateTimeImmutable();
}
return $dateTime->setTimezone(new DateTimeZone(date_default_timezone_get())); return $dateTime->setTimezone(new DateTimeZone(date_default_timezone_get()));
} }
@ -265,7 +270,7 @@ abstract class HistoryTransformer {
return "/{$this->type}/details/{$data['slug']}"; return "/{$this->type}/details/{$data['slug']}";
} }
protected function isReconsuming ($entry): bool protected function isReconsuming (array $entry): bool
{ {
return $entry['libraryEntry']['reconsuming']; return $entry['libraryEntry']['reconsuming'];
} }

View File

@ -26,7 +26,7 @@ use Aviat\Ion\Type\StringType;
*/ */
final class LibraryEntryTransformer extends AbstractTransformer final class LibraryEntryTransformer extends AbstractTransformer
{ {
public function transform($item) public function transform(array|object $item): AnimeListItem|MangaListItem
{ {
$item = (array)$item; $item = (array)$item;
$type = $item['media']['type'] ?? ''; $type = $item['media']['type'] ?? '';
@ -38,17 +38,12 @@ final class LibraryEntryTransformer extends AbstractTransformer
sort($genres); sort($genres);
} }
switch (strtolower($type)) return match (strtolower($type))
{ {
case 'anime': 'anime' => $this->animeTransform($item, $genres),
return $this->animeTransform($item, $genres); 'manga' => $this->mangaTransform($item, $genres),
default => AnimeListItem::from([]),
case 'manga': };
return $this->mangaTransform($item, $genres);
default:
return [];
}
} }
private function animeTransform(array $item, array $genres): AnimeListItem private function animeTransform(array $item, array $genres): AnimeListItem

View File

@ -31,11 +31,12 @@ final class MangaListTransformer extends AbstractTransformer {
/** /**
* Remap zipped anime data to a more logical form * Remap zipped anime data to a more logical form
* *
* @param array $item manga entry item * @param array|object $item manga entry item
* @return MangaListItem * @return MangaListItem
*/ */
public function transform($item): MangaListItem public function transform(array|object $item): MangaListItem
{ {
$item = (array)$item;
$mangaId = $item['media']['id']; $mangaId = $item['media']['id'];
$manga = $item['media']; $manga = $item['media'];

View File

@ -29,11 +29,12 @@ final class MangaTransformer extends AbstractTransformer {
* Convert raw api response to a more * Convert raw api response to a more
* logical and workable structure * logical and workable structure
* *
* @param array $item API library item * @param array|object $item API library item
* @return MangaPage * @return MangaPage
*/ */
public function transform($item): MangaPage public function transform(array|object $item): MangaPage
{ {
$item = (array)$item;
$base = $item['data']['findMangaBySlug'] ?? $item['data']['findMangaById'] ?? $item['data']['randomMedia']; $base = $item['data']['findMangaBySlug'] ?? $item['data']['findMangaById'] ?? $item['data']['randomMedia'];
$characters = []; $characters = [];
$links = []; $links = [];

View File

@ -26,12 +26,13 @@ use Aviat\Ion\Transformer\AbstractTransformer;
final class PersonTransformer extends AbstractTransformer { final class PersonTransformer extends AbstractTransformer {
/** /**
* @param array|object $personData * @param array|object $item
* @return Person * @return Person
*/ */
public function transform($personData): Person public function transform(array|object $item): Person
{ {
$data = $personData['data']['findPersonBySlug'] ?? []; $item = (array)$item;
$data = $item['data']['findPersonBySlug'] ?? [];
$canonicalName = $data['names']['localized'][$data['names']['canonical']] $canonicalName = $data['names']['localized'][$data['names']['canonical']]
?? array_shift($data['names']['localized']); ?? array_shift($data['names']['localized']);

View File

@ -29,9 +29,10 @@ use Aviat\Ion\Transformer\AbstractTransformer;
* @return User * @return User
*/ */
final class UserTransformer extends AbstractTransformer { final class UserTransformer extends AbstractTransformer {
public function transform($profileData): User public function transform(array|object $item): User
{ {
$base = $profileData['data']['findProfileBySlug'] ?? []; $item = (array)$item;
$base = $item['data']['findProfileBySlug'] ?? [];
$favorites = $base['favorites']['nodes'] ?? []; $favorites = $base['favorites']['nodes'] ?? [];
$stats = $base['stats'] ?? []; $stats = $base['stats'] ?? [];
$waifu = (array_key_exists('waifu', $base)) ? [ $waifu = (array_key_exists('waifu', $base)) ? [
@ -71,7 +72,7 @@ final class UserTransformer extends AbstractTransformer {
return $output; return $output;
} }
private function organizeStats(array $stats, $data = []): array private function organizeStats(array $stats, array $data = []): array
{ {
$animeStats = []; $animeStats = [];
$mangaStats = []; $mangaStats = [];

View File

@ -28,7 +28,7 @@ abstract class AbstractTransformer implements TransformerInterface {
* @param array|object $item * @param array|object $item
* @return mixed * @return mixed
*/ */
abstract public function transform($item); abstract public function transform(array|object $item): mixed;
/** /**
* Transform a set of structures * Transform a set of structures

View File

@ -27,5 +27,5 @@ interface TransformerInterface {
* @param array|object $item * @param array|object $item
* @return mixed * @return mixed
*/ */
public function transform($item); public function transform(array|object $item): mixed;
} }