From 0cff22099385fe265b321e3510a21ed59b9171a3 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Tue, 9 May 2023 12:49:36 -0400 Subject: [PATCH] Code style updates --- src/AnimeClient/API/Anilist/Model.php | 6 +- src/AnimeClient/API/Kitsu/Auth.php | 2 +- src/AnimeClient/API/Kitsu/Model.php | 1 + src/AnimeClient/API/Kitsu/MutationTrait.php | 3 - src/AnimeClient/API/ParallelAPIRequest.php | 2 +- src/AnimeClient/AnimeClient.php | 27 +--- src/AnimeClient/Command/BaseCommand.php | 4 +- src/AnimeClient/Command/SyncLists.php | 12 +- src/AnimeClient/Controller.php | 150 +++++++++--------- src/AnimeClient/Controller/Anime.php | 3 +- .../Controller/AnimeCollection.php | 5 +- src/AnimeClient/Controller/Character.php | 3 +- src/AnimeClient/Controller/History.php | 3 +- src/AnimeClient/Controller/Images.php | 3 +- src/AnimeClient/Controller/Manga.php | 7 +- src/AnimeClient/Controller/Misc.php | 6 +- src/AnimeClient/Controller/People.php | 3 +- src/AnimeClient/Controller/Settings.php | 3 +- src/AnimeClient/Controller/User.php | 3 +- src/AnimeClient/Dispatcher.php | 9 +- src/AnimeClient/Model/Settings.php | 9 +- src/AnimeClient/Types/AbstractType.php | 6 +- 22 files changed, 113 insertions(+), 157 deletions(-) diff --git a/src/AnimeClient/API/Anilist/Model.php b/src/AnimeClient/API/Anilist/Model.php index d5833c84..383ba619 100644 --- a/src/AnimeClient/API/Anilist/Model.php +++ b/src/AnimeClient/API/Anilist/Model.php @@ -189,7 +189,7 @@ final class Model */ public function deleteItem(FormItem $data, string $type): ?Request { - $mediaId = $this->getMediaId((array)$data, $type); + $mediaId = $this->getMediaId((array) $data, $type); if ($mediaId === NULL) { return NULL; @@ -209,7 +209,7 @@ final class Model */ public function getListIdFromData(FormItem $data, string $type = 'ANIME'): ?string { - $mediaId = $this->getMediaId((array)$data, $type); + $mediaId = $this->getMediaId((array) $data, $type); if ($mediaId === NULL) { return NULL; @@ -244,7 +244,7 @@ final class Model /** * Find the id to update by */ - private function getMediaId (array $data, string $type = 'ANIME'): ?string + private function getMediaId(array $data, string $type = 'ANIME'): ?string { if (isset($data['anilist_id'])) { diff --git a/src/AnimeClient/API/Kitsu/Auth.php b/src/AnimeClient/API/Kitsu/Auth.php index 342ee77f..8e302696 100644 --- a/src/AnimeClient/API/Kitsu/Auth.php +++ b/src/AnimeClient/API/Kitsu/Auth.php @@ -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) { diff --git a/src/AnimeClient/API/Kitsu/Model.php b/src/AnimeClient/API/Kitsu/Model.php index 6c72a635..b4cf554f 100644 --- a/src/AnimeClient/API/Kitsu/Model.php +++ b/src/AnimeClient/API/Kitsu/Model.php @@ -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 diff --git a/src/AnimeClient/API/Kitsu/MutationTrait.php b/src/AnimeClient/API/Kitsu/MutationTrait.php index 52cb84ea..1660a5ea 100644 --- a/src/AnimeClient/API/Kitsu/MutationTrait.php +++ b/src/AnimeClient/API/Kitsu/MutationTrait.php @@ -67,9 +67,6 @@ trait MutationTrait /** * Remove a list item - * - * @param FormItem $data - * @return Request */ public function deleteItem(FormItem $data): Request { diff --git a/src/AnimeClient/API/ParallelAPIRequest.php b/src/AnimeClient/API/ParallelAPIRequest.php index 6af3b7b2..b2a3cf4f 100644 --- a/src/AnimeClient/API/ParallelAPIRequest.php +++ b/src/AnimeClient/API/ParallelAPIRequest.php @@ -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) { diff --git a/src/AnimeClient/AnimeClient.php b/src/AnimeClient/AnimeClient.php index 819eb4dd..2a07674e 100644 --- a/src/AnimeClient/AnimeClient.php +++ b/src/AnimeClient/AnimeClient.php @@ -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(); diff --git a/src/AnimeClient/Command/BaseCommand.php b/src/AnimeClient/Command/BaseCommand.php index 6da5f206..62e73846 100644 --- a/src/AnimeClient/Command/BaseCommand.php +++ b/src/AnimeClient/Command/BaseCommand.php @@ -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) { diff --git a/src/AnimeClient/Command/SyncLists.php b/src/AnimeClient/Command/SyncLists.php index d73ba1b8..d2d897d3 100644 --- a/src/AnimeClient/Command/SyncLists.php +++ b/src/AnimeClient/Command/SyncLists.php @@ -98,21 +98,23 @@ 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 $isKitsuAuthenticated = $this->container->get('auth')->isAuthenticated(); - if ( !$isKitsuAuthenticated) + 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); diff --git a/src/AnimeClient/Controller.php b/src/AnimeClient/Controller.php index b0beb7e0..b7363d9d 100644 --- a/src/AnimeClient/Controller.php +++ b/src/AnimeClient/Controller.php @@ -121,13 +121,13 @@ class Controller } /** - * Set the current url in the session as the target of a future redirect - * - * @codeCoverageIgnore - * @throws ContainerException - * @throws NotFoundException - */ - public function setSessionRedirect(?string $url = NULL): void + * Set the current url in the session as the target of a future redirect + * + * @throws ContainerException + * @throws NotFoundException + */ + #[\PHPUnit\Framework\Attributes\CodeCoverageIgnore] + public function setSessionRedirect(?string $url = NULL): void { $serverParams = $this->request->getServerParams(); @@ -159,14 +159,14 @@ class Controller } /** - * Redirect to the url previously set in the session - * - * If one is not set, redirect to default url - * - * @codeCoverageIgnore - * @throws InvalidArgumentException - */ - public function sessionRedirect(): void + * Redirect to the url previously set in the session + * + * If one is not set, redirect to default url + * + * @throws InvalidArgumentException + */ + #[\PHPUnit\Framework\Attributes\CodeCoverageIgnore] + public function sessionRedirect(): void { $target = $this->session->get('redirect_url') ?? '/'; @@ -175,10 +175,10 @@ class Controller } /** - * Check if the current user is authenticated, else error and exit - * @codeCoverageIgnore - */ - protected function checkAuth(): void + * Check if the current user is authenticated, else error and exit + */ + #[\PHPUnit\Framework\Attributes\CodeCoverageIgnore] + protected function checkAuth(): void { if ( ! $this->auth->isAuthenticated()) { @@ -191,11 +191,10 @@ class Controller } /** - * Get the string output of a partial template - * - * @codeCoverageIgnore - */ - protected function loadPartial(HtmlView $view, string $template, array $data = []): string + * Get the string output of a partial template + */ + #[\PHPUnit\Framework\Attributes\CodeCoverageIgnore] + protected function loadPartial(HtmlView $view, string $template, array $data = []): string { $router = $this->container->get('dispatcher'); @@ -218,11 +217,10 @@ class Controller } /** - * Render a template with header and footer - * - * @codeCoverageIgnore - */ - protected function renderFullPage(HtmlView $view, string $template, array $data): HtmlView + * Render a template with header and footer + */ + #[\PHPUnit\Framework\Attributes\CodeCoverageIgnore] + protected function renderFullPage(HtmlView $view, string $template, array $data): HtmlView { $csp = [ "default-src 'self' media.kitsu.io kitsu-production-media.s3.us-west-002.backblazeb2.com", @@ -245,12 +243,12 @@ class Controller } /** - * 404 action - * - * @codeCoverageIgnore - * @throws InvalidArgumentException - */ - public function notFound( + * 404 action + * + * @throws InvalidArgumentException + */ + #[\PHPUnit\Framework\Attributes\CodeCoverageIgnore] + public function notFound( string $title = 'Sorry, page not found', string $message = 'Page Not Found' ): void { @@ -263,12 +261,12 @@ class Controller } /** - * Display a generic error page - * - * @codeCoverageIgnore - * @throws InvalidArgumentException - */ - public function errorPage(int $httpCode, string $title, string $message, string $longMessage = ''): void + * Display a generic error page + * + * @throws InvalidArgumentException + */ + #[\PHPUnit\Framework\Attributes\CodeCoverageIgnore] + public function errorPage(int $httpCode, string $title, string $message, string $longMessage = ''): void { $this->outputHTML('error', [ 'title' => $title, @@ -278,24 +276,23 @@ class Controller } /** - * Redirect to the default controller/url from an empty path - * - * @codeCoverageIgnore - * @throws InvalidArgumentException - */ - public function redirectToDefaultRoute(): void + * Redirect to the default controller/url from an empty path + * + * @throws InvalidArgumentException + */ + #[\PHPUnit\Framework\Attributes\CodeCoverageIgnore] + public function redirectToDefaultRoute(): void { $defaultType = $this->config->get('default_list'); $this->redirect($this->urlGenerator->defaultUrl($defaultType), 303); } /** - * Set a session flash variable to display a message on - * next page load - * - * @codeCoverageIgnore - */ - public function setFlashMessage(string $message, string $type = 'info'): void + * Set a session flash variable to display a message on + * next page load + */ + #[\PHPUnit\Framework\Attributes\CodeCoverageIgnore] + public function setFlashMessage(string $message, string $type = 'info'): void { static $messages; @@ -323,12 +320,12 @@ class Controller } /** - * Add a message box to the page - * - * @codeCoverageIgnore - * @throws InvalidArgumentException - */ - protected function showMessage(HtmlView $view, string $type, string $message): string + * Add a message box to the page + * + * @throws InvalidArgumentException + */ + #[\PHPUnit\Framework\Attributes\CodeCoverageIgnore] + protected function showMessage(HtmlView $view, string $type, string $message): string { return $this->loadPartial($view, 'message', [ 'message_type' => $type, @@ -337,12 +334,12 @@ class Controller } /** - * Output a template to HTML, using the provided data - * - * @codeCoverageIgnore - * @throws InvalidArgumentException - */ - protected function outputHTML(string $template, array $data = [], ?HtmlView $view = NULL, int $code = 200): void + * Output a template to HTML, using the provided data + * + * @throws InvalidArgumentException + */ + #[\PHPUnit\Framework\Attributes\CodeCoverageIgnore] + protected function outputHTML(string $template, array $data = [], ?HtmlView $view = NULL, int $code = 200): void { if (NULL === $view) { @@ -354,13 +351,13 @@ class Controller } /** - * Output a JSON Response - * - * @codeCoverageIgnore - * @param int $code - the http status code - * @throws DoubleRenderException - */ - protected function outputJSON(mixed $data, int $code): void + * Output a JSON Response + * + * @param int $code - the http status code + * @throws DoubleRenderException + */ + #[\PHPUnit\Framework\Attributes\CodeCoverageIgnore] + protected function outputJSON(mixed $data, int $code): void { JsonView::new() ->setOutput($data) @@ -369,11 +366,10 @@ class Controller } /** - * Redirect to the selected page - * - * @codeCoverageIgnore - */ - protected function redirect(string $url, int $code): void + * Redirect to the selected page + */ + #[\PHPUnit\Framework\Attributes\CodeCoverageIgnore] + protected function redirect(string $url, int $code): void { HttpView::new() ->redirect($url, $code) diff --git a/src/AnimeClient/Controller/Anime.php b/src/AnimeClient/Controller/Anime.php index a29e1abd..be4c807d 100644 --- a/src/AnimeClient/Controller/Anime.php +++ b/src/AnimeClient/Controller/Anime.php @@ -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; diff --git a/src/AnimeClient/Controller/AnimeCollection.php b/src/AnimeClient/Controller/AnimeCollection.php index 5577eda9..26400a64 100644 --- a/src/AnimeClient/Controller/AnimeCollection.php +++ b/src/AnimeClient/Controller/AnimeCollection.php @@ -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 diff --git a/src/AnimeClient/Controller/Character.php b/src/AnimeClient/Controller/Character.php index 1bb5466e..cc0685e6 100644 --- a/src/AnimeClient/Controller/Character.php +++ b/src/AnimeClient/Controller/Character.php @@ -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}; diff --git a/src/AnimeClient/Controller/History.php b/src/AnimeClient/Controller/History.php index 9f654ea4..583c35b8 100644 --- a/src/AnimeClient/Controller/History.php +++ b/src/AnimeClient/Controller/History.php @@ -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}; diff --git a/src/AnimeClient/Controller/Images.php b/src/AnimeClient/Controller/Images.php index 20c9eccd..0abbb1ec 100644 --- a/src/AnimeClient/Controller/Images.php +++ b/src/AnimeClient/Controller/Images.php @@ -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}; diff --git a/src/AnimeClient/Controller/Manga.php b/src/AnimeClient/Controller/Manga.php index 5ab92bc2..cd69a825 100644 --- a/src/AnimeClient/Controller/Manga.php +++ b/src/AnimeClient/Controller/Manga.php @@ -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 */ diff --git a/src/AnimeClient/Controller/Misc.php b/src/AnimeClient/Controller/Misc.php index 1f4ac47d..f4ba9fe2 100644 --- a/src/AnimeClient/Controller/Misc.php +++ b/src/AnimeClient/Controller/Misc.php @@ -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; diff --git a/src/AnimeClient/Controller/People.php b/src/AnimeClient/Controller/People.php index e142c0e6..5e7db3db 100644 --- a/src/AnimeClient/Controller/People.php +++ b/src/AnimeClient/Controller/People.php @@ -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}; diff --git a/src/AnimeClient/Controller/Settings.php b/src/AnimeClient/Controller/Settings.php index 325f0861..a5ffe601 100644 --- a/src/AnimeClient/Controller/Settings.php +++ b/src/AnimeClient/Controller/Settings.php @@ -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}; diff --git a/src/AnimeClient/Controller/User.php b/src/AnimeClient/Controller/User.php index 3bc6ad20..4a0268d6 100644 --- a/src/AnimeClient/Controller/User.php +++ b/src/AnimeClient/Controller/User.php @@ -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}; diff --git a/src/AnimeClient/Dispatcher.php b/src/AnimeClient/Dispatcher.php index 3d0ab117..b278091d 100644 --- a/src/AnimeClient/Dispatcher.php +++ b/src/AnimeClient/Dispatcher.php @@ -317,14 +317,15 @@ final class Dispatcher extends RoutingBase $params = []; - switch ($failure->failedRule) { + switch ($failure->failedRule) + { case Rule\Allows::class: $params = [ 'http_code' => 405, 'title' => '405 Method Not Allowed', 'message' => 'Invalid HTTP Verb', ]; - break; + break; case Rule\Accepts::class: $params = [ @@ -332,12 +333,12 @@ final class Dispatcher extends RoutingBase 'title' => '406 Not Acceptable', 'message' => 'Unacceptable content type', ]; - break; + break; default: // Fall back to a 404 message $actionMethod = NOT_FOUND_METHOD; - break; + break; } return [ diff --git a/src/AnimeClient/Model/Settings.php b/src/AnimeClient/Model/Settings.php index 83d10832..40df895e 100644 --- a/src/AnimeClient/Model/Settings.php +++ b/src/AnimeClient/Model/Settings.php @@ -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) { diff --git a/src/AnimeClient/Types/AbstractType.php b/src/AnimeClient/Types/AbstractType.php index dce78ad0..a49d532d 100644 --- a/src/AnimeClient/Types/AbstractType.php +++ b/src/AnimeClient/Types/AbstractType.php @@ -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;