Fix a bunch more phpstan errors

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
ignoreErrors:
- "#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 Query\\QueryBuilderInterface::[a-zA-Z0-9_]+\(\)#'
excludes_analyse:

View File

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

View File

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

View File

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

View File

@ -58,10 +58,9 @@ trait CacheTrait {
* @param string $key
* @param callable $primer
* @param array|null $primeArgs
* @return mixed|null
* @throws InvalidArgumentException
* @return mixed
*/
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);

View File

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

View File

@ -26,7 +26,6 @@ use Amp\Http\Client\Request;
use Amp\Http\Client\Response;
use Aviat\AnimeClient\Kitsu as K;
use Aviat\AnimeClient\API\APIRequestBuilder;
use Aviat\AnimeClient\API\FailedResponseException;
use Aviat\AnimeClient\Enum\EventType;
use Aviat\Ion\Di\ContainerAware;
use Aviat\Ion\Di\ContainerInterface;
@ -157,7 +156,6 @@ final class RequestBuilder extends APIRequestBuilder {
* @param string $name
* @param array $variables
* @return array
* @throws Throwable
*/
public function mutate(string $name, array $variables = []): array
{
@ -181,7 +179,6 @@ final class RequestBuilder extends APIRequestBuilder {
* @param string $url
* @param array $options
* @return Response
* @throws \Throwable
*/
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
{
$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.');
}
@ -240,12 +237,11 @@ final class RequestBuilder extends APIRequestBuilder {
* @param string $name
* @param array $variables
* @return Request
* @throws Throwable
*/
public function mutateRequest (string $name, array $variables = []): Request
{
$file = "{$this->filePath}/Mutations/{$name}.graphql";
if ( ! file_exists($file))
$file = realpath("{$this->filePath}/Mutations/{$name}.graphql");
if ($file === FALSE || ! file_exists($file))
{
throw new LogicException('GraphQL mutation file does not exist.');
}
@ -274,9 +270,6 @@ final class RequestBuilder extends APIRequestBuilder {
* @param string $type
* @param string $url
* @param array $options
* @throws JsonException
* @throws FailedResponseException
* @throws Throwable
* @return 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
* logical and workable structure
*
* @param array $item API library item
* @param array|object $item API library item
* @return AnimeListItem
*/
public function transform($item): AnimeListItem
public function transform(array|object $item): AnimeListItem
{
$item = (array)$item;
$animeId = $item['media']['id'];
$anime = $item['media'];
@ -115,7 +116,7 @@ final class AnimeListTransformer extends AbstractTransformer {
* @param array $item Transformed 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']);
$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
* logical and workable structure
*
* @param array $item API library item
* @param array|object $item API library item
* @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'];
$characters = [];
$links = [];

View File

@ -28,12 +28,13 @@ use Locale;
final class CharacterTransformer extends AbstractTransformer {
/**
* @param array $characterData
* @param array|object $item
* @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 = [];
$media = [
'anime' => [],

View File

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

View File

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

View File

@ -29,11 +29,12 @@ final class MangaTransformer extends AbstractTransformer {
* Convert raw api response to a more
* logical and workable structure
*
* @param array $item API library item
* @param array|object $item API library item
* @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'];
$characters = [];
$links = [];

View File

@ -26,12 +26,13 @@ use Aviat\Ion\Transformer\AbstractTransformer;
final class PersonTransformer extends AbstractTransformer {
/**
* @param array|object $personData
* @param array|object $item
* @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']]
?? array_shift($data['names']['localized']);

View File

@ -29,9 +29,10 @@ use Aviat\Ion\Transformer\AbstractTransformer;
* @return User
*/
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'] ?? [];
$stats = $base['stats'] ?? [];
$waifu = (array_key_exists('waifu', $base)) ? [
@ -71,7 +72,7 @@ final class UserTransformer extends AbstractTransformer {
return $output;
}
private function organizeStats(array $stats, $data = []): array
private function organizeStats(array $stats, array $data = []): array
{
$animeStats = [];
$mangaStats = [];

View File

@ -148,7 +148,7 @@ abstract class BaseCommand extends Command {
{
$bgColor = (string)$bgColor;
}
$message = Colors::colorize($message, $fgColor, $bgColor);
$this->getConsole()->writeln($message);
}

View File

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

View File

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