Solve more PHPStan issues

This commit is contained in:
Timothy Warren 2021-02-12 11:14:45 -05:00
parent 35ec3c8bfa
commit 2cd9f99011
6 changed files with 36 additions and 12 deletions

View File

@ -8,10 +8,12 @@ parameters:
- ./console - ./console
- index.php - index.php
ignoreErrors: ignoreErrors:
- '#Access to an undefined property Aviat\\Ion\\Friend#'
- "#Offset 'fields' does not exist on array#" - "#Offset 'fields' does not exist on array#"
- '#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:
- tests/mocks.php - tests/mocks.php
- vendor - vendor
# These are objects that basically can return anything
universalObjectCratesClasses:
- Aviat\Ion\Friend

View File

@ -66,7 +66,7 @@ final class Auth {
->getSegment(SESSION_SEGMENT); ->getSegment(SESSION_SEGMENT);
$this->model = $container->get('kitsu-model'); $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 * @param string $password
* @return boolean * @return boolean
* @throws Throwable * @throws Throwable
* @throws InvalidArgumentException
*/ */
public function authenticate(string $password): bool public function authenticate(string $password): bool
{ {
@ -90,9 +91,10 @@ final class Auth {
/** /**
* Make the call to re-authenticate with the existing refresh token * Make the call to re-authenticate with the existing refresh token
* *
* @param string $refreshToken * @param string|null $refreshToken
* @return boolean * @return boolean
* @throws Throwable|InvalidArgumentException * @throws InvalidArgumentException
* @throws Throwable
*/ */
public function reAuthenticate(?string $refreshToken = NULL): bool public function reAuthenticate(?string $refreshToken = NULL): bool
{ {

View File

@ -28,6 +28,7 @@ final class LibraryEntryTransformer extends AbstractTransformer
{ {
public function transform($item) public function transform($item)
{ {
$item = (array)$item;
$type = $item['media']['type'] ?? ''; $type = $item['media']['type'] ?? '';
$genres = []; $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']; $animeId = $item['media']['id'];
$anime = $item['media']; $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']; $mangaId = $item['media']['id'];
$manga = $item['media']; $manga = $item['media'];

View File

@ -413,5 +413,6 @@ function renderTemplate(string $path, array $data): string
ob_start(); ob_start();
extract($data, EXTR_OVERWRITE); extract($data, EXTR_OVERWRITE);
include $path; include $path;
return ob_get_clean(); $rawOutput = ob_get_clean();
return (is_string($rawOutput)) ? $rawOutput : '';
} }

View File

@ -52,13 +52,22 @@ abstract class BaseCommand extends Command {
* @param string|int|null $bgColor * @param string|int|null $bgColor
* @return void * @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)) if (is_array($message))
{ {
$message = implode("\n", $message); $message = implode("\n", $message);
} }
if ($fgColor !== NULL)
{
$fgColor = (string)$fgColor;
}
if ($bgColor !== NULL)
{
$bgColor = (string)$bgColor;
}
// color message // color message
$message = Colors::colorize($message, $fgColor, $bgColor); $message = Colors::colorize($message, $fgColor, $bgColor);
@ -129,8 +138,17 @@ abstract class BaseCommand extends Command {
return $this->_di($configArray, $APP_DIR); 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); $message = Colors::colorize($message, $fgColor, $bgColor);
$this->getConsole()->writeln($message); $this->getConsole()->writeln($message);
} }

View File

@ -218,7 +218,7 @@ final class SyncLists extends BaseCommand {
* @param array $data * @param array $data
* @throws Throwable * @throws Throwable
*/ */
protected function update(string $type, array $data) protected function update(string $type, array $data): void
{ {
if ( ! empty($data['addToAnilist'])) if ( ! empty($data['addToAnilist']))
{ {
@ -259,7 +259,7 @@ final class SyncLists extends BaseCommand {
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// Fetch helpers // Fetch helpers
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
private function fetchAnilistCount(string $type) private function fetchAnilistCount(string $type): int
{ {
$list = $this->fetchAnilist($type); $list = $this->fetchAnilist($type);