Skip to content

Commit

Permalink
Feature/phpstan (#40)
Browse files Browse the repository at this point in the history
* Fix Warning: Undefined array key when setting required attributes active

* added phpstan to akeneo bundle

---------

Co-authored-by: Pim Ruiter <[email protected]>
  • Loading branch information
fritsjustbetter and pimruiter committed Feb 20, 2024
1 parent 174cad2 commit ef3966d
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 18 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/analyse.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vendor
composer.lock
1 change: 0 additions & 1 deletion Block/Adminhtml/Akeneo.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ protected function _getAddButtonOptions()
}

/**
* @param string $type
* @return string
*/
protected function _getCreateUrl()
Expand Down
3 changes: 2 additions & 1 deletion Block/Adminhtml/Akeneo/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ protected function _construct()
*/
protected function _prepareCollection()
{
/* @phpstan-ignore-next-line */
$collection = $this->_akeneoFactory->create()->getCollection();
$this->setCollection($collection);

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions Block/Adminhtml/System/Config/Form/Field/TaxIdMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions Console/Command/SlackNotificationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->runSlackMessage->execute($input, $output);

return self::SUCCESS;
}
}
4 changes: 2 additions & 2 deletions Controller/Adminhtml/akeneo/NewAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class NewAction extends Action
{
/**
* @var \Magento\Backend\Model\View\Result\Forward
* @var \Magento\Backend\Model\View\Result\ForwardFactory
*/
protected $resultForwardFactory;

Expand All @@ -21,8 +21,8 @@ public function __construct(
Context $context,
ForwardFactory $resultForwardFactory
) {
$this->resultForwardFactory = $resultForwardFactory;
parent::__construct($context);
$this->resultForwardFactory = $resultForwardFactory;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Helper/Import/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ?? '';
Expand Down
5 changes: 2 additions & 3 deletions Plugin/CheckWebsiteAssociation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,6 +19,8 @@ class CheckWebsiteAssociation
protected $entitiesHelper;
protected $storeHelper;
protected $config;
protected $configHelper;
protected $authenticator;
protected $serializer;

/**
Expand All @@ -32,15 +33,13 @@ public function __construct(
ScopeConfigInterface $config,
ConfigHelper $configHelper,
Authenticator $authenticator,
SearchBuilderFactory $searchBuilderFactory,
SerializerInterface $serializer
) {
$this->entitiesHelper = $entitiesHelper;
$this->storeHelper = $storeHelper;
$this->config = $config;
$this->configHelper = $configHelper;
$this->authenticator = $authenticator;
$this->searchBuilderFactory = $searchBuilderFactory;
$this->serializer = $serializer;
}

Expand Down
14 changes: 6 additions & 8 deletions Plugin/SetTaxClassId.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,7 +29,6 @@ class SetTaxClassId
* @param ConfigHelper $configHelper
* @param Authenticator $authenticator
* @param ScopeConfigInterface $scopeConfig
* @param EavConfig $eavConfig
*/
public function __construct(
ProductImportHelper $entitiesHelper,
Expand All @@ -37,15 +37,13 @@ public function __construct(
ConfigHelper $configHelper,
Authenticator $authenticator,
ScopeConfigInterface $scopeConfig,
EavConfig $eavConfig
) {
$this->entitiesHelper = $entitiesHelper;
$this->storeHelper = $storeHelper;
$this->serializer = $serializer;
$this->configHelper = $configHelper;
$this->authenticator = $authenticator;
$this->scopeConfig = $scopeConfig;
$this->eavConfig = $eavConfig;
}

/**
Expand Down Expand Up @@ -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);

Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions Plugin/SetTierPrices.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class SetTierPrices
protected $serializer;
protected $config;
protected $entitiesHelper;
protected $customerGroups;
public $customerGroupsUnserialized;

/**
Expand Down
16 changes: 16 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand All @@ -16,12 +20,24 @@
"email": "[email protected]"
}
],
"repositories": {
"magento": {
"type": "composer",
"url": "https://repo-magento-mirror.fooman.co.nz/"
}
},
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"JustBetter\\AkeneoBundle\\": ""
}
},
"config": {
"allow-plugins": {
"php-http/discovery": true,
"magento/composer-dependency-version-audit-plugin": true
}
}
}
12 changes: 12 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -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#'

0 comments on commit ef3966d

Please sign in to comment.