diff --git a/.github/workflows/testing-suite.yaml b/.github/workflows/grumphp.yaml similarity index 72% rename from .github/workflows/testing-suite.yaml rename to .github/workflows/grumphp.yaml index f33b374..af31d25 100644 --- a/.github/workflows/testing-suite.yaml +++ b/.github/workflows/grumphp.yaml @@ -1,4 +1,4 @@ -name: Testing Suite +name: GrumPHP on: [push] jobs: linter: @@ -13,10 +13,11 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 - - name: Testing Suite + - name: GrumPHP run: | composer2 config http-basic.repo.magento.com ${{ secrets.MAGENTO_USERNAME }} ${{ secrets.MAGENTO_PASSWORD }} + composer2 config gitlab-token.git.emico.io ${{ secrets.GITLAB_TOKEN }} composer2 install --dev --prefer-dist --no-scripts --no-progress --optimize-autoloader --no-interaction -vvv composer2 show - vendor/bin/grumphp run --no-interaction + vendor/bin/grumphp run --tasks=phpmd,phpcs,xmllint,phplint,composer --no-interaction shell: bash diff --git a/.gitignore b/.gitignore index ba79275..de7710c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ /.idea /vendor /composer.lock +/auth.json /build/local.env /build/data diff --git a/.grumphpinclude b/.grumphpinclude new file mode 100644 index 0000000..a922fa6 --- /dev/null +++ b/.grumphpinclude @@ -0,0 +1,3 @@ +# Add all files which should be included in here. +# Patterns are equal to .gitignore +*.php diff --git a/composer.json b/composer.json index dd76d52..497f6be 100644 --- a/composer.json +++ b/composer.json @@ -7,11 +7,8 @@ "magento/module-catalog": "^102.0||^103.0||^104.0" }, "require-dev": { - "symfony/finder": "6.4.0", - "youwe/testing-suite": "^2.18", - "youwe/coding-standard-magento2": "^2.0.0", - "phpstan/extension-installer": "^1.3", - "bitexpert/phpstan-magento": "^0.30.1" + "emico/code-quality": "^10.5", + "symfony/finder": "6.4.0" }, "prefer-stable": true, "type": "magento2-module", @@ -26,35 +23,24 @@ "Emico\\AttributeLanding\\": "src" } }, - "repositories": [ - { + "repositories": { + "magento": { "type": "composer", "url": "https://repo.magento.com/" + }, + "emico/code-quality": { + "type": "vcs", + "url": "https://git.emico.io/composer-packages/generic/codequality.git" } - ], + }, "config": { "sort-packages": true, "allow-plugins": { "magento/composer-dependency-version-audit-plugin": true, - "youwe/coding-standard-phpstorm": true, - "phpro/grumphp-shim": true, "dealerdirect/phpcodesniffer-composer-installer": true, - "youwe/testing-suite": true, - "phpstan/extension-installer": true + "phpstan/extension-installer": true, + "phpro/grumphp": true, + "emico/code-quality": true } - }, - "archive": { - "exclude": [ - "/.gitignore", - "/grumphp.yml", - "/pdepend.xml", - "/phpstan.neon", - "/phpunit.xml", - "/phpcs.xml", - "/phpmd.xml", - "/package.json", - "/.eslintrc.json", - "/.eslintignore" - ] } } diff --git a/grumphp.yml b/grumphp.yml index 69f43b7..453b594 100644 --- a/grumphp.yml +++ b/grumphp.yml @@ -1,90 +1,44 @@ -parameters: - # Default settings for php testing suite tasks - composer.strict: true - - jsonlint.detect_key_conflicts: true - - xmllint.load_from_net: true - xmllint.x_include: true - xmllint.dtd_validation: true - xmllint.scheme_validation: true - xmllint.triggered_by: [xml] - xmllint.ignore_patterns: - # Uses an incomplete definition, which conflicts when - # is defined. - - /^phpcs.xml$/ - - /^phpmd.xml$/ - - /^phpunit.xml$/ - - /^pdepend.xml$/ - - yamllint.parse_constant: true - - phpcs.standard: ./phpcs.xml - phpcs.triggered_by: [php,phtml] - - phplint.exclude: ['vendor'] - phplint.jobs: ~ - phplint.short_open_tag: false - phplint.ignore_patterns: [ ] - phplint.triggered_by: ['php'] - - phpmd.exclude: [] - phpmd.ruleset: - - ./phpmd.xml - phpmd.triggered_by: [php] - - phpstan.autoload_file: ~ - phpstan.configuration: ./phpstan.neon - phpstan.level: 4 - phpstan.triggered_by: [php] - - phpunit.config_file: ./phpunit.xml - - securitychecker.lockfile: ./composer.lock - securitychecker.run_always: true - - git_blacklist.keywords: - - "die(" - - "dd(" - - "var_dump(" - - "console.log(" - - "print_r(" - - "phpinfo(" - - "exit(" - - "exit;" - - "<<<<<<<" - - ">>>>>>>" - - "=======" - - " - - - - memory - - - diff --git a/phpcs.xml b/phpcs.xml deleted file mode 100644 index 2eb1290..0000000 --- a/phpcs.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - PHPCS - - - - - - - - diff --git a/phpcs.xml b/phpcs.xml new file mode 120000 index 0000000..7dc8705 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1 @@ +vendor/emico/code-quality/config-templates/magento/phpcs.dist.xml \ No newline at end of file diff --git a/phpmd.xml b/phpmd.xml deleted file mode 100644 index 1b454e9..0000000 --- a/phpmd.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - PHPMD - - - diff --git a/phpstan.neon b/phpstan.neon index 9314954..fb3ba23 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,3 +1,27 @@ +services: + - class: Emico\CodeQuality\PHPStan\VarModelExtension + tags: + - phpstan.broker.methodsClassReflectionExtension + parameters: - excludePaths: -# - %rootDir%/../../../path/to/exclude/* + ignoreErrors: + - '/Call to an undefined method Mockery\\ExpectationInterface|Mockery\\HigherOrderMessage::andReturnUsing\(\)./' + - '/expects string, Magento\\Framework\\Phrase given/' + - identifier: missingType.iterableValue + - identifier: missingType.generics + - messages: + - '/::delete\(\) expects Magento\\Framework\\Model\\AbstractModel,/' + - '/::save\(\) expects Magento\\Framework\\Model\\AbstractModel,/' + - '/::load\(\) expects Magento\\Framework\\Model\\AbstractModel,/' + path: *Repository.php + stubFiles: + - ./vendor/emico/code-quality/phpstan/stubs/globalFunctions.stub + - ./vendor/emico/code-quality/phpstan/stubs/Magento/Catalog/Model/ResourceModel/Product/Collection.stub + - ./vendor/emico/code-quality/phpstan/stubs/Magento/Eav/Setup/EavSetup.stub + - ./vendor/emico/code-quality/phpstan/stubs/Magento/Framework/Api/Search/FilterGroupBuilder.stub + - ./vendor/emico/code-quality/phpstan/stubs/Magento/Framework/App/ActionFlag.stub + - ./vendor/emico/code-quality/phpstan/stubs/Magento/Framework/Escaper.stub + - ./vendor/emico/code-quality/phpstan/stubs/Magento/Framework/Serialize/SerializerInterface.stub + - ./vendor/emico/code-quality/phpstan/stubs/Magento/InventoryImportExport/Model/Import/Serializer/Json.stub + bootstrapFiles: + - ../../autoload.php diff --git a/ruleset.xml b/ruleset.xml new file mode 120000 index 0000000..7aa9095 --- /dev/null +++ b/ruleset.xml @@ -0,0 +1 @@ +vendor/emico/code-quality/config-templates/magento/ruleset.dist.xml \ No newline at end of file diff --git a/src/Api/Data/FilterInterface.php b/src/Api/Data/FilterInterface.php index 010a866..fa35d24 100644 --- a/src/Api/Data/FilterInterface.php +++ b/src/Api/Data/FilterInterface.php @@ -1,4 +1,4 @@ - diff --git a/src/Api/Data/LandingPageInterface.php b/src/Api/Data/LandingPageInterface.php index c3980e6..94052c7 100644 --- a/src/Api/Data/LandingPageInterface.php +++ b/src/Api/Data/LandingPageInterface.php @@ -1,4 +1,4 @@ - @@ -72,7 +72,7 @@ public function isActive(): bool; /** * Get name - * @return string|null + * @return string */ public function getName(): string; @@ -167,7 +167,7 @@ public function setFilterAttributes(?string $filterAttributes): LandingPageInter public function getFilters(): array; /** - * @return mixed + * @return array */ public function getUnserializedFilterAttributes(): array; @@ -183,13 +183,13 @@ public function getOverviewPageImage(); /** * @return bool - * @SuppressWarnings(PHPMD.BooleanGetMethodName) + * @SuppressWarnings("PHPMD.BooleanGetMethodName") */ public function getIsFilterLinkAllowed(): bool; /** * @return bool - * @SuppressWarnings(PHPMD.BooleanGetMethodName) + * @SuppressWarnings("PHPMD.BooleanGetMethodName") */ public function getHideSelectedFilters(): bool; diff --git a/src/Api/Data/OverviewPageInterface.php b/src/Api/Data/OverviewPageInterface.php index ddc89df..88fb96f 100644 --- a/src/Api/Data/OverviewPageInterface.php +++ b/src/Api/Data/OverviewPageInterface.php @@ -1,4 +1,4 @@ - diff --git a/src/Api/Data/OverviewPageSearchResultsInterface.php b/src/Api/Data/OverviewPageSearchResultsInterface.php index 962ca5b..5a46717 100644 --- a/src/Api/Data/OverviewPageSearchResultsInterface.php +++ b/src/Api/Data/OverviewPageSearchResultsInterface.php @@ -1,4 +1,4 @@ - diff --git a/src/Api/Data/PageSearchResultsInterface.php b/src/Api/Data/PageSearchResultsInterface.php index 1f4a5bb..42935cf 100644 --- a/src/Api/Data/PageSearchResultsInterface.php +++ b/src/Api/Data/PageSearchResultsInterface.php @@ -1,4 +1,4 @@ - diff --git a/src/Api/LandingPageRepositoryInterface.php b/src/Api/LandingPageRepositoryInterface.php index 145935c..4337539 100644 --- a/src/Api/LandingPageRepositoryInterface.php +++ b/src/Api/LandingPageRepositoryInterface.php @@ -1,4 +1,4 @@ - diff --git a/src/Block/Adminhtml/OverviewPage/Edit/BackButton.php b/src/Block/Adminhtml/OverviewPage/Edit/BackButton.php index f2853f3..6df4333 100644 --- a/src/Block/Adminhtml/OverviewPage/Edit/BackButton.php +++ b/src/Block/Adminhtml/OverviewPage/Edit/BackButton.php @@ -1,4 +1,4 @@ - @@ -33,11 +33,6 @@ class Breadcrumbs extends CatalogBreadcrumbs */ private $overviewPageRepository; - /** - * @var UrlInterface - */ - private UrlInterface $urlInterface; - /** * @param Context $context * @param Data $catalogData @@ -51,13 +46,12 @@ public function __construct( Data $catalogData, LandingPageContext $landingPageContext, OverviewPageRepositoryInterface $overviewPageRepository, - UrlInterface $urlInterface, + private UrlInterface $urlInterface, array $data = [] ) { parent::__construct($context, $catalogData, $data); $this->landingPageContext = $landingPageContext; $this->overviewPageRepository = $overviewPageRepository; - $this->urlInterface = $urlInterface; } /** @@ -70,11 +64,13 @@ public function __construct( protected function _prepareLayout() { $landingPage = $this->landingPageContext->getLandingPage(); + /** @phpstan-ignore-next-line */ if ($landingPage === null) { return parent::_prepareLayout(); } $this->addLandingPageBreadCrumbs($landingPage); + return $this; } /** @@ -90,17 +86,20 @@ public function addLandingPageBreadCrumbs(LandingPageInterface $landingPage): vo return; } + /** @phpstan-ignore-next-line */ $breadcrumbsBlock->addCrumb( 'home', [ 'label' => __('Home'), 'title' => __('Go to Home Page'), - 'link' => $this->_storeManager->getStore()->getBaseUrl() + 'link' => $this->_storeManager->getStore()->getBaseUrl() // @phpstan-ignore-line ] ); + /** @phpstan-ignore-next-line */ if ($landingPage->getOverviewPageId() !== null) { $overviewPage = $this->overviewPageRepository->getById($landingPage->getOverviewPageId()); + /** @phpstan-ignore-next-line */ $breadcrumbsBlock->addCrumb( 'overviewpage', [ @@ -111,6 +110,7 @@ public function addLandingPageBreadCrumbs(LandingPageInterface $landingPage): vo ); } + /** @phpstan-ignore-next-line */ $breadcrumbsBlock->addCrumb( 'landingpage', [ diff --git a/src/Block/LandingPage/Content.php b/src/Block/LandingPage/Content.php index 2781dd8..dead2a8 100644 --- a/src/Block/LandingPage/Content.php +++ b/src/Block/LandingPage/Content.php @@ -1,4 +1,4 @@ - diff --git a/src/Block/LayeredNavigation/Navigation/FilterHidePlugin.php b/src/Block/LayeredNavigation/Navigation/FilterHidePlugin.php index a74b5d2..a2780b7 100644 --- a/src/Block/LayeredNavigation/Navigation/FilterHidePlugin.php +++ b/src/Block/LayeredNavigation/Navigation/FilterHidePlugin.php @@ -1,4 +1,4 @@ - @@ -42,18 +42,22 @@ public function __construct(LandingPageContext $landingPageContext, FilterHiderI * @param Navigation $subject * @param array $filters * @return array + * phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter */ public function afterGetFilters(Navigation $subject, array $filters) { $landingPage = $this->landingPageContext->getLandingPage(); + /** @phpstan-ignore-next-line */ if (!$landingPage || !$landingPage->getHideSelectedFilters()) { return $filters; } foreach ($filters as $index => $filter) { - if ($this->filterHider->shouldHideFilter($landingPage, $filter)) { - unset($filters[$index]); + if (!$this->filterHider->shouldHideFilter($landingPage, $filter)) { + continue; } + + unset($filters[$index]); } return $filters; diff --git a/src/Block/OverviewPage/View.php b/src/Block/OverviewPage/View.php index fee2502..2a7f3a2 100644 --- a/src/Block/OverviewPage/View.php +++ b/src/Block/OverviewPage/View.php @@ -1,4 +1,4 @@ - @@ -77,6 +77,7 @@ public function __construct( public function getLandingPages(): array { $overviewPage = $this->getOverviewPage(); + /** @phpstan-ignore-next-line */ if ($overviewPage === null) { return []; } @@ -99,6 +100,7 @@ public function getOverviewPage(): OverviewPageInterface public function getLandingPageImage(LandingPageInterface $landingPage): ?string { $image = $landingPage->getOverviewPageImage(); + /** @phpstan-ignore-next-line */ if ($image === null) { return null; } @@ -145,6 +147,7 @@ protected function getFilteredContent(string $content): string */ protected function _prepareLayout(): View { + /** @phpstan-ignore-next-line */ if ($this->landingPageContext->getOverviewPage() === null) { return parent::_prepareLayout(); } @@ -159,7 +162,7 @@ protected function _prepareLayout(): View [ 'label' => __('Home'), 'title' => __('Go to Home Page'), - 'link' => $this->_storeManager->getStore()->getBaseUrl() + 'link' => $this->_storeManager->getStore()->getBaseUrl() // @phpstan-ignore-line ] ); diff --git a/src/Console/Command/RegenerateUrlRewrites.php b/src/Console/Command/RegenerateUrlRewrites.php index e3587b1..018a442 100644 --- a/src/Console/Command/RegenerateUrlRewrites.php +++ b/src/Console/Command/RegenerateUrlRewrites.php @@ -9,37 +9,21 @@ use Emico\AttributeLanding\Model\UrlRewriteService; use Exception; use Magento\Framework\Api\SearchCriteriaBuilder; -use Magento\Framework\App\Area; -use Magento\Framework\App\State; use Magento\Framework\Console\Cli; use Magento\Framework\Exception\LocalizedException; -use Magento\Store\Model\App\Emulation; -use Magento\Store\Model\StoreManagerInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; class RegenerateUrlRewrites extends Command { - private LandingPageRepositoryInterface $landingPageRepository; - - private SearchCriteriaBuilder $searchCriteriaBuilder; - - private UrlRewriteService $urlRewriteService; - - private OverviewPageRepositoryInterface $overviewPageRepository; - public function __construct( - LandingPageRepositoryInterface $landingPageRepository, - OverviewPageRepositoryInterface $overviewPageRepository, - SearchCriteriaBuilder $searchCriteriaBuilder, - UrlRewriteService $urlRewriteService + private LandingPageRepositoryInterface $landingPageRepository, + private OverviewPageRepositoryInterface $overviewPageRepository, + private SearchCriteriaBuilder $searchCriteriaBuilder, + private UrlRewriteService $urlRewriteService ) { parent::__construct(); - $this->landingPageRepository = $landingPageRepository; - $this->searchCriteriaBuilder = $searchCriteriaBuilder; - $this->urlRewriteService = $urlRewriteService; - $this->overviewPageRepository = $overviewPageRepository; } /** @@ -59,6 +43,8 @@ protected function configure() * * @return int * @throws LocalizedException + * phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed + * */ protected function execute(InputInterface $input, OutputInterface $output): int { diff --git a/src/Controller/Adminhtml/OverviewPage.php b/src/Controller/Adminhtml/OverviewPage.php index 20e6f48..09fd407 100644 --- a/src/Controller/Adminhtml/OverviewPage.php +++ b/src/Controller/Adminhtml/OverviewPage.php @@ -1,4 +1,4 @@ -resultRedirectFactory->create(); + /** @phpstan-ignore-next-line */ $data = $this->getRequest()->getPostValue(); if (!$data) { diff --git a/src/Controller/Adminhtml/Page.php b/src/Controller/Adminhtml/Page.php index f678624..e92ac08 100644 --- a/src/Controller/Adminhtml/Page.php +++ b/src/Controller/Adminhtml/Page.php @@ -1,4 +1,4 @@ -landingPageRepository->getById($id); + $existingLandingPage = $this->landingPageRepository->getById($id); // @phpstan-ignore-line /** @var LandingPage $newLandingPage */ $newLandingPage = $this->landingPageFactory->create(); @@ -76,6 +76,7 @@ public function execute() $this->messageManager->addNoticeMessage('Your page has been duplicated'); $this->messageManager->addWarningMessage('Do not forget to change the URL path'); + /** @phpstan-ignore-next-line */ return $resultRedirect->setPath('*/*/edit', ['page_id' => $newLandingPage->getId()]); } catch (NoSuchEntityException $exception) { $this->messageManager->addErrorMessage(__('This Page no longer exists.')); diff --git a/src/Controller/Adminhtml/Page/Edit.php b/src/Controller/Adminhtml/Page/Edit.php index 898f7ee..ecda546 100644 --- a/src/Controller/Adminhtml/Page/Edit.php +++ b/src/Controller/Adminhtml/Page/Edit.php @@ -1,4 +1,4 @@ -resultRedirectFactory->create(); + /** @phpstan-ignore-next-line */ $data = $this->getRequest()->getPostValue(); $data[LandingPageInterface::STORE_ID] = (int)$data[LandingPageInterface::STORE_ID]; + /** @phpstan-ignore-next-line */ if (!$data) { return $resultRedirect->setPath('*/*/'); } @@ -122,6 +124,7 @@ public function execute() /** * @param LandingPageInterface $landingPage * @param array $data + * @return void * * phpcs:disable Magento2.Security.InsecureFunction.FoundWithAlternative */ @@ -161,9 +164,12 @@ protected function sanitizeFilterAttributes(array $filterAttributes): array $sanitizedAttributes = []; foreach ($filterAttributes as $filterAttribute) { foreach (array_keys($filterAttribute) as $field) { - if (!in_array($field, $allowedFields)) { - unset($filterAttribute[$field]); + // phpcs:disable SlevomatCodingStandard.Functions.StrictCall.StrictParameterMissing + if (in_array($field, $allowedFields)) { + continue; } + + unset($filterAttribute[$field]); } $sanitizedAttributes[] = $filterAttribute; diff --git a/src/Controller/Adminhtml/Page/UploadImage.php b/src/Controller/Adminhtml/Page/UploadImage.php index 2ff9127..f251af8 100644 --- a/src/Controller/Adminhtml/Page/UploadImage.php +++ b/src/Controller/Adminhtml/Page/UploadImage.php @@ -1,4 +1,4 @@ - @@ -11,7 +11,6 @@ use Magento\Backend\App\Action\Context; use Magento\Framework\Controller\Result\Json; use Magento\Framework\Controller\ResultFactory; -use Psr\Log\LoggerInterface; class UploadImage extends \Magento\Backend\App\Action { diff --git a/src/Controller/LandingPage/View.php b/src/Controller/LandingPage/View.php index f6cd4c2..8979305 100644 --- a/src/Controller/LandingPage/View.php +++ b/src/Controller/LandingPage/View.php @@ -1,4 +1,4 @@ - @@ -7,7 +7,6 @@ namespace Emico\AttributeLanding\Model\Catalog\Layer\State; -use Emico\AttributeLanding\Controller\Page\ViewContext; use Emico\AttributeLanding\Model\FilterHider\FilterHiderInterface; use Emico\AttributeLanding\Model\LandingPageContext; use Magento\Catalog\Model\Layer\Filter\Item; @@ -42,23 +41,28 @@ public function __construct(LandingPageContext $landingPageContext, FilterHiderI * @param Item[] $result * @return mixed * @throws LocalizedException + * phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed */ public function afterGetFilters(State $subject, $result) { + /** @phpstan-ignore-next-line */ if (!\is_array($result) || empty($result)) { return $result; } $landingPage = $this->landingPageContext->getLandingPage(); + /** @phpstan-ignore-next-line */ if (!$landingPage || !$landingPage->getHideSelectedFilters()) { return $result; } /** @var Item $activeFilter */ foreach ($result as $index => $activeFilter) { - if ($this->filterHider->shouldHideFilter($landingPage, $activeFilter->getFilter(), $activeFilter)) { - unset($result[$index]); + if (!$this->filterHider->shouldHideFilter($landingPage, $activeFilter->getFilter(), $activeFilter)) { + continue; } + + unset($result[$index]); } return $result; diff --git a/src/Model/Config.php b/src/Model/Config.php index a5fa9aa..f0c6c4e 100644 --- a/src/Model/Config.php +++ b/src/Model/Config.php @@ -1,4 +1,4 @@ - @@ -79,7 +79,7 @@ public function isCanonicalSelfReferencingEnabled(?Store $store = null): bool return (bool) $this->config->isSetFlag( 'emico_attributelanding/general/canonical_self_referencing', ScopeInterface::SCOPE_STORE, - $store + $store // @phpstan-ignore-line ); } } diff --git a/src/Model/Config/Source/OverviewPage.php b/src/Model/Config/Source/OverviewPage.php index 1839e5b..5a2d6e7 100644 --- a/src/Model/Config/Source/OverviewPage.php +++ b/src/Model/Config/Source/OverviewPage.php @@ -1,4 +1,4 @@ - diff --git a/src/Model/Filter.php b/src/Model/Filter.php index de9418f..8cede0b 100644 --- a/src/Model/Filter.php +++ b/src/Model/Filter.php @@ -1,4 +1,4 @@ - diff --git a/src/Model/FilterApplier/AggregateFilterApplier.php b/src/Model/FilterApplier/AggregateFilterApplier.php index 1b67262..c079392 100644 --- a/src/Model/FilterApplier/AggregateFilterApplier.php +++ b/src/Model/FilterApplier/AggregateFilterApplier.php @@ -1,4 +1,4 @@ - diff --git a/src/Model/FilterApplier/FilterApplierInterface.php b/src/Model/FilterApplier/FilterApplierInterface.php index bd1f49e..056cc14 100644 --- a/src/Model/FilterApplier/FilterApplierInterface.php +++ b/src/Model/FilterApplier/FilterApplierInterface.php @@ -1,4 +1,4 @@ - diff --git a/src/Model/FilterApplier/MagentoFilterApplier.php b/src/Model/FilterApplier/MagentoFilterApplier.php index a8b7dcf..6d6f691 100644 --- a/src/Model/FilterApplier/MagentoFilterApplier.php +++ b/src/Model/FilterApplier/MagentoFilterApplier.php @@ -1,4 +1,4 @@ - diff --git a/src/Model/FilterHider/FilterHiderInterface.php b/src/Model/FilterHider/FilterHiderInterface.php index 115a387..20c7427 100644 --- a/src/Model/FilterHider/FilterHiderInterface.php +++ b/src/Model/FilterHider/FilterHiderInterface.php @@ -1,4 +1,4 @@ - diff --git a/src/Model/LandingPage.php b/src/Model/LandingPage.php index 4989832..4f76ad9 100644 --- a/src/Model/LandingPage.php +++ b/src/Model/LandingPage.php @@ -1,4 +1,4 @@ -_getExtensionAttributes(); } @@ -131,7 +132,7 @@ public function setExtensionAttributes(LandingPageExtensionInterface $extensionA /** * Get name - * @return string|null + * @return string */ public function getName(): string { @@ -339,13 +340,13 @@ public function setFilterAttributes(?string $filterAttributes): LandingPageInter } /** - * @return mixed + * @return array * * phpcs:disable Magento2.Security.InsecureFunction.FoundWithAlternative */ public function getUnserializedFilterAttributes(): array { - if (null === $this->getFilterAttributes()) { + if ($this->getFilterAttributes() === null) { return []; } @@ -358,6 +359,7 @@ public function getUnserializedFilterAttributes(): array public function getFilters(): array { $unserializedFilters = $this->getUnserializedFilterAttributes(); + /** @phpstan-ignore-next-line */ if (!is_array($unserializedFilters)) { return []; } @@ -491,7 +493,7 @@ public function getOverviewPageId() } /** - * @param int|null $overviewPageId + * @param string|null $overviewPageId * @return LandingPageInterface */ public function setOverviewPageId(?string $overviewPageId): LandingPageInterface @@ -522,7 +524,7 @@ public function setOverviewPageImage(?string $overviewPageImage): LandingPageInt /** * @return bool - * @SuppressWarnings(PHPMD.BooleanGetMethodName) + * @SuppressWarnings("PHPMD.BooleanGetMethodName") */ public function getIsFilterLinkAllowed(): bool { @@ -540,7 +542,7 @@ public function setIsFilterLinkAllowed(bool $isFilterLinkAllowed = true): Landin /** * @return bool - * @SuppressWarnings(PHPMD.BooleanGetMethodName) + * @SuppressWarnings("PHPMD.BooleanGetMethodName") */ public function getHideSelectedFilters(): bool { diff --git a/src/Model/LandingPageContext.php b/src/Model/LandingPageContext.php index f69d0a7..63f53eb 100644 --- a/src/Model/LandingPageContext.php +++ b/src/Model/LandingPageContext.php @@ -1,4 +1,4 @@ - @@ -32,6 +32,7 @@ public function getLandingPage() /** * @param LandingPageInterface $page + * @return void */ public function setLandingPage(LandingPageInterface $page) { @@ -56,6 +57,7 @@ public function getOverviewPage() /** * @param OverviewPageInterface $overviewPage + * @return void */ public function setOverviewPage(OverviewPageInterface $overviewPage) { diff --git a/src/Model/LandingPageRepository.php b/src/Model/LandingPageRepository.php index a080cca..b72e899 100644 --- a/src/Model/LandingPageRepository.php +++ b/src/Model/LandingPageRepository.php @@ -1,4 +1,4 @@ - @@ -61,16 +61,6 @@ class LandingPageRepository implements LandingPageRepositoryInterface */ private $searchCriteriaBuilder; - /** - * @var StoreManagerInterface - */ - private StoreManagerInterface $storeManager; - - /** - * @var Options - */ - private Options $options; - /** * @param ResourcePage $resource * @param LandingPageInterfaceFactory $dataPageFactory @@ -90,8 +80,8 @@ public function __construct( CollectionProcessorInterface $collectionProcessor, JoinProcessorInterface $extensionAttributesJoinProcessor, SearchCriteriaBuilder $searchCriteriaBuilder, - StoreManagerInterface $storeManager, - Options $options + private StoreManagerInterface $storeManager, + private Options $options ) { $this->resource = $resource; $this->pageCollectionFactory = $pageCollectionFactory; @@ -100,8 +90,6 @@ public function __construct( $this->collectionProcessor = $collectionProcessor; $this->extensionAttributesJoinProcessor = $extensionAttributesJoinProcessor; $this->searchCriteriaBuilder = $searchCriteriaBuilder; - $this->storeManager = $storeManager; - $this->options = $options; } /** @@ -122,15 +110,19 @@ public function save(LandingPageInterface $page): LandingPageInterface } } - if (in_array($page->getData('category_id'), $rootCategories)) { - $page->setData('hide_selected_filters', "1"); + // phpcs:disable SlevomatCodingStandard.Functions.StrictCall.StrictParameterMissing + if (in_array($page->getData('category_id'), $rootCategories)) { // @phpstan-ignore-line + /** @phpstan-ignore-next-line */ + $page->setData('hide_selected_filters', '1'); } $parentLandingPage = $this->dataPageFactory->create(); + /** @phpstan-ignore-next-line */ $parentLandingPage->setData($page->getLandingPageDataWithoutStore()); /** @var LandingPage $page */ $this->resource->save($parentLandingPage); + /** @phpstan-ignore-next-line */ $page->setPageId($parentLandingPage->getPageId()); $this->resource->saveLandingPageStoreData($page); } catch (\Exception $exception) { @@ -176,14 +168,17 @@ public function getByIdWithStore(int $pageId, int $storeId): LandingPageInterfac if (!empty($storeData)) { unset($storeData['id']); + /** @phpstan-ignore-next-line */ $landingPage->setData($storeData); } else { $defaultData = $this->resource->getLandingPageStoreData($pageId, 0); if (!empty($defaultData)) { unset($defaultData['id']); + /** @phpstan-ignore-next-line */ $landingPage->setData($defaultData); } + /** @phpstan-ignore-next-line */ $landingPage->setData(LandingPageInterface::STORE_ID, $storeId); } @@ -201,6 +196,7 @@ public function getAllPagesById(int $pageId): array foreach ($storeData as $data) { $page = $this->dataPageFactory->create(); + /** @phpstan-ignore-next-line */ $page->setData($data); $pages[] = $page; } @@ -225,6 +221,7 @@ public function getList(SearchCriteriaInterface $criteria) $searchResults = $this->searchResultsFactory->create(); $searchResults->setSearchCriteria($criteria); + /** @phpstan-ignore-next-line */ $searchResults->setItems($collection->getItems()); $searchResults->setTotalCount($collection->getSize()); return $searchResults; diff --git a/src/Model/OverviewPage.php b/src/Model/OverviewPage.php index 247522c..45e4f1c 100644 --- a/src/Model/OverviewPage.php +++ b/src/Model/OverviewPage.php @@ -1,9 +1,8 @@ -loadedData)) { return $this->loadedData; } + /** @phpstan-ignore-next-line */ $items = $this->collection->getItems(); foreach ($items as $model) { /** @var OverviewPage $model */ @@ -67,14 +69,14 @@ public function getData() } $data = $this->dataPersistor->get('emico_attributelanding_overviewpage'); - + if (!empty($data)) { $model = $this->collection->getNewEmptyItem(); $model->setData($data); $this->loadedData[$model->getPageId()] = $model->getData(); $this->dataPersistor->clear('emico_attributelanding_overviewpage'); } - + return $this->loadedData; } } diff --git a/src/Model/OverviewPageRepository.php b/src/Model/OverviewPageRepository.php index 70cd105..2f557b2 100644 --- a/src/Model/OverviewPageRepository.php +++ b/src/Model/OverviewPageRepository.php @@ -1,4 +1,4 @@ -resource->save($page); + $this->resource->save($page); // @phpstan-ignore-line } catch (\Exception $exception) { throw new CouldNotSaveException( __( @@ -91,6 +91,7 @@ public function save(OverviewPageInterface $page): OverviewPageInterface ); } + /** @phpstan-ignore-next-line */ return $page; } @@ -108,6 +109,7 @@ public function getById(int $pageId): OverviewPageInterface throw new NoSuchEntityException(__('Page with id "%d" does not exist.', $pageId)); } + /** @phpstan-ignore-next-line */ return $page; } @@ -123,6 +125,7 @@ public function getList(SearchCriteriaInterface $criteria) $searchResults = $this->searchResultsFactory->create(); $searchResults->setSearchCriteria($criteria); + /** @phpstan-ignore-next-line */ $searchResults->setItems($collection->getItems()); $searchResults->setTotalCount($collection->getSize()); return $searchResults; @@ -137,7 +140,7 @@ public function delete(OverviewPageInterface $page): bool { try { /** @var LandingPage $page */ - $this->resource->delete($page); + $this->resource->delete($page); // @phpstan-ignore-line } catch (\Exception $exception) { throw new CouldNotDeleteException( __( @@ -169,6 +172,7 @@ public function findAllActive(): array ->create(); $result = $this->getList($searchCriteria); + /** @phpstan-ignore-next-line */ return $result->getItems(); } @@ -179,6 +183,7 @@ public function findAllActive(): array */ public function getByLandingPage(LandingPageInterface $landingPage): OverviewPageInterface { + /** @phpstan-ignore-next-line */ if ($landingPage->getOverviewPageId() === null) { throw new NoSuchEntityException(__('The landingpage does not have a overview page linked')); } diff --git a/src/Model/Page/DataProvider.php b/src/Model/Page/DataProvider.php index c87d631..256b0fb 100644 --- a/src/Model/Page/DataProvider.php +++ b/src/Model/Page/DataProvider.php @@ -1,4 +1,4 @@ - @@ -49,6 +49,7 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider * @param LandingPageRepository $landingPageRepository * @param array $meta * @param array $data + * @SuppressWarnings("PHPMD.ExcessiveParameterList") */ public function __construct( $name, @@ -84,6 +85,7 @@ public function getData() foreach ($items as $model) { $modelData = $model->getData(); + /** @phpstan-ignore-next-line */ $storeData = $this->landingPageRepository->getByIdWithStore($model->getPageId(), $storeId)->getData(); foreach ($storeData as $key => $value) { diff --git a/src/Model/Page/ImageUploader.php b/src/Model/Page/ImageUploader.php index 304b83b..eb165c9 100644 --- a/src/Model/Page/ImageUploader.php +++ b/src/Model/Page/ImageUploader.php @@ -1,4 +1,4 @@ - @@ -102,8 +102,8 @@ public function upload(): array */ public function getMediaUrl(string $filename, bool $relative = false): string { - /** @var Store $store */ try { + /** @var Store $store */ $store = $this->storeManager->getStore(); } catch (NoSuchEntityException $e) { $store = $this->storeManager->getDefaultStoreView(); @@ -113,6 +113,7 @@ public function getMediaUrl(string $filename, bool $relative = false): string return self::MEDIA_PATH_OVERVIEW . '/' . $filename; } + /** @phpstan-ignore-next-line */ return $store->getBaseUrl(UrlInterface::URL_TYPE_MEDIA) . self::MEDIA_PATH_OVERVIEW . '/' . $filename; } } diff --git a/src/Model/ResourceModel/OverviewPage.php b/src/Model/ResourceModel/OverviewPage.php index d68e0a7..c277072 100644 --- a/src/Model/ResourceModel/OverviewPage.php +++ b/src/Model/ResourceModel/OverviewPage.php @@ -1,4 +1,4 @@ - diff --git a/src/Model/ResourceModel/OverviewPage/Collection.php b/src/Model/ResourceModel/OverviewPage/Collection.php index 6a226b9..46465ba 100644 --- a/src/Model/ResourceModel/OverviewPage/Collection.php +++ b/src/Model/ResourceModel/OverviewPage/Collection.php @@ -1,4 +1,4 @@ - @@ -22,7 +22,7 @@ class Page extends AbstractDb * @param null $connectionName */ public function __construct( - private readonly Context $context, + Context $context, private readonly EventManager $eventManager, $connectionName = null ) { @@ -46,6 +46,7 @@ protected function _construct(): void public function getLandingPageStoreData(int $landingPageId, int $storeId = 0): array { $connection = $this->getConnection(); + /** @phpstan-ignore-next-line */ $select = $connection->select() ->from(['ps' => $this->getTable('emico_attributelanding_page_store')]) ->join( @@ -56,6 +57,7 @@ public function getLandingPageStoreData(int $landingPageId, int $storeId = 0): a ->where('ps.page_id = ?', $landingPageId) ->where('store_id = ?', $storeId); + /** @phpstan-ignore-next-line */ $result = $connection->fetchRow($select); if ($result) { @@ -74,12 +76,14 @@ public function getLandingPageStoreData(int $landingPageId, int $storeId = 0): a public function getAllLandingPageStoreData(int $pageId): array { $connection = $this->getConnection(); + /** @phpstan-ignore-next-line */ $select = $connection->select() ->from($this->getTable('emico_attributelanding_page_store')) ->where('page_id = :page_id'); $bind = ['page_id' => (int)$pageId]; + /** @phpstan-ignore-next-line */ return $connection->fetchAll($select, $bind); } @@ -89,6 +93,7 @@ public function getAllLandingPageStoreData(int $pageId): array */ public function saveLandingPageStoreData(LandingPageInterface $page): void { + /** @phpstan-ignore-next-line */ $data = $page->getLandingPageDataForStore(); $connection = $this->getConnection(); $table = $this->getTable('emico_attributelanding_page_store'); @@ -100,11 +105,13 @@ public function saveLandingPageStoreData(LandingPageInterface $page): void unset($data['id']); if (!empty($this->getLandingPageStoreData($page->getPageId(), $page->getStoreId()))) { + /** @phpstan-ignore-next-line */ $connection->update($table, $data, $where); } else { unset($data['id']); $data['page_id'] = $page->getPageId(); $data['store_id'] = $page->getStoreId(); + /** @phpstan-ignore-next-line */ $connection->insert($table, $data); } diff --git a/src/Model/ResourceModel/Page/Collection.php b/src/Model/ResourceModel/Page/Collection.php index 50d7ffc..df6a359 100644 --- a/src/Model/ResourceModel/Page/Collection.php +++ b/src/Model/ResourceModel/Page/Collection.php @@ -1,4 +1,4 @@ - @@ -59,9 +59,10 @@ public function getItems($storeId) $landingPages = $this->landingPageRepository->findAllActive(); foreach ($landingPages as $landingPage) { + /** @phpstan-ignore-next-line */ yield $this->itemFactory->create( [ - 'url' => $landingPage->getUrlRewriteRequestPath(), + 'url' => $landingPage->getUrlRewriteRequestPath(), // @phpstan-ignore-line 'updatedAt' => $landingPage->getUpdatedAt(), 'priority' => $this->configReader->getPriority($storeId), 'changeFrequency' => $this->configReader->getChangeFrequency($storeId), diff --git a/src/Model/System/Config/AppendUrlSuffix.php b/src/Model/System/Config/AppendUrlSuffix.php index 6883324..f1cede3 100644 --- a/src/Model/System/Config/AppendUrlSuffix.php +++ b/src/Model/System/Config/AppendUrlSuffix.php @@ -1,4 +1,4 @@ - @@ -84,15 +84,16 @@ public function findUrlByFilters(array $filters, ?int $categoryId = null) $this->landingPageLookup = $this->loadPageLookupArray(); } + /** @phpstan-ignore-next-line */ $storePrefix = $this->storeManager->getStore()->getBaseUrl(); if (!isset($this->landingPageLookup[$this->storeManager->getStore()->getId()][$filterHash])) { //check if hash is set for all stores - if (isset($this->landingPageLookup[0][$filterHash])) { - $result = $this->landingPageLookup[0][$filterHash]; - } else { + if (!isset($this->landingPageLookup[0][$filterHash])) { return null; } + + $result = $this->landingPageLookup[0][$filterHash]; } if (empty($result)) { @@ -137,7 +138,8 @@ function (FilterInterface $filter) { protected function loadPageLookupArray(): array { $landingPageLookup = $this->cache->load(self::CACHE_KEY); - if ($landingPageLookup !== false) { + if ($landingPageLookup) { + /** @phpstan-ignore-next-line */ return $this->serializer->unserialize($landingPageLookup); } @@ -147,10 +149,11 @@ protected function loadPageLookupArray(): array ->create(); $landingPageLookup = []; - $landingPageStores = []; foreach ($this->landingPageRepository->getList($searchCriteria)->getItems() as $landingPage) { $hash = $this->createHashForFilters($landingPage->getFilters(), $landingPage->getCategoryId()); + /** @phpstan-ignore-next-line */ $storeId = $landingPage->getData('store_id'); + /** @phpstan-ignore-next-line */ $landingPageLookup[$storeId][$hash] = $landingPage->getUrlRewriteRequestPath(); } diff --git a/src/Model/UrlRewriteService.php b/src/Model/UrlRewriteService.php index e1b1d33..9e738a1 100644 --- a/src/Model/UrlRewriteService.php +++ b/src/Model/UrlRewriteService.php @@ -1,4 +1,4 @@ -landingPageRepository->getList($searchCriteria); foreach ($landingPages->getItems() as $page) { + /** @phpstan-ignore-next-line */ $this->generateRewrite($page, $newSuffix); } } @@ -108,6 +110,7 @@ static function (UrlRewrite $rewrite) { /** * @param UrlRewriteGeneratorInterface $page * @param string|null $suffix + * @return void * @throws \Magento\UrlRewrite\Model\Exception\UrlAlreadyExistsException|\Exception */ public function generateRewrite(UrlRewriteGeneratorInterface $page, ?string $suffix = null) @@ -115,9 +118,9 @@ public function generateRewrite(UrlRewriteGeneratorInterface $page, ?string $suf $this->removeExistingUrlRewrites($page); $urlRewritesToPersist = []; - if ($page->getUrlRewriteEntityType() == 'landingpage') { + if ($page->getUrlRewriteEntityType() === 'landingpage') { $urlRewritesToPersist = $this->generateLandingPageRewrites($page, $suffix); - } elseif ($page->getUrlRewriteEntityType() == 'landingpage_overview') { + } elseif ($page->getUrlRewriteEntityType() === 'landingpage_overview') { $urlRewritesToPersist = $this->generateOverviewPageRewrites($page, $suffix); } @@ -132,17 +135,19 @@ public function generateRewrite(UrlRewriteGeneratorInterface $page, ?string $suf private function generateLandingPageRewrites(UrlRewriteGeneratorInterface $page, ?string $suffix = null): array { $urlRewritesToPersist = []; + /** @phpstan-ignore-next-line */ $allPages = $this->landingPageRepository->getAllPagesById($page->getPageId()); foreach ($allPages as $storePage) { - if ($storePage->getStoreId() == $page->getStoreId()) { + /** @phpstan-ignore-next-line */ + if ($storePage->getStoreId() === $page->getStoreId()) { $storePage = $page; } - if ($storePage->getStoreId() == 0) { + if ($storePage->getStoreId() === 0) { $urlRewritesToPersist = $this->generateRewritesForAllStores( $storePage, - $page, + $page, // @phpstan-ignore-line $suffix, $urlRewritesToPersist ); @@ -171,18 +176,22 @@ private function generateRewritesForAllStores( $stores = $this->storeManager->getStores(); foreach ($stores as $store) { - if ($store->getId() == $page->getStoreId()) { + if ($store->getId() === $page->getStoreId()) { $storePage = $page; } + /** @phpstan-ignore-next-line */ if (empty($storePage)) { continue; } - if (!isset($urlRewritesToPersist[$store->getId()])) { - $urlRewrite = $this->createUrlRewrite($storePage, $store->getId(), $suffix); - $urlRewritesToPersist[$store->getId()] = $urlRewrite; + if (isset($urlRewritesToPersist[$store->getId()])) { + continue; } + + /** @phpstan-ignore-next-line */ + $urlRewrite = $this->createUrlRewrite($storePage, $store->getId(), $suffix); + $urlRewritesToPersist[$store->getId()] = $urlRewrite; } return $urlRewritesToPersist; @@ -231,9 +240,9 @@ private function createUrlRewrite( ->setTargetPath($page->getUrlRewriteTargetPath()) ->setStoreId($storeId); - $requestPath = ($suffix === null) + $requestPath = $suffix === null ? $page->getUrlRewriteRequestPath() - : $page->getUrlPath() . $suffix; + : $page->getUrlPath() . $suffix; // @phpstan-ignore-line $requestPath = trim($requestPath, '/'); @@ -244,7 +253,8 @@ private function createUrlRewrite( protected function getActiveStoreIds(UrlRewriteGeneratorInterface $landingPage): array { - if (\in_array('0', $landingPage->getStoreIds(), false) !== false) { + // phpcs:disable SlevomatCodingStandard.Functions.StrictCall.NonStrictComparison + if (\in_array('0', $landingPage->getStoreIds(), false) !== false) { // @phpstan-ignore-line return array_map( static function (StoreInterface $store) { return $store->getId(); @@ -253,6 +263,7 @@ static function (StoreInterface $store) { ); } + /** @phpstan-ignore-next-line */ return $landingPage->getStoreIds(); } } diff --git a/src/Observer/CategoryUrlSuffixObserver.php b/src/Observer/CategoryUrlSuffixObserver.php index 2edbd63..ba2eae7 100644 --- a/src/Observer/CategoryUrlSuffixObserver.php +++ b/src/Observer/CategoryUrlSuffixObserver.php @@ -1,4 +1,4 @@ - diff --git a/src/Observer/SeoObserver.php b/src/Observer/SeoObserver.php index 6417182..302badc 100644 --- a/src/Observer/SeoObserver.php +++ b/src/Observer/SeoObserver.php @@ -1,4 +1,4 @@ - @@ -8,7 +8,6 @@ namespace Emico\AttributeLanding\Observer; use Emico\AttributeLanding\Api\Data\LandingPageInterface; -use Emico\AttributeLanding\Controller\Page\ViewContext; use Emico\AttributeLanding\Model\LandingPageContext; use Magento\Catalog\Api\CategoryRepositoryInterface; use Magento\Catalog\Block\Category\View as LandingPageView; @@ -23,16 +22,6 @@ class SeoObserver implements ObserverInterface { - /** - * @var PageConfig $pageConfig - */ - private PageConfig $pageConfig; - - /** - * @var Config $config - */ - private Config $config; - /** * @var LandingPageContext */ @@ -48,11 +37,6 @@ class SeoObserver implements ObserverInterface */ private $storeManager; - /** - * @var MagentoHttpRequest $request - */ - protected MagentoHttpRequest $request; - /** * MetaTagsObserver constructor. * @param PageConfig $pageConfig @@ -62,19 +46,16 @@ class SeoObserver implements ObserverInterface * @param StoreManagerInterface $storeManager */ public function __construct( - PageConfig $pageConfig, - Config $config, + private PageConfig $pageConfig, + private Config $config, LandingPageContext $landingPageContext, CategoryRepositoryInterface $categoryRepository, StoreManagerInterFace $storeManager, - MagentoHttpRequest $request + protected MagentoHttpRequest $request ) { - $this->pageConfig = $pageConfig; - $this->config = $config; $this->landingPageContext = $landingPageContext; $this->categoryRepository = $categoryRepository; $this->storeManager = $storeManager; - $this->request = $request; } /** @@ -90,8 +71,10 @@ public function execute(Observer $observer) } $page = $this->landingPageContext->getLandingPage(); + /** @phpstan-ignore-next-line */ if (!$page) { $page = $this->landingPageContext->getOverviewPage(); + /** @phpstan-ignore-next-line */ if (!$page) { return; } @@ -103,18 +86,23 @@ public function execute(Observer $observer) /** @var Title $pageMainTitle */ $pageMainTitle = $block->getLayout()->getBlock('page.main.title'); + /** @phpstan-ignore-next-line */ if ($pageMainTitle) { $pageMainTitle->setPageTitle($page->getHeading()); } - if ($page instanceof LandingPageInterface) { - $this->clearCurrentCanonical($page); - $this->setLandingPageCanonicalUrl($page); + /** @phpstan-ignore-next-line */ + if (!($page instanceof LandingPageInterface)) { + return; } + + $this->clearCurrentCanonical($page); + $this->setLandingPageCanonicalUrl($page); } /** * @param LandingPageInterface $landingPage + * @return void */ protected function setLandingPageCanonicalUrl(LandingPageInterface $landingPage) { @@ -144,9 +132,11 @@ protected function getCanonicalUrl(LandingPageInterface $landingPage) $params['_escape'] = false; $params['query'] = $this->request->getQuery(); + /** @phpstan-ignore-next-line */ return $this->storeManager->getStore()->getUrl($landingPage->getUrlPath(), $params); } + /** @phpstan-ignore-next-line */ return $this->storeManager->getStore()->getUrl('', ['_direct' => $landingPage->getUrlPath()]); } @@ -154,6 +144,7 @@ protected function getCanonicalUrl(LandingPageInterface $landingPage) * Clear * * @param LandingPageInterface $landingPage + * @return void * @throws \Magento\Framework\Exception\NoSuchEntityException */ protected function clearCurrentCanonical(LandingPageInterface $landingPage) @@ -163,6 +154,7 @@ protected function clearCurrentCanonical(LandingPageInterface $landingPage) } $category = $this->categoryRepository->get($landingPage->getCategoryId()); + /** @phpstan-ignore-next-line */ $this->pageConfig->getAssetCollection()->remove($category->getUrl()); } } diff --git a/src/Observer/UrlRewriteGenerateObserver.php b/src/Observer/UrlRewriteGenerateObserver.php index a2ef30a..ab0fed9 100644 --- a/src/Observer/UrlRewriteGenerateObserver.php +++ b/src/Observer/UrlRewriteGenerateObserver.php @@ -1,4 +1,4 @@ - diff --git a/src/Observer/UrlRewriteRemoveObserver.php b/src/Observer/UrlRewriteRemoveObserver.php index 0b600d2..076cfc9 100644 --- a/src/Observer/UrlRewriteRemoveObserver.php +++ b/src/Observer/UrlRewriteRemoveObserver.php @@ -1,4 +1,4 @@ - @@ -7,7 +7,6 @@ namespace Emico\AttributeLanding\Observer; -use Emico\AttributeLanding\Api\Data\LandingPageInterface; use Emico\AttributeLanding\Api\UrlRewriteGeneratorInterface; use Magento\Framework\Event\Observer; use Magento\Framework\Event\ObserverInterface; @@ -37,6 +36,7 @@ public function __construct(UrlPersistInterface $urlPersist) public function execute(Observer $observer) { $page = $observer->getEvent()->getData('object'); + /** @phpstan-ignore-next-line */ if (!$page instanceof UrlRewriteGeneratorInterface || !$page->getPageId()) { return; } diff --git a/src/Plugin/Model/SitemapPlugin.php b/src/Plugin/Model/SitemapPlugin.php index 04f836d..2add099 100644 --- a/src/Plugin/Model/SitemapPlugin.php +++ b/src/Plugin/Model/SitemapPlugin.php @@ -1,4 +1,4 @@ - @@ -41,6 +41,7 @@ public function __construct( * Add landingpages to sitemap * * @param Sitemap $subject + * @return void */ public function afterCollectSitemapItems(Sitemap $subject) { diff --git a/src/Setup/Patch/Data/ConvertLandingpageEntries.php b/src/Setup/Patch/Data/ConvertLandingpageEntries.php index 9d4f0df..7ff5492 100644 --- a/src/Setup/Patch/Data/ConvertLandingpageEntries.php +++ b/src/Setup/Patch/Data/ConvertLandingpageEntries.php @@ -1,11 +1,10 @@ -moduleDataSetup->startSetup(); $connection = $this->moduleDataSetup->getConnection(); $landingPageTable = $this->moduleDataSetup->getTable('emico_attributelanding_page'); $landingPageStoreTable = $this->moduleDataSetup->getTable('emico_attributelanding_page_store'); - $stores = $this->storeManager->getStores(); $select = $connection->select()->from($landingPageTable); $landingPages = $connection->fetchAll($select); @@ -39,11 +35,14 @@ public function apply(): void foreach ($landingPages as $landingPage) { $storeIds = explode(',', $landingPage['store_ids']); foreach ($storeIds as $storeId) { + /** @phpstan-ignore-next-line */ $this->insertLandingPageStore($connection, $landingPageStoreTable, $landingPage, $storeId); } } $this->moduleDataSetup->endSetup(); + + return $this; } /** @@ -84,9 +83,11 @@ private function insertLandingPageStore( ]; foreach ($fields as $field) { - if (isset($landingPage[$field])) { - $data[$field] = $landingPage[$field]; + if (!isset($landingPage[$field])) { + continue; } + + $data[$field] = $landingPage[$field]; } $connection->insert($table, $data); diff --git a/src/Ui/Component/Listing/Column/OverviewPageActions.php b/src/Ui/Component/Listing/Column/OverviewPageActions.php index 5e74953..f42efc1 100644 --- a/src/Ui/Component/Listing/Column/OverviewPageActions.php +++ b/src/Ui/Component/Listing/Column/OverviewPageActions.php @@ -1,4 +1,4 @@ -urlBuilder = $urlBuilder; - $this->storeRepository = $storeRepository; parent::__construct($context, $uiComponentFactory, $components, $data); } @@ -46,11 +44,12 @@ public function __construct( * @return array * * phpcs:disable Generic.Metrics.NestingLevel.TooHigh - * @SuppressWarnings(PHPMD.CyclomaticComplexity) + * @SuppressWarnings("PHPMD.CyclomaticComplexity") */ public function prepareDataSource(array $dataSource) { if (isset($dataSource['data']['items'])) { + // phpcs:ignore SlevomatCodingStandard.PHP.DisallowReference.DisallowedAssigningByReference foreach ($dataSource['data']['items'] as & $item) { if (isset($item['page_id'])) { $item[$this->getData('name')] = [ @@ -81,17 +80,23 @@ public function prepareDataSource(array $dataSource) if (!empty($item['store_ids']) && is_string($item['store_ids'])) { $store_ids = explode(',', $item['store_ids']); + /** @phpstan-ignore-next-line */ if (!empty($store_ids) && is_array($store_ids)) { $stores = $this->storeRepository->getList(); $item['stores'] = ''; foreach ($stores as $store) { $id = $store->getId(); - if (in_array($id, $store_ids)) { - if ($id === "0") { - $item['stores'] .= 'All Store Views' . ', '; - } else { - $item['stores'] .= $store->getName() . ', '; - } + + // phpcs:ignore SlevomatCodingStandard.Functions.StrictCall.StrictParameterMissing + if (!in_array($id, $store_ids)) { + continue; + } + + /** @phpstan-ignore-next-line */ + if ($id === '0') { + $item['stores'] .= 'All Store Views' . ', '; + } else { + $item['stores'] .= $store->getName() . ', '; } } } diff --git a/src/Ui/Component/Listing/Column/PageActions.php b/src/Ui/Component/Listing/Column/PageActions.php index 64db874..bc2bff7 100644 --- a/src/Ui/Component/Listing/Column/PageActions.php +++ b/src/Ui/Component/Listing/Column/PageActions.php @@ -1,4 +1,4 @@ -storeRepository = $storeRepository; $this->categoryRepository = $categoryRepository; $this->urlBuilder = $urlBuilder; @@ -61,7 +55,9 @@ public function __construct( * @throws NoSuchEntityException * * phpcs:disable Generic.Metrics.NestingLevel.TooHigh - * @SuppressWarnings(PHPMD.CyclomaticComplexity) + * phpcs:disable SlevomatCodingStandard.PHP.DisallowReference.DisallowedAssigningByReference + * phpcs:disable SlevomatCodingStandard.Functions.StrictCall.StrictParameterMissing + * @SuppressWarnings("PHPMD.CyclomaticComplexity") */ public function prepareDataSource(array $dataSource) { @@ -111,17 +107,21 @@ public function prepareDataSource(array $dataSource) if (!empty($item['store_ids']) && is_string($item['store_ids'])) { $store_ids = explode(',', $item['store_ids']); + /** @phpstan-ignore-next-line */ if (!empty($store_ids) && is_array($store_ids)) { $stores = $this->storeRepository->getList(); $item['stores'] = ''; foreach ($stores as $store) { $id = $store->getId(); - if (in_array($id, $store_ids)) { - if ($id === "0") { - $item['stores'] .= 'All Store Views' . ', '; - } else { - $item['stores'] .= $store->getName() . ', '; - } + if (!in_array($id, $store_ids)) { + continue; + } + + /** @phpstan-ignore-next-line */ + if ($id === '0') { + $item['stores'] .= 'All Store Views' . ', '; + } else { + $item['stores'] .= $store->getName() . ', '; } } } diff --git a/src/Ui/Component/Product/Form/Categories/Options.php b/src/Ui/Component/Product/Form/Categories/Options.php index 6e752e2..1e83278 100644 --- a/src/Ui/Component/Product/Form/Categories/Options.php +++ b/src/Ui/Component/Product/Form/Categories/Options.php @@ -1,11 +1,10 @@ -