Code style updates
This commit is contained in:
parent
05d4fb1ad7
commit
45449b6907
@ -133,7 +133,7 @@ final class Auth
|
||||
/**
|
||||
* Save the new authentication information
|
||||
*/
|
||||
private function storeAuth(array|FALSE $auth): bool
|
||||
private function storeAuth(array|false $auth): bool
|
||||
{
|
||||
if (FALSE !== $auth)
|
||||
{
|
||||
|
@ -34,6 +34,7 @@ use Aviat\AnimeClient\API\{
|
||||
use Aviat\AnimeClient\Enum\MediaType;
|
||||
use Aviat\AnimeClient\Kitsu as K;
|
||||
use Aviat\AnimeClient\Types\{Anime, MangaPage};
|
||||
use Aviat\AnimeClient\Types\{AnimeListItem, MangaListItem};
|
||||
use Aviat\Ion\{
|
||||
Di\ContainerAware,
|
||||
Json
|
||||
|
@ -67,9 +67,6 @@ trait MutationTrait
|
||||
|
||||
/**
|
||||
* Remove a list item
|
||||
*
|
||||
* @param FormItem $data
|
||||
* @return Request
|
||||
*/
|
||||
public function deleteItem(FormItem $data): Request
|
||||
{
|
||||
|
@ -35,7 +35,7 @@ final class ParallelAPIRequest
|
||||
/**
|
||||
* Add a request
|
||||
*/
|
||||
public function addRequest(string|Request $request, string|int|NULL $key = NULL): self
|
||||
public function addRequest(string|Request $request, string|int|null $key = NULL): self
|
||||
{
|
||||
if ($key !== NULL)
|
||||
{
|
||||
|
@ -17,6 +17,7 @@ namespace Aviat\AnimeClient;
|
||||
use Amp\Http\Client\{HttpClient, HttpClientBuilder, Request, Response};
|
||||
|
||||
use Aviat\Ion\{ConfigInterface, ImageBuilder};
|
||||
use PHPUnit\Framework\Attributes\CodeCoverageIgnore;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
use Throwable;
|
||||
|
||||
@ -31,9 +32,9 @@ use function Aviat\Ion\_dir;
|
||||
/**
|
||||
* Load configuration options from .toml files
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @param string $path - Path to load config
|
||||
*/
|
||||
#[CodeCoverageIgnore]
|
||||
function loadConfig(string $path): array
|
||||
{
|
||||
$output = [];
|
||||
@ -72,9 +73,8 @@ function loadConfig(string $path): array
|
||||
|
||||
/**
|
||||
* Load config from one specific TOML file
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
#[CodeCoverageIgnore]
|
||||
function loadTomlFile(string $filename): array
|
||||
{
|
||||
return Toml::parseFile($filename);
|
||||
@ -131,19 +131,6 @@ function tomlToArray(string $toml): array
|
||||
//! Misc Functions
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('array_is_list'))
|
||||
{
|
||||
/**
|
||||
* Polyfill for PHP 8
|
||||
*
|
||||
* @see https://www.php.net/manual/en/function.array-is-list
|
||||
*/
|
||||
function array_is_list(array $a): bool
|
||||
{
|
||||
return $a === [] || (array_keys($a) === range(0, count($a) - 1));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the array sequential, not associative?
|
||||
*/
|
||||
@ -256,9 +243,8 @@ function getLocalImg(string $kitsuUrl, bool $webp = TRUE): string
|
||||
|
||||
/**
|
||||
* Create a transparent placeholder image
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
#[CodeCoverageIgnore]
|
||||
function createPlaceholderImage(string $path, int $width = 200, int $height = 200, string $text = 'Image Unavailable'): bool
|
||||
{
|
||||
$img = ImageBuilder::new($width, $height)
|
||||
@ -303,16 +289,15 @@ function clearCache(CacheInterface $cache): bool
|
||||
|
||||
$cleared = $cache->clear();
|
||||
|
||||
$saved = (empty($userData)) ? TRUE : $cache->setMultiple($userData);
|
||||
$saved = empty($userData) || $cache->setMultiple($userData);
|
||||
|
||||
return $cleared && $saved;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a PHP code template as a string
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
#[CodeCoverageIgnore]
|
||||
function renderTemplate(string $path, array $data): string
|
||||
{
|
||||
ob_start();
|
||||
|
@ -44,7 +44,7 @@ abstract class BaseCommand extends Command
|
||||
/**
|
||||
* Echo text in a box
|
||||
*/
|
||||
public function echoBox(string|array $message, string|int|NULL $fgColor = NULL, string|int|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))
|
||||
{
|
||||
@ -131,7 +131,7 @@ abstract class BaseCommand extends Command
|
||||
return $this->_di($configArray, $APP_DIR);
|
||||
}
|
||||
|
||||
private function _line(string $message, int|string|NULL $fgColor = NULL, int|string|NULL $bgColor = NULL): void
|
||||
private function _line(string $message, int|string|null $fgColor = NULL, int|string|null $bgColor = NULL): void
|
||||
{
|
||||
if ($fgColor !== NULL)
|
||||
{
|
||||
|
@ -98,7 +98,8 @@ final class SyncLists extends BaseCommand
|
||||
if ( ! $anilistEnabled)
|
||||
{
|
||||
$this->echoErrorBox('Anlist API is not enabled. Can not sync.');
|
||||
return false;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Authentication is required to update Kitsu
|
||||
@ -106,13 +107,14 @@ final class SyncLists extends BaseCommand
|
||||
if ( ! $isKitsuAuthenticated)
|
||||
{
|
||||
$this->echoErrorBox('Kitsu is not authenticated. Kitsu list can not be updated.');
|
||||
return false;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$this->anilistModel = $this->container->get('anilist-model');
|
||||
$this->kitsuModel = $this->container->get('kitsu-model');
|
||||
|
||||
return true;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -148,7 +150,7 @@ final class SyncLists extends BaseCommand
|
||||
*/
|
||||
protected function fetch(string $type): array
|
||||
{
|
||||
$this->echo("Fetching $type List Data");
|
||||
$this->echo("Fetching {$type} List Data");
|
||||
$progress = new Widgets\ProgressBar($this->getConsole(), 2, 50, FALSE);
|
||||
|
||||
$anilist = $this->fetchAnilist($type);
|
||||
|
@ -123,10 +123,10 @@ class Controller
|
||||
/**
|
||||
* Set the current url in the session as the target of a future redirect
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @throws ContainerException
|
||||
* @throws NotFoundException
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\CodeCoverageIgnore]
|
||||
public function setSessionRedirect(?string $url = NULL): void
|
||||
{
|
||||
$serverParams = $this->request->getServerParams();
|
||||
@ -163,9 +163,9 @@ class Controller
|
||||
*
|
||||
* If one is not set, redirect to default url
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\CodeCoverageIgnore]
|
||||
public function sessionRedirect(): void
|
||||
{
|
||||
$target = $this->session->get('redirect_url') ?? '/';
|
||||
@ -176,8 +176,8 @@ class Controller
|
||||
|
||||
/**
|
||||
* Check if the current user is authenticated, else error and exit
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\CodeCoverageIgnore]
|
||||
protected function checkAuth(): void
|
||||
{
|
||||
if ( ! $this->auth->isAuthenticated())
|
||||
@ -192,9 +192,8 @@ class Controller
|
||||
|
||||
/**
|
||||
* Get the string output of a partial template
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\CodeCoverageIgnore]
|
||||
protected function loadPartial(HtmlView $view, string $template, array $data = []): string
|
||||
{
|
||||
$router = $this->container->get('dispatcher');
|
||||
@ -219,9 +218,8 @@ class Controller
|
||||
|
||||
/**
|
||||
* Render a template with header and footer
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\CodeCoverageIgnore]
|
||||
protected function renderFullPage(HtmlView $view, string $template, array $data): HtmlView
|
||||
{
|
||||
$csp = [
|
||||
@ -247,9 +245,9 @@ class Controller
|
||||
/**
|
||||
* 404 action
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\CodeCoverageIgnore]
|
||||
public function notFound(
|
||||
string $title = 'Sorry, page not found',
|
||||
string $message = 'Page Not Found'
|
||||
@ -265,9 +263,9 @@ class Controller
|
||||
/**
|
||||
* Display a generic error page
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\CodeCoverageIgnore]
|
||||
public function errorPage(int $httpCode, string $title, string $message, string $longMessage = ''): void
|
||||
{
|
||||
$this->outputHTML('error', [
|
||||
@ -280,9 +278,9 @@ class Controller
|
||||
/**
|
||||
* Redirect to the default controller/url from an empty path
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\CodeCoverageIgnore]
|
||||
public function redirectToDefaultRoute(): void
|
||||
{
|
||||
$defaultType = $this->config->get('default_list');
|
||||
@ -292,9 +290,8 @@ class Controller
|
||||
/**
|
||||
* Set a session flash variable to display a message on
|
||||
* next page load
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\CodeCoverageIgnore]
|
||||
public function setFlashMessage(string $message, string $type = 'info'): void
|
||||
{
|
||||
static $messages;
|
||||
@ -325,9 +322,9 @@ class Controller
|
||||
/**
|
||||
* Add a message box to the page
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\CodeCoverageIgnore]
|
||||
protected function showMessage(HtmlView $view, string $type, string $message): string
|
||||
{
|
||||
return $this->loadPartial($view, 'message', [
|
||||
@ -339,9 +336,9 @@ class Controller
|
||||
/**
|
||||
* Output a template to HTML, using the provided data
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\CodeCoverageIgnore]
|
||||
protected function outputHTML(string $template, array $data = [], ?HtmlView $view = NULL, int $code = 200): void
|
||||
{
|
||||
if (NULL === $view)
|
||||
@ -356,10 +353,10 @@ class Controller
|
||||
/**
|
||||
* Output a JSON Response
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @param int $code - the http status code
|
||||
* @throws DoubleRenderException
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\CodeCoverageIgnore]
|
||||
protected function outputJSON(mixed $data, int $code): void
|
||||
{
|
||||
JsonView::new()
|
||||
@ -370,9 +367,8 @@ class Controller
|
||||
|
||||
/**
|
||||
* Redirect to the selected page
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\CodeCoverageIgnore]
|
||||
protected function redirect(string $url, int $code): void
|
||||
{
|
||||
HttpView::new()
|
||||
|
@ -21,8 +21,7 @@ use Aviat\AnimeClient\API\Mapping\AnimeWatchingStatus;
|
||||
use Aviat\AnimeClient\Controller as BaseController;
|
||||
use Aviat\AnimeClient\Model\Anime as AnimeModel;
|
||||
use Aviat\AnimeClient\Types\FormItem;
|
||||
use Aviat\Ion\Attribute\Controller;
|
||||
use Aviat\Ion\Attribute\Route;
|
||||
use Aviat\Ion\Attribute\{Controller, Route};
|
||||
use Aviat\Ion\Di\ContainerInterface;
|
||||
use Aviat\Ion\Di\Exception\{ContainerException, NotFoundException};
|
||||
use Aviat\Ion\Json;
|
||||
|
@ -20,11 +20,9 @@ use Aviat\AnimeClient\Model\{
|
||||
Anime as AnimeModel,
|
||||
AnimeCollection as AnimeCollectionModel
|
||||
};
|
||||
use Aviat\Ion\Attribute\Controller;
|
||||
use Aviat\Ion\Attribute\Route;
|
||||
use Aviat\Ion\Attribute\{Controller, Route};
|
||||
use Aviat\Ion\Di\ContainerInterface;
|
||||
use Aviat\Ion\Di\Exception\{ContainerException, NotFoundException};
|
||||
use Aviat\Ion\Json;
|
||||
use Aviat\Ion\Exception\DoubleRenderException;
|
||||
|
||||
use InvalidArgumentException;
|
||||
@ -114,7 +112,6 @@ final class AnimeCollection extends BaseController
|
||||
/**
|
||||
* Show the anime collection add/edit form
|
||||
*
|
||||
* @param int|null $id
|
||||
* @throws ContainerException
|
||||
* @throws InvalidArgumentException
|
||||
* @throws NotFoundException
|
||||
|
@ -18,8 +18,7 @@ use Aviat\AnimeClient\API\Kitsu\Model;
|
||||
use Aviat\AnimeClient\API\Kitsu\Transformer\CharacterTransformer;
|
||||
use Aviat\AnimeClient\Controller as BaseController;
|
||||
|
||||
use Aviat\Ion\Attribute\Controller;
|
||||
use Aviat\Ion\Attribute\Route;
|
||||
use Aviat\Ion\Attribute\{Controller, Route};
|
||||
use Aviat\Ion\Di\ContainerInterface;
|
||||
use Aviat\Ion\Di\Exception\{ContainerException, NotFoundException};
|
||||
|
||||
|
@ -14,9 +14,8 @@
|
||||
|
||||
namespace Aviat\AnimeClient\Controller;
|
||||
|
||||
use Aviat\Ion\Attribute\Controller;
|
||||
use Aviat\Ion\Attribute\Route;
|
||||
use Aviat\AnimeClient\{Controller as BaseController, Model};
|
||||
use Aviat\Ion\Attribute\{Controller, Route};
|
||||
use Aviat\Ion\Di\ContainerInterface;
|
||||
use Aviat\Ion\Di\Exception\{ContainerException, NotFoundException};
|
||||
|
||||
|
@ -15,8 +15,7 @@
|
||||
namespace Aviat\AnimeClient\Controller;
|
||||
|
||||
use Aviat\AnimeClient\Controller as BaseController;
|
||||
use Aviat\Ion\Attribute\Controller;
|
||||
use Aviat\Ion\Attribute\Route;
|
||||
use Aviat\Ion\Attribute\{Controller, Route};
|
||||
use Throwable;
|
||||
use function Amp\Promise\wait;
|
||||
use function Aviat\AnimeClient\{createPlaceholderImage, getResponse};
|
||||
|
@ -14,21 +14,16 @@
|
||||
|
||||
namespace Aviat\AnimeClient\Controller;
|
||||
|
||||
use Aura\Router\Exception\RouteNotFound;
|
||||
use Aviat\AnimeClient\API\Kitsu\Transformer\MangaListTransformer;
|
||||
use Aviat\AnimeClient\API\Mapping\MangaReadingStatus;
|
||||
use Aviat\AnimeClient\Controller as BaseController;
|
||||
use Aviat\AnimeClient\Model\Manga as MangaModel;
|
||||
use Aviat\AnimeClient\Types\FormItem;
|
||||
use Aviat\Ion\Attribute\Controller;
|
||||
use Aviat\Ion\Attribute\Route;
|
||||
use Aviat\Ion\Attribute\{Controller, Route};
|
||||
use Aviat\Ion\Di\ContainerInterface;
|
||||
use Aviat\Ion\Di\Exception\{ContainerException, NotFoundException};
|
||||
use Aviat\Ion\Json;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Controller for manga list
|
||||
*/
|
||||
|
@ -15,12 +15,10 @@
|
||||
namespace Aviat\AnimeClient\Controller;
|
||||
|
||||
use Aviat\AnimeClient\API\Kitsu\Model;
|
||||
use Aviat\AnimeClient\API\Kitsu\Transformer\CharacterTransformer;
|
||||
use Aviat\AnimeClient\API\Kitsu\Transformer\PersonTransformer;
|
||||
use Aviat\AnimeClient\API\Kitsu\Transformer\{CharacterTransformer, PersonTransformer};
|
||||
use Aviat\AnimeClient\Controller as BaseController;
|
||||
use Aviat\AnimeClient\Enum\EventType;
|
||||
use Aviat\Ion\Attribute\DefaultController;
|
||||
use Aviat\Ion\Attribute\Route;
|
||||
use Aviat\Ion\Attribute\{DefaultController, Route};
|
||||
use Aviat\Ion\Di\ContainerInterface;
|
||||
use Aviat\Ion\Event;
|
||||
use Aviat\Ion\View\HtmlView;
|
||||
|
@ -18,8 +18,7 @@ use Aviat\AnimeClient\API\Kitsu\Model;
|
||||
use Aviat\AnimeClient\API\Kitsu\Transformer\PersonTransformer;
|
||||
use Aviat\AnimeClient\Controller as BaseController;
|
||||
|
||||
use Aviat\Ion\Attribute\Controller;
|
||||
use Aviat\Ion\Attribute\Route;
|
||||
use Aviat\Ion\Attribute\{Controller, Route};
|
||||
use Aviat\Ion\Di\ContainerInterface;
|
||||
use Aviat\Ion\Di\Exception\{ContainerException, NotFoundException};
|
||||
|
||||
|
@ -18,8 +18,7 @@ use Aura\Router\Exception\RouteNotFound;
|
||||
use Aviat\AnimeClient\API\Anilist\Model as AnilistModel;
|
||||
use Aviat\AnimeClient\Controller as BaseController;
|
||||
use Aviat\AnimeClient\Model\Settings as SettingsModel;
|
||||
use Aviat\Ion\Attribute\Controller;
|
||||
use Aviat\Ion\Attribute\Route;
|
||||
use Aviat\Ion\Attribute\{Controller, Route};
|
||||
use Aviat\Ion\Di\ContainerInterface;
|
||||
use Aviat\Ion\Di\Exception\{ContainerException, NotFoundException};
|
||||
|
||||
|
@ -18,8 +18,7 @@ use Aviat\AnimeClient\API\Kitsu\Model;
|
||||
use Aviat\AnimeClient\API\Kitsu\Transformer\UserTransformer;
|
||||
use Aviat\AnimeClient\Controller as BaseController;
|
||||
|
||||
use Aviat\Ion\Attribute\Controller;
|
||||
use Aviat\Ion\Attribute\Route;
|
||||
use Aviat\Ion\Attribute\{Controller, Route};
|
||||
use Aviat\Ion\Di\ContainerInterface;
|
||||
use Aviat\Ion\Di\Exception\{ContainerException, NotFoundException};
|
||||
|
||||
|
@ -317,7 +317,8 @@ final class Dispatcher extends RoutingBase
|
||||
|
||||
$params = [];
|
||||
|
||||
switch ($failure->failedRule) {
|
||||
switch ($failure->failedRule)
|
||||
{
|
||||
case Rule\Allows::class:
|
||||
$params = [
|
||||
'http_code' => 405,
|
||||
|
@ -95,14 +95,7 @@ final class Settings
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists($key, $values) && is_scalar($values[$key]))
|
||||
{
|
||||
$value['value'] = $values[$key];
|
||||
}
|
||||
else
|
||||
{
|
||||
$value['value'] = $value['default'] ?? '';
|
||||
}
|
||||
$value['value'] = array_key_exists($key, $values) && is_scalar($values[$key]) ? $values[$key] : $value['default'] ?? '';
|
||||
|
||||
foreach (['readonly', 'disabled'] as $flag)
|
||||
{
|
||||
|
@ -201,10 +201,8 @@ abstract class AbstractType implements ArrayAccess, Countable, Stringable
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
final protected function fromObject(mixed $parent = NULL): float|NULL|bool|int|array|string
|
||||
#[\PHPUnit\Framework\Attributes\CodeCoverageIgnore]
|
||||
final protected function fromObject(mixed $parent = NULL): float|null|bool|int|array|string
|
||||
{
|
||||
$object = $parent ?? $this;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user