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