From 174cad27142568585c65c3ca3c8ba10eba514ca7 Mon Sep 17 00:00:00 2001 From: Pim Ruiter Date: Fri, 2 Feb 2024 11:46:55 +0100 Subject: [PATCH 1/2] Fix Warning: Undefined array key when setting required attributes active (#39) --- Helper/Import/Product.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Helper/Import/Product.php b/Helper/Import/Product.php index dddd6cd..50968e0 100644 --- a/Helper/Import/Product.php +++ b/Helper/Import/Product.php @@ -12,7 +12,7 @@ protected function getColumnsFromResult(array $result, array $keys = []): array // This returns the result for the temp table DB columns. ex: 'name-nl_NL-ecommerce' => 'value' $mappedResult = parent::getColumnsFromResult($result, $keys); - if (!$this->scopeConfig->getValue('akeneo_connector/justbetter/defaultstorevalues')) { + if (!$this->scopeConfig->getValue('akeneo_connector/justbetter/defaultstorevalues') || !array_key_exists('values', $result)) { return $mappedResult; } From ef3966d3982828e679fd0c5af1904381ea4202fe Mon Sep 17 00:00:00 2001 From: Frits de Vries <110908371+fritsjustbetter@users.noreply.github.com> Date: Tue, 20 Feb 2024 13:53:17 +0100 Subject: [PATCH 2/2] Feature/phpstan (#40) * Fix Warning: Undefined array key when setting required attributes active * added phpstan to akeneo bundle --------- Co-authored-by: Pim Ruiter --- .github/workflows/analyse.yml | 25 +++++++++++++++++++ .gitignore | 2 ++ Block/Adminhtml/Akeneo.php | 1 - Block/Adminhtml/Akeneo/Grid.php | 3 ++- .../System/Config/Form/Field/TaxIdMapping.php | 2 -- Console/Command/SlackNotificationCommand.php | 2 ++ Controller/Adminhtml/akeneo/NewAction.php | 4 +-- Helper/Import/Product.php | 2 +- Plugin/CheckWebsiteAssociation.php | 5 ++-- Plugin/SetTaxClassId.php | 14 +++++------ Plugin/SetTierPrices.php | 1 + composer.json | 16 ++++++++++++ phpstan.neon | 12 +++++++++ 13 files changed, 71 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/analyse.yml create mode 100644 .gitignore create mode 100644 phpstan.neon diff --git a/.github/workflows/analyse.yml b/.github/workflows/analyse.yml new file mode 100644 index 0000000..c687e18 --- /dev/null +++ b/.github/workflows/analyse.yml @@ -0,0 +1,25 @@ +name: PHPStan + +on: ['push', 'pull_request'] + +jobs: + test: + runs-on: ubuntu-latest + name: analyse + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.2 + extensions: dom, curl, libxml, mbstring, zip, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo + coverage: none + + - name: Install dependencies + run: composer install --no-interaction + + - name: Analyse + run: vendor/bin/phpstan analyse \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..88e99d5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +vendor +composer.lock \ No newline at end of file diff --git a/Block/Adminhtml/Akeneo.php b/Block/Adminhtml/Akeneo.php index 9de9274..67aba79 100755 --- a/Block/Adminhtml/Akeneo.php +++ b/Block/Adminhtml/Akeneo.php @@ -59,7 +59,6 @@ protected function _getAddButtonOptions() } /** - * @param string $type * @return string */ protected function _getCreateUrl() diff --git a/Block/Adminhtml/Akeneo/Grid.php b/Block/Adminhtml/Akeneo/Grid.php index f1fb42c..5304a9f 100755 --- a/Block/Adminhtml/Akeneo/Grid.php +++ b/Block/Adminhtml/Akeneo/Grid.php @@ -69,6 +69,7 @@ protected function _construct() */ protected function _prepareCollection() { + /* @phpstan-ignore-next-line */ $collection = $this->_akeneoFactory->create()->getCollection(); $this->setCollection($collection); @@ -191,7 +192,7 @@ public function getGridUrl() } /** - * @param \JustBetter\AkeneoBundle\Model\akeneo|\Magento\Framework\Object $row + * @param \JustBetter\AkeneoBundle\Model\Akeneo|\Magento\Framework\Object $row * @return string */ public function getRowUrl($row) diff --git a/Block/Adminhtml/System/Config/Form/Field/TaxIdMapping.php b/Block/Adminhtml/System/Config/Form/Field/TaxIdMapping.php index 5c55a52..93b2993 100644 --- a/Block/Adminhtml/System/Config/Form/Field/TaxIdMapping.php +++ b/Block/Adminhtml/System/Config/Form/Field/TaxIdMapping.php @@ -41,14 +41,12 @@ public function __construct( Context $context, Factory $elementFactory, Product $productTaxClassSource, - Config $eavConfig, array $data = [] ) { parent::__construct($context, $data); $this->elementFactory = $elementFactory; $this->productTaxClassSource = $productTaxClassSource; - $this->eavConfig = $eavConfig; } /** diff --git a/Console/Command/SlackNotificationCommand.php b/Console/Command/SlackNotificationCommand.php index 4927308..23de3d1 100644 --- a/Console/Command/SlackNotificationCommand.php +++ b/Console/Command/SlackNotificationCommand.php @@ -33,5 +33,7 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { $this->runSlackMessage->execute($input, $output); + + return self::SUCCESS; } } diff --git a/Controller/Adminhtml/akeneo/NewAction.php b/Controller/Adminhtml/akeneo/NewAction.php index 211fdd1..b131353 100755 --- a/Controller/Adminhtml/akeneo/NewAction.php +++ b/Controller/Adminhtml/akeneo/NewAction.php @@ -9,7 +9,7 @@ class NewAction extends Action { /** - * @var \Magento\Backend\Model\View\Result\Forward + * @var \Magento\Backend\Model\View\Result\ForwardFactory */ protected $resultForwardFactory; @@ -21,8 +21,8 @@ public function __construct( Context $context, ForwardFactory $resultForwardFactory ) { - $this->resultForwardFactory = $resultForwardFactory; parent::__construct($context); + $this->resultForwardFactory = $resultForwardFactory; } /** diff --git a/Helper/Import/Product.php b/Helper/Import/Product.php index 50968e0..9ee8813 100644 --- a/Helper/Import/Product.php +++ b/Helper/Import/Product.php @@ -42,7 +42,7 @@ protected function getColumnsFromResult(array $result, array $keys = []): array return $mappedResult; } - protected function getFirstValue(array $values): string + protected function getFirstValue(array $values): mixed { $array = array_reverse($values); return array_pop($array)['data'] ?? ''; diff --git a/Plugin/CheckWebsiteAssociation.php b/Plugin/CheckWebsiteAssociation.php index 5bbbf00..cab2ad3 100644 --- a/Plugin/CheckWebsiteAssociation.php +++ b/Plugin/CheckWebsiteAssociation.php @@ -2,7 +2,6 @@ namespace JustBetter\AkeneoBundle\Plugin; -use Akeneo\Pim\ApiClient\Search\SearchBuilderFactory; use Magento\Framework\DB\Select; use Magento\Framework\DB\Statement\Pdo\Mysql; use Magento\Framework\Serialize\SerializerInterface; @@ -20,6 +19,8 @@ class CheckWebsiteAssociation protected $entitiesHelper; protected $storeHelper; protected $config; + protected $configHelper; + protected $authenticator; protected $serializer; /** @@ -32,7 +33,6 @@ public function __construct( ScopeConfigInterface $config, ConfigHelper $configHelper, Authenticator $authenticator, - SearchBuilderFactory $searchBuilderFactory, SerializerInterface $serializer ) { $this->entitiesHelper = $entitiesHelper; @@ -40,7 +40,6 @@ public function __construct( $this->config = $config; $this->configHelper = $configHelper; $this->authenticator = $authenticator; - $this->searchBuilderFactory = $searchBuilderFactory; $this->serializer = $serializer; } diff --git a/Plugin/SetTaxClassId.php b/Plugin/SetTaxClassId.php index 497fe80..027f3f1 100644 --- a/Plugin/SetTaxClassId.php +++ b/Plugin/SetTaxClassId.php @@ -7,19 +7,20 @@ use Akeneo\Connector\Helper\Store as StoreHelper; use Akeneo\Connector\Helper\Config as ConfigHelper; use Akeneo\Connector\Helper\Import\Product as ProductImportHelper; +use Exception; use Magento\Store\Model\ScopeInterface as scope; use Magento\Framework\Serialize\Serializer\Json; use Magento\Framework\App\Config\ScopeConfigInterface; -use Magento\Eav\Model\Config as EavConfig; class SetTaxClassId { protected $entitiesHelper; + protected $storeHelper; + protected $serializer; protected $configHelper; + protected $authenticator; protected $scopeConfig; protected $tax_id_columns; - protected $storeHelper; - protected $serializer; /** * @param ProductImportHelper $entitiesHelper @@ -28,7 +29,6 @@ class SetTaxClassId * @param ConfigHelper $configHelper * @param Authenticator $authenticator * @param ScopeConfigInterface $scopeConfig - * @param EavConfig $eavConfig */ public function __construct( ProductImportHelper $entitiesHelper, @@ -37,7 +37,6 @@ public function __construct( ConfigHelper $configHelper, Authenticator $authenticator, ScopeConfigInterface $scopeConfig, - EavConfig $eavConfig ) { $this->entitiesHelper = $entitiesHelper; $this->storeHelper = $storeHelper; @@ -45,7 +44,6 @@ public function __construct( $this->configHelper = $configHelper; $this->authenticator = $authenticator; $this->scopeConfig = $scopeConfig; - $this->eavConfig = $eavConfig; } /** @@ -185,7 +183,7 @@ public function checkTaxColumnsExist($mappings, $tmpTable) /** @var AdapterInterface $connection */ $connection = $this->entitiesHelper->getConnection(); - foreach ($mappings as $key => $mapping) { + foreach ($mappings as $mapping) { $akeneoAttribute = $this->authenticator->getAkeneoApiClient()->getAttributeApi()->get($mapping); @@ -197,7 +195,7 @@ public function checkTaxColumnsExist($mappings, $tmpTable) if (isset($akeneoAttribute['localizable'])) { $mappedChannels = $this->configHelper->getMappedChannels(); - foreach ($mappedChannels as $key => $channel) { + foreach ($mappedChannels as $channel) { foreach ($this->storeHelper->getChannelStoreLangs($channel) as $locale) { if ($connection->tableColumnExists($tmpTable, $mapping . '-' . $locale . '-' . $channel)) { $newMappings[] = $mapping . '-' . $locale . '-' . $channel; diff --git a/Plugin/SetTierPrices.php b/Plugin/SetTierPrices.php index c965527..cb32cac 100644 --- a/Plugin/SetTierPrices.php +++ b/Plugin/SetTierPrices.php @@ -18,6 +18,7 @@ class SetTierPrices protected $serializer; protected $config; protected $entitiesHelper; + protected $customerGroups; public $customerGroupsUnserialized; /** diff --git a/composer.json b/composer.json index abc2986..b860627 100644 --- a/composer.json +++ b/composer.json @@ -5,6 +5,10 @@ "php": ">=8.0", "akeneo/module-magento2-connector-community": "*" }, + "require-dev": { + "bitexpert/phpstan-magento": "^0.11.0", + "phpstan/phpstan": "^1.10" + }, "type": "magento2-module", "authors": [ { @@ -16,6 +20,12 @@ "email": "robin@justbetter.nl" } ], + "repositories": { + "magento": { + "type": "composer", + "url": "https://repo-magento-mirror.fooman.co.nz/" + } + }, "autoload": { "files": [ "registration.php" @@ -23,5 +33,11 @@ "psr-4": { "JustBetter\\AkeneoBundle\\": "" } + }, + "config": { + "allow-plugins": { + "php-http/discovery": true, + "magento/composer-dependency-version-audit-plugin": true + } } } diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..d5ab6f2 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,12 @@ +includes: + - vendor/bitexpert/phpstan-magento/extension.neon +parameters: + paths: + - . + excludePaths: + - vendor + level: 1 + ignoreErrors: + - '#Magento\\Backend\\Model\\View\\Result\\ForwardFactory#' + - '#Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Set\\CollectionFactory#' + - '#Magento\\Catalog\\Model\\ResourceModel\\Product\\CollectionFactory#' \ No newline at end of file