diff --git a/.github/workflows/grumphp.yaml b/.github/workflows/grumphp.yaml index a156f31..af31d25 100644 --- a/.github/workflows/grumphp.yaml +++ b/.github/workflows/grumphp.yaml @@ -16,7 +16,8 @@ jobs: - 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 2462e66..de7710c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ /.idea /vendor /composer.lock +/auth.json /build/local.env -/build/data \ No newline at end of file +/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 3ed3465..27957cf 100644 --- a/composer.json +++ b/composer.json @@ -12,11 +12,7 @@ }, "require-dev": { "magento/framework": "*", - "phpro/grumphp-shim": "^2.7", - "squizlabs/php_codesniffer": "^3.10", - "phpmd/phpmd": "^2.15", - "slevomat/coding-standard": "^8.15", - "magento-ecg/coding-standard": "^4.5" + "emico/code-quality": "^10.5" }, "autoload": { "files": [ @@ -26,17 +22,26 @@ "Tweakwise\\TweakwiseJs\\": "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": { "allow-plugins": { - "phpro/grumphp-shim": true, "magento/composer-dependency-version-audit-plugin": false, - "dealerdirect/phpcodesniffer-composer-installer": true + "dealerdirect/phpcodesniffer-composer-installer": true, + "phpstan/extension-installer": true, + "emico/code-quality": true, + "phpro/grumphp": true + }, + "preferred-install": { + "emico/code-quality": "dist" } } } diff --git a/grumphp.yml b/grumphp.yml index cc7b1f7..97c0909 100644 --- a/grumphp.yml +++ b/grumphp.yml @@ -1,11 +1,140 @@ grumphp: - tasks: - xmllint: - triggered_by: ['xml', 'xsd'] - scheme_validation: true - x_include: true - dtd_validation: true - phpcs: ~ - phpmd: - ruleset: - - "ruleset.xml" + process_timeout: 360 + extensions: + - Emico\CodeQuality\GrumPHP\Extension + parallel: + enabled: false + tasks: + phpstan: + triggered_by: + - php + level: 7 + ignore_patterns: + - "vendor" + - "generated" + - "setup" + - "update" + - "dev" + - "tests" + - "public" + - "backend/vendor" + - "backend/generated" + - "backend/setup" + - "backend/update" + - "backend/tests" + - "backend/dev" + - "deploy.php" + - "deploy" + - "magento/vendor" + - "magento/generated" + - "magento/setup" + - "magento/update" + - "magento/tests/_support/_generated" + - "magento/dev" + - "LocalValetDriver.php" + configuration: phpstan.neon + phpmd: + triggered_by: + - php + ruleset: + - "ruleset.xml" + exclude: + - "vendor" + - "generated" + - "setup" + - "update" + - "dev" + - "public" + - "deploy" + - "tests/_support/_generated" + - "app/etc/config.php" + - "backend/vendor" + - "backend/generated" + - "backend/setup" + - "backend/update" + - "backend/update" + - "backend/dev" + - "backend/tests/_support/_generated" + - "backend/app/etc/config.php" + - "magento/app/etc/config.php" + - "magento/vendor" + - "magento/generated" + - "magento/setup" + - "magento/update" + - "magento/tests/_support/_generated" + - "magento/dev" + phpcs: + triggered_by: + - php + ignore_patterns: + - "vendor" + - "generated" + - "setup" + - "update" + - "dev" + - "public" + - "deploy" + - "tests/_support/_generated" + - "app/etc/config.php" + - "backend/vendor" + - "backend/generated" + - "backend/setup" + - "backend/update" + - "backend/dev" + - "backend/tests/_support/_generated" + - "backend/app/etc/config.php" + - "magento/app/etc/config.php" + - "magento/vendor" + - "magento/generated" + - "magento/setup" + - "magento/update" + - "magento/tests/_support/_generated" + - "magento/dev" + + xmllint: + triggered_by: [ 'xml', 'xsd' ] + scheme_validation: true + x_include: true + dtd_validation: true + load_from_net: true + + phplint: + short_open_tag: true + ignore_patterns: + - "vendor" + - "generated" + - "setup" + - "update" + - "dev" + - "public" + - "deploy" + - "tests/_support/_generated" + - "app/etc/config.php" + - "backend/vendor" + - "backend/generated" + - "backend/setup" + - "backend/update" + - "backend/dev" + - "backend/tests/_support/_generated" + - "backend/app/etc/config.php" + - "magento/app/etc/config.php" + - "magento/vendor" + - "magento/generated" + - "magento/setup" + - "magento/update" + - "magento/tests/_support/_generated" + - "magento/dev" + + composer: + no_check_publish: true + with_dependencies: false + strict: false + + git_commit_message: + allow_empty_message: false + enforce_capitalized_subject: false + enforce_no_subject_punctuations: false + enforce_no_subject_trailing_period: false + enforce_single_lined_subject: true + max_body_width: 100 + max_subject_width: 100 diff --git a/phpcs.xml b/phpcs.xml deleted file mode 100644 index a4c8229..0000000 --- a/phpcs.xml +++ /dev/null @@ -1,106 +0,0 @@ - - - Tweakwise coding standard ruleset for PHP. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - error - - - - - - - - - - - - - - - - - - - *.phtml - - - - - - - - - - - - - *.phtml - - - - - - - - - - - - - - - - - - - - - */tests/* - - 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/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..10cdaf9 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,28 @@ +services: + - class: Emico\CodeQuality\PHPStan\VarModelExtension + tags: + - phpstan.broker.methodsClassReflectionExtension + +parameters: + 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 deleted file mode 100644 index 84cda59..0000000 --- a/ruleset.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - Tweakwise Code Check Rules - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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/Block/Adminhtml/System/Config/Version.php b/src/Block/Adminhtml/System/Config/Version.php index be94647..9fdb267 100644 --- a/src/Block/Adminhtml/System/Config/Version.php +++ b/src/Block/Adminhtml/System/Config/Version.php @@ -28,7 +28,7 @@ public function __construct( * @param AbstractElement $element * @return string * phpcs:disable PSR2.Methods.MethodDeclaration.Underscore - * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass */ protected function _getElementHtml(AbstractElement $element): string { diff --git a/src/Controller/Adminhtml/Ajax/FacetAttributes.php b/src/Controller/Adminhtml/Ajax/FacetAttributes.php index 0988883..ecda089 100644 --- a/src/Controller/Adminhtml/Ajax/FacetAttributes.php +++ b/src/Controller/Adminhtml/Ajax/FacetAttributes.php @@ -75,6 +75,7 @@ public function execute() /** @var FacetAttributeResponseInterface $response */ $response = $this->client->request($facetAttributeRequest); + // @phpstan-ignore-next-line if (!$response) { return $result->setData([$otherAttributeOption]); } diff --git a/src/Model/Api/Client.php b/src/Model/Api/Client.php index 788dc13..38402ac 100644 --- a/src/Model/Api/Client.php +++ b/src/Model/Api/Client.php @@ -45,7 +45,7 @@ public function getFeatures(Request $request): array { $cachedFeatures = $this->cache->load(self::FEATURES_CACHE_KEY); if ($cachedFeatures) { - return $this->jsonSerializer->unserialize($cachedFeatures); + return (array)$this->jsonSerializer->unserialize($cachedFeatures); } $instanceKey = $this->config->getInstanceKey(); @@ -131,6 +131,7 @@ private function doRequest(Request $request): Response sprintf( 'Invalid response received by Tweakwise server, xml load fails. Request "%s", XML Errors: %s', $url, + // @phpstan-ignore-next-line implode(PHP_EOL, $errors) ) ); diff --git a/src/Model/Api/Request.php b/src/Model/Api/Request.php index 7c89dc1..b1e84bd 100644 --- a/src/Model/Api/Request.php +++ b/src/Model/Api/Request.php @@ -26,7 +26,6 @@ public function __construct( */ protected array $parameters = []; - /** * @return string */ diff --git a/src/Model/Config/Source/SearchType.php b/src/Model/Config/Source/SearchType.php index 7385cb7..7c2bfb2 100644 --- a/src/Model/Config/Source/SearchType.php +++ b/src/Model/Config/Source/SearchType.php @@ -46,6 +46,7 @@ public function toOptionArray(): array protected function isSuggestionsFeatureEnabled(): bool { $featureRequest = $this->requestFactory->create(); + // @phpstan-ignore-next-line return (bool)$this->apiClient->getFeatures($featureRequest)[Feature::SUGGESTIONS->value] ?? false; } } diff --git a/src/Model/Config/Source/Template.php b/src/Model/Config/Source/Template.php index 43464ec..7c364ab 100644 --- a/src/Model/Config/Source/Template.php +++ b/src/Model/Config/Source/Template.php @@ -39,6 +39,7 @@ protected function buildOptions(): array ['value' => null, 'label' => __('* Default template')], ]; + // @phpstan-ignore-next-line if (!is_array($response->getTemplates())) { return $result; } diff --git a/src/Model/Config/Source/Yesno.php b/src/Model/Config/Source/Yesno.php index 4165496..0ca78ae 100644 --- a/src/Model/Config/Source/Yesno.php +++ b/src/Model/Config/Source/Yesno.php @@ -39,6 +39,7 @@ public function toOptionArray(): array protected function isNavigationFeatureEnabled(): bool { $featureRequest = $this->requestFactory->create(); + // @phpstan-ignore-next-line return (bool)$this->apiClient->getFeatures($featureRequest)[Feature::NAVIGATION->value] ?? false; } } diff --git a/src/Observer/AddPageAssets.php b/src/Observer/AddPageAssets.php index 63e7f5d..904ebd3 100644 --- a/src/Observer/AddPageAssets.php +++ b/src/Observer/AddPageAssets.php @@ -25,7 +25,7 @@ public function __construct( /** * @param Observer $observer * @return void - * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterface */ public function execute(Observer $observer): void { diff --git a/src/Observer/ManageLayoutBlocks.php b/src/Observer/ManageLayoutBlocks.php index 2e70af2..9a71e6a 100644 --- a/src/Observer/ManageLayoutBlocks.php +++ b/src/Observer/ManageLayoutBlocks.php @@ -78,7 +78,7 @@ private function shouldShowTweakwiseJsCategoryViewBlock(): bool } $currentCategory = $this->layerResolver->get()->getCurrentCategory(); - if (!$currentCategory) { + if (!$currentCategory->getId()) { return false; } diff --git a/src/Plugin/Model/Autocomplete.php b/src/Plugin/Model/Autocomplete.php index 5dfba32..0a9d51f 100644 --- a/src/Plugin/Model/Autocomplete.php +++ b/src/Plugin/Model/Autocomplete.php @@ -23,7 +23,6 @@ public function __construct( * @param Subject $subject * @param array $result * @return array - * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function afterGetItems(Subject $subject, array $result): array { diff --git a/src/Plugin/Model/Page/DataProvider.php b/src/Plugin/Model/Page/DataProvider.php index c383429..d12e1ad 100644 --- a/src/Plugin/Model/Page/DataProvider.php +++ b/src/Plugin/Model/Page/DataProvider.php @@ -24,7 +24,6 @@ public function __construct( * @param Subject $subject * @param array $result * @return array - * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function afterGetConfigData(Subject $subject, array $result): array { diff --git a/src/ViewModel/AttributeLanding.php b/src/ViewModel/AttributeLanding.php index 01629d8..3818fa4 100644 --- a/src/ViewModel/AttributeLanding.php +++ b/src/ViewModel/AttributeLanding.php @@ -55,6 +55,7 @@ protected function getFilterAttributes(string $filterAttributesSerialized, bool { $filterAttributes = $this->serializer->unserialize($filterAttributesSerialized); $filters = []; + // @phpstan-ignore-next-line foreach ($filterAttributes as $filterAttribute) { $filters[$this->getAttribute($filterAttribute, $addPrefix)] = $this->getValue($filterAttribute); } diff --git a/src/ViewModel/Search.php b/src/ViewModel/Search.php index 880813e..07b3a09 100644 --- a/src/ViewModel/Search.php +++ b/src/ViewModel/Search.php @@ -7,6 +7,7 @@ use Magento\Framework\App\Request\Http; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\UrlInterface; +use Magento\Store\Model\Store; use Magento\Store\Model\StoreManagerInterface; use Tweakwise\TweakwiseJs\Helper\Data; use Tweakwise\TweakwiseJs\Model\Config; @@ -45,8 +46,10 @@ public function getSearchType(): SearchType public function getStoreRootCategory(): int { try { + /** @var Store $store */ + $store = $this->storeManager->getStore(); return (int)$this->dataHelper->getTweakwiseId( - (int)$this->storeManager->getStore()->getRootCategoryId() + (int)$store->getRootCategoryId() ); } catch (NoSuchEntityException $e) { return 0;