Skip to content

Commit

Permalink
fix: Applied phpcs and phpmd rules
Browse files Browse the repository at this point in the history
  • Loading branch information
jansentjeu committed Mar 29, 2024
1 parent 763cfca commit e5dc85d
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public function __construct(

/**
* @inheritDoc
*
* phpcs:disable Magento2.CodeAnalysis.EmptyBlock.DetectedCatch
* phpcs:disable Generic.CodeAnalysis.EmptyStatement.DetectedCatch
*/
public function getRewrites(MagentoHttpRequest $request): array
{
Expand Down Expand Up @@ -107,6 +110,7 @@ protected function getPossibleLandingPagePaths(string $fullUriPath): array
$lastPathPart .= '/' . $pathPart;
$paths[] = $lastPathPart;
}

$paths = array_reverse($paths);

if (!$this->attributeLandingConfig->isAppendCategoryUrlSuffix()) {
Expand Down
7 changes: 5 additions & 2 deletions src/Model/FilterApplier/TweakwiseFilterApplier.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @author Bram Gerritsen <bgerritsen@emico.nl>
* @copyright (c) Emico B.V. 2017
Expand Down Expand Up @@ -40,11 +41,13 @@ public function applyFilters(LandingPageInterface $page)
$navigationRequest->addAttributeFilter($filter->getFacet(), $filter->getValue());
}

if ($filterTemplateId = $page->getTweakwiseFilterTemplate()) {
$filterTemplateId = $page->getTweakwiseFilterTemplate();
if ($filterTemplateId) {
$navigationRequest->setTemplateId($filterTemplateId);
}

if ($sortTemplateId = $page->getTweakwiseSortTemplate()) {
$sortTemplateId = $page->getTweakwiseSortTemplate();
if ($sortTemplateId) {
$navigationRequest->setSortTemplateId($sortTemplateId);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* @author : Edwin Jacobs, email: ejacobs@emico.nl.
* @copyright : Copyright Emico B.V. 2020.
*/

namespace Tweakwise\AttributeLandingTweakwise\Model\FilterFormInputProvider;

use Emico\AttributeLanding\Api\Data\LandingPageInterface;
Expand Down Expand Up @@ -114,7 +115,7 @@ protected function getPage(): LandingPageInterface
/**
* @return string
*/
public function getOriginalUrl() : string
public function getOriginalUrl(): string
{
return $this->layerUrl->getUrlStrategy()->getOriginalUrl($this->request);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Model/FilterHider/TweakwiseFilterHider.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @author Bram Gerritsen <bgerritsen@emico.nl>
* @copyright (c) Emico B.V. 2017
Expand Down Expand Up @@ -26,8 +27,7 @@ public function shouldHideFilter(
LandingPageInterface $landingPage,
FilterInterface $filter,
Item $filterItem = null
): bool
{
): bool {
if (!$filter instanceof TweakwiseFilter) {
return false;
}
Expand Down
35 changes: 24 additions & 11 deletions src/Model/FilterManager.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @author Bram Gerritsen <bgerritsen@emico.nl>
* @copyright (c) Emico B.V. 2017
Expand Down Expand Up @@ -92,7 +93,8 @@ static function (Item $item) {
SORT_REGULAR
);

if ($url = $this->urlFinder->findUrlByFilters($filters, $layer->getCurrentCategory()->getEntityId())) {
$url = $this->urlFinder->findUrlByFilters($filters, $layer->getCurrentCategory()->getEntityId());
if ($url) {
return $url;
}

Expand All @@ -104,7 +106,8 @@ static function (Item $item) {
*/
public function getLandingsPageFilters()
{
if (!$landingsPage = $this->landingPageContext->getLandingPage()) {
$landingsPage = $this->landingPageContext->getLandingPage();
if (!$landingsPage) {
return [];
}

Expand All @@ -122,18 +125,23 @@ public function getActiveFiltersExcludingLandingPageFilters(): array
if ($landingPage === null) {
return $filters;
}

/** @var string|int $index */
foreach ($filters as $index => $filterItem) {
if ($this->filterHider->shouldHideFilter(
$landingPage,
$filterItem->getFilter(),
$filterItem
)) {
if (
$this->filterHider->shouldHideFilter(
$landingPage,
$filterItem->getFilter(),
$filterItem
)
) {
unset($filters[$index]);
}
}

$this->activeFiltersExcludingLandingPageFilters = $filters;
}

return $this->activeFiltersExcludingLandingPageFilters;
}

Expand All @@ -150,15 +158,19 @@ public function getAllActiveFilters(): array
if (!\is_array($filterItems)) {
return [];
}

// Do not consider category as active
$filterItems = \array_filter($filterItems, function (Item $filter) {
$source = $filter
$filterItems = \array_filter(
$filterItems,
function (Item $filter) {
$source = $filter
->getFilter()
->getFacet()
->getFacetSettings()
->getSource();
return $source !== SettingsType::SOURCE_CATEGORY;
});
return $source !== SettingsType::SOURCE_CATEGORY;
}
);
$this->activeFilters = $filterItems;
return $this->activeFilters;
}
Expand Down Expand Up @@ -186,6 +198,7 @@ public function isFilterAvailableOnLandingPage(LandingPageInterface $landingPage
return true;
}
}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

/**
* Class DefaultRendererPlugin
* @package Tweakwise\AttributeLandingTweakwise\Plugin\Block\LayeredNavigation\RenderLayered
*/
class RendererPlugin
{
Expand All @@ -27,7 +26,7 @@ public function __construct(FilterManager $filterManager)
}

/**
* @param Template $renderer used Template here as this class is subscribed multiple times as a plugin
* @param Template $renderer
* @param string $result
* @param Item $filterItem
* @return string
Expand Down
9 changes: 5 additions & 4 deletions src/Plugin/Model/AjaxNavigationResultPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,17 @@ public function __construct(
$this->url = $url;
}

public function aroundGetResponseUrl(AjaxNavigationResult $ajaxNavigationResult, callable $proceed) {
$type = $this->request->getParam('__tw_ajax_type');
public function aroundGetResponseUrl(AjaxNavigationResult $ajaxNavigationResult, callable $proceed)
{
$type = $this->request->getParam('__tw_ajax_type');

if ($type === 'landingpage' && $this->landingPageContext->getLandingPage()) {
$filters = $this->filterManager->getActiveFiltersExcludingLandingPageFilters();
$url = $this->url->getFilterUrl($filters);

return $url;
}
}

return $proceed();
return $proceed();
}
}
8 changes: 6 additions & 2 deletions src/Plugin/PathSlugStrategyPlugin.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @author Bram Gerritsen <bgerritsen@emico.nl>
* @copyright (c) Emico B.V. 2017
Expand Down Expand Up @@ -41,7 +42,7 @@ class PathSlugStrategyPlugin
* @param LandingPageContext $landingPageContext
* @param FilterManager $filterManager
* @param UrlFactory $urlFactory
* @param Url $magentoUrl
* @param FilterSlugManager $filterSlugManager
*/
public function __construct(
LandingPageContext $landingPageContext,
Expand Down Expand Up @@ -133,11 +134,13 @@ public function aroundGetAttributeRemoveUrl(
} else {
$filters = $this->filterManager->getAllActiveFilters();
}

foreach ($filters as $key => $activeItem) {
if ($activeItem === $item) {
unset($filters[$key]);
}
}

return $pathSlugStrategy->buildFilterUrl($request, $filters);
}

Expand Down Expand Up @@ -186,7 +189,8 @@ public function afterGetCategoryFilterSelectUrl(
}

/**
* @deprecated
* @param PathSlugStrategy $original
* @param string $result
* @param MagentoHttpRequest $request
* @return string
*/
Expand Down
12 changes: 9 additions & 3 deletions src/Plugin/QueryParameterStrategyPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* @author : Edwin Jacobs, email: ejacobs@emico.nl.
* @copyright : Copyright Emico B.V. 2020.
*/

namespace Tweakwise\AttributeLandingTweakwise\Plugin;

use Emico\AttributeLanding\Model\LandingPageContext;
Expand Down Expand Up @@ -55,6 +56,8 @@ public function __construct(
* @param QueryParameterStrategy $original
* @param string $result
* @return string
*
* phpcs:disable Magento2.Functions.DiscouragedFunction.Discouraged
*/
public function afterGetCategoryFilterSelectUrl(
QueryParameterStrategy $original,
Expand Down Expand Up @@ -98,8 +101,11 @@ public function afterGetCategoryFilterSelectUrl(
/**
* {@inheritdoc}
*/
public function afterGetAttributeFilters(QueryParameterStrategy $original, array $result, MagentoHttpRequest $request)
{
public function afterGetAttributeFilters(
QueryParameterStrategy $original,
array $result,
MagentoHttpRequest $request
) {
$landingPage = $this->landingPageContext->getLandingPage();
if ($landingPage === null) {
return $result;
Expand All @@ -112,7 +118,7 @@ public function afterGetAttributeFilters(QueryParameterStrategy $original, array
if (isset($result[$filter->getFacet()])) {
foreach ($result[$filter->getFacet()] as $key => $value) {
if ($value == $filter->getValue()) {
unset ($result[$filter->getFacet()][$key]);
unset($result[$filter->getFacet()][$key]);
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/Plugin/Seo/FilterHelperPlugin.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @author Bram Gerritsen <bgerritsen@emico.nl>
* @copyright (c) Emico B.V. 2017
Expand Down Expand Up @@ -43,11 +44,13 @@ public function __construct(
*/
public function aroundShouldPageBeIndexable(FilterHelper $helper, callable $proceed): bool
{
if ($this->landingPageContext->isOnLandingPage() &&
if (
$this->landingPageContext->isOnLandingPage() &&
\count($this->filterManager->getActiveFiltersExcludingLandingPageFilters()) === 0
) {
return true;
}

return $proceed();
}

Expand All @@ -61,6 +64,7 @@ public function aroundGetActiveFilterItems(FilterHelper $helper, callable $proce
if ($this->landingPageContext->isOnLandingPage()) {
return $this->filterManager->getActiveFiltersExcludingLandingPageFilters();
}

return $proceed();
}

Expand Down
4 changes: 3 additions & 1 deletion src/Plugin/UrlPlugin.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @author Bram Gerritsen <bgerritsen@emico.nl>
* @copyright (c) Emico B.V. 2017
Expand Down Expand Up @@ -78,7 +79,8 @@ public function aroundGetSelectFilter(Url $subject, Closure $proceed, Item $filt
return $proceed($filterItem);
}

if ($url = $this->filterManager->findLandingPageUrlForFilterItem($filterItem)) {
$url = $this->filterManager->findLandingPageUrlForFilterItem($filterItem);
if ($url) {
return '/' . $url;
}

Expand Down
1 change: 1 addition & 0 deletions src/registration.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Tweakwise_AttributeLandingTweakwise',
Expand Down

0 comments on commit e5dc85d

Please sign in to comment.