refactorings

This commit is contained in:
pushrbx 2023-06-28 16:43:11 +01:00
parent 714d4cb490
commit 10d25cc022
5 changed files with 13 additions and 10 deletions

View File

@ -381,7 +381,7 @@ class Anime extends JikanApiSearchableModel
{
return [
[
"field" => "_text_match(buckets:" . App::make("jikan-config")->maxResultsPerPage() . ")",
"field" => "_text_match(buckets:" . max_results_per_page() . ")",
"direction" => "desc"
],
[

View File

@ -8,7 +8,7 @@ trait ResolvesPaginatorParams
{
private function getPaginatorParams(?int $limit = null, ?int $page = null): array
{
$default_max_results_per_page = App::make("jikan-config")->maxResultsPerPage();
$default_max_results_per_page = max_results_per_page();
$limit = $limit ?? $default_max_results_per_page;
$page = $page ?? 1;

View File

@ -20,7 +20,7 @@ trait PreparesData
// let's always set the limit parameter to the globally configured default value
if (property_exists(static::class, "limit") && !$properties->has("limit")) {
/** @noinspection PhpUndefinedFieldInspection */
$properties->put("limit", App::make("jikan-config")->maxResultsPerPage(
$properties->put("limit", max_results_per_page(
property_exists(static::class, "defaultLimit") ? static::$defaultLimit : null));
}

View File

@ -28,7 +28,7 @@ final class MaxResultsPerPageRule implements Rule
$value = intval($value);
}
if ($value > $this->maxResultsPerPage()) {
if ($value > max_results_per_page()) {
return false;
}
@ -37,11 +37,7 @@ final class MaxResultsPerPageRule implements Rule
public function message(): array|string
{
return "Value {$this->value} is higher than the configured '{$this->maxResultsPerPage()}' max value.";
}
private function maxResultsPerPage(): int
{
return (int) App::make("jikan-config")->maxResultsPerPage($this->fallbackLimit);
$mrpp = max_results_per_page();
return "Value {$this->value} is higher than the configured '$mrpp' max value.";
}
}

View File

@ -54,3 +54,10 @@ if (!function_exists('to_boolean')) {
}
}
if (!function_exists('max_results_per_page')) {
function max_results_per_page(?int $fallbackLimit = null): int
{
return app()->make("jikan-config")->maxResultsPerPage($fallbackLimit);
}
}