Skip to content
This repository has been archived by the owner on Oct 19, 2022. It is now read-only.

Commit

Permalink
Add return types and trim filter values before exploding
Browse files Browse the repository at this point in the history
  • Loading branch information
Herant committed Dec 8, 2021
1 parent ec59255 commit 259f0f7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 9 additions & 2 deletions Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,17 +390,24 @@ public function getFilterWhitelist(Store $store = null)
* @param Store|null $store
* @return array
*/
public function getFilterValuesWhitelist(Store $store = null)
public function getFilterValuesWhitelist(Store $store = null): array
{
$filterList = $this->getStoreConfig('tweakwise/seo/filter_values_whitelist', $store);

if (empty($filterList)) {
return [];
}

$filterList = trim($filterList);

$filterListExploded = explode(',', $filterList) ?: [];
if (empty($filterListExploded)) {
return [];
}

$return = [];
foreach ($filterListExploded as $listItem) {
$item = explode('=', $listItem) ?: null;
$item = explode('=', trim($listItem)) ?: null;
if ($item === null) {
continue;
}
Expand Down
6 changes: 2 additions & 4 deletions Model/Seo/FilterHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ protected function getAttributeCodeFromFilterItem(Item $item)
* @param Item $item
* @return string|null
*/
protected function getAttributeValueFromFilterItem(Item $item)
protected function getAttributeValueFromFilterItem(Item $item): ?string
{
return $item->getAttribute()->getTitle();
}
Expand Down Expand Up @@ -174,13 +174,11 @@ protected function isFilterValueItemInWhiteList(Item $item): bool
return false;
}

$isIn = \in_array(
return \in_array(
strtolower($attributeValue),
array_map('strtolower', $filterValuesWhiteList[$attributeCode]),
true
);

return $isIn;
}

/**
Expand Down

0 comments on commit 259f0f7

Please sign in to comment.