Skip to content

Commit 7127ffc

Browse files
author
Denis V
committed
allow empty allowed limits and provide the default limit in BaseConfig artprima#3
1 parent ca465d9 commit 7127ffc

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

QueryFilter/Config/BaseConfig.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
*/
1414
class BaseConfig implements ConfigInterface
1515
{
16+
private const DEFAULT_LIMIT = 10;
17+
1618
/**
1719
* @var Request
1820
*/
@@ -106,7 +108,7 @@ public function addSearchByAliases(Alias $alias): ConfigInterface
106108
*/
107109
public function getSearchByAliases(): array
108110
{
109-
return $this->searchBy['aliases'];
111+
return $this->searchBy['aliases'] ?? [];
110112
}
111113

112114
/**
@@ -177,7 +179,7 @@ public function getRepositoryCallback(): callable
177179
*/
178180
public function getAllowedLimits(): array
179181
{
180-
return $this->allowedLimits;
182+
return $this->allowedLimits ?? [];
181183
}
182184

183185
/**
@@ -205,7 +207,7 @@ public function setDefaultLimit(int $limit): ConfigInterface
205207
*/
206208
public function getDefaultLimit(): int
207209
{
208-
return $this->defaultLimit;
210+
return $this->defaultLimit ?? self::DEFAULT_LIMIT;
209211
}
210212

211213
/**

QueryFilter/Config/ConfigInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function setAllowedLimits(array $allowedLimits): ConfigInterface;
109109
*
110110
* @return array
111111
*/
112-
public function getAllowedLimits(): array;
112+
public function getAllowedLimits(): ?array;
113113

114114
/**
115115
* @var int $limit default limit in case of limit not specified or limit is not within the allowed limits

QueryFilter/QueryFilter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ private function getQueryFilterArgs(ConfigInterface $config): QueryFilterArgs
226226

227227
$limit = $config->getRequest()->getLimit();
228228
$allowedLimits = $config->getAllowedLimits();
229-
if ($limit === -1 || (!empty($allowedLimits) && !in_array($limit, $config->getAllowedLimits(), true))) {
229+
if ($limit === -1 || !in_array($limit, $allowedLimits, true)) {
230230
$limit = $config->getDefaultLimit();
231231
}
232232

0 commit comments

Comments
 (0)