From eb03679579019e05f54fc305c5b8efbb67e29f37 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Fri, 12 Feb 2021 11:14:45 -0500 Subject: [PATCH] Solve more PHPStan issues --- phpstan.neon | 6 +++-- src/AnimeClient/API/Kitsu/Auth.php | 8 ++++--- .../Transformer/LibraryEntryTransformer.php | 5 +++-- src/AnimeClient/AnimeClient.php | 3 ++- src/AnimeClient/Command/BaseCommand.php | 22 +++++++++++++++++-- src/AnimeClient/Command/SyncLists.php | 4 ++-- 6 files changed, 36 insertions(+), 12 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index a5bf6603..53b8e218 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -8,10 +8,12 @@ parameters: - ./console - index.php ignoreErrors: - - '#Access to an undefined property Aviat\\Ion\\Friend#' - "#Offset 'fields' does not exist on array#" - '#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: - tests/mocks.php - - vendor \ No newline at end of file + - vendor + # These are objects that basically can return anything + universalObjectCratesClasses: + - Aviat\Ion\Friend diff --git a/src/AnimeClient/API/Kitsu/Auth.php b/src/AnimeClient/API/Kitsu/Auth.php index 54d5de7c..67a1f7f3 100644 --- a/src/AnimeClient/API/Kitsu/Auth.php +++ b/src/AnimeClient/API/Kitsu/Auth.php @@ -66,7 +66,7 @@ final class Auth { ->getSegment(SESSION_SEGMENT); $this->model = $container->get('kitsu-model'); - Event::on('::unauthorized::', [$this, 'reAuthenticate'], []); + Event::on('::unauthorized::', [$this, 'reAuthenticate']); } /** @@ -76,6 +76,7 @@ final class Auth { * @param string $password * @return boolean * @throws Throwable + * @throws InvalidArgumentException */ public function authenticate(string $password): bool { @@ -90,9 +91,10 @@ final class Auth { /** * Make the call to re-authenticate with the existing refresh token * - * @param string $refreshToken + * @param string|null $refreshToken * @return boolean - * @throws Throwable|InvalidArgumentException + * @throws InvalidArgumentException + * @throws Throwable */ public function reAuthenticate(?string $refreshToken = NULL): bool { diff --git a/src/AnimeClient/API/Kitsu/Transformer/LibraryEntryTransformer.php b/src/AnimeClient/API/Kitsu/Transformer/LibraryEntryTransformer.php index b18409bd..2a9b4105 100644 --- a/src/AnimeClient/API/Kitsu/Transformer/LibraryEntryTransformer.php +++ b/src/AnimeClient/API/Kitsu/Transformer/LibraryEntryTransformer.php @@ -28,6 +28,7 @@ final class LibraryEntryTransformer extends AbstractTransformer { public function transform($item) { + $item = (array)$item; $type = $item['media']['type'] ?? ''; $genres = []; @@ -50,7 +51,7 @@ final class LibraryEntryTransformer extends AbstractTransformer } } - private function animeTransform($item, array $genres): AnimeListItem + private function animeTransform(array $item, array $genres): AnimeListItem { $animeId = $item['media']['id']; $anime = $item['media']; @@ -119,7 +120,7 @@ final class LibraryEntryTransformer extends AbstractTransformer ]); } - private function mangaTransform($item, array $genres): MangaListItem + private function mangaTransform(array $item, array $genres): MangaListItem { $mangaId = $item['media']['id']; $manga = $item['media']; diff --git a/src/AnimeClient/AnimeClient.php b/src/AnimeClient/AnimeClient.php index 9dd179ba..1a903d89 100644 --- a/src/AnimeClient/AnimeClient.php +++ b/src/AnimeClient/AnimeClient.php @@ -413,5 +413,6 @@ function renderTemplate(string $path, array $data): string ob_start(); extract($data, EXTR_OVERWRITE); include $path; - return ob_get_clean(); + $rawOutput = ob_get_clean(); + return (is_string($rawOutput)) ? $rawOutput : ''; } \ No newline at end of file diff --git a/src/AnimeClient/Command/BaseCommand.php b/src/AnimeClient/Command/BaseCommand.php index f043d9e2..b538e2cd 100644 --- a/src/AnimeClient/Command/BaseCommand.php +++ b/src/AnimeClient/Command/BaseCommand.php @@ -52,13 +52,22 @@ abstract class BaseCommand extends Command { * @param string|int|null $bgColor * @return void */ - public function echoBox($message, $fgColor = NULL, $bgColor = NULL): void + public function echoBox(string|array $message, string|int|null $fgColor = NULL, string|int|null $bgColor = NULL): void { if (is_array($message)) { $message = implode("\n", $message); } + if ($fgColor !== NULL) + { + $fgColor = (string)$fgColor; + } + if ($bgColor !== NULL) + { + $bgColor = (string)$bgColor; + } + // color message $message = Colors::colorize($message, $fgColor, $bgColor); @@ -129,8 +138,17 @@ abstract class BaseCommand extends Command { return $this->_di($configArray, $APP_DIR); } - private function _line(string $message, $fgColor = NULL, $bgColor = NULL): void + private function _line(string $message, int|string|null $fgColor = NULL, int|string|null $bgColor = NULL): void { + if ($fgColor !== NULL) + { + $fgColor = (string)$fgColor; + } + if ($bgColor !== NULL) + { + $bgColor = (string)$bgColor; + } + $message = Colors::colorize($message, $fgColor, $bgColor); $this->getConsole()->writeln($message); } diff --git a/src/AnimeClient/Command/SyncLists.php b/src/AnimeClient/Command/SyncLists.php index 8eb01e0f..427ec829 100644 --- a/src/AnimeClient/Command/SyncLists.php +++ b/src/AnimeClient/Command/SyncLists.php @@ -218,7 +218,7 @@ final class SyncLists extends BaseCommand { * @param array $data * @throws Throwable */ - protected function update(string $type, array $data) + protected function update(string $type, array $data): void { if ( ! empty($data['addToAnilist'])) { @@ -259,7 +259,7 @@ final class SyncLists extends BaseCommand { // ------------------------------------------------------------------------ // Fetch helpers // ------------------------------------------------------------------------ - private function fetchAnilistCount(string $type) + private function fetchAnilistCount(string $type): int { $list = $this->fetchAnilist($type);