Skip to content

Commit ef3966d

Browse files
Feature/phpstan (#40)
* Fix Warning: Undefined array key when setting required attributes active * added phpstan to akeneo bundle --------- Co-authored-by: Pim Ruiter <[email protected]>
1 parent 174cad2 commit ef3966d

File tree

13 files changed

+71
-18
lines changed

13 files changed

+71
-18
lines changed

.github/workflows/analyse.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: PHPStan
2+
3+
on: ['push', 'pull_request']
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
name: analyse
9+
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v2
13+
14+
- name: Setup PHP
15+
uses: shivammathur/setup-php@v2
16+
with:
17+
php-version: 8.2
18+
extensions: dom, curl, libxml, mbstring, zip, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
19+
coverage: none
20+
21+
- name: Install dependencies
22+
run: composer install --no-interaction
23+
24+
- name: Analyse
25+
run: vendor/bin/phpstan analyse

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
vendor
2+
composer.lock

Block/Adminhtml/Akeneo.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ protected function _getAddButtonOptions()
5959
}
6060

6161
/**
62-
* @param string $type
6362
* @return string
6463
*/
6564
protected function _getCreateUrl()

Block/Adminhtml/Akeneo/Grid.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ protected function _construct()
6969
*/
7070
protected function _prepareCollection()
7171
{
72+
/* @phpstan-ignore-next-line */
7273
$collection = $this->_akeneoFactory->create()->getCollection();
7374
$this->setCollection($collection);
7475

@@ -191,7 +192,7 @@ public function getGridUrl()
191192
}
192193

193194
/**
194-
* @param \JustBetter\AkeneoBundle\Model\akeneo|\Magento\Framework\Object $row
195+
* @param \JustBetter\AkeneoBundle\Model\Akeneo|\Magento\Framework\Object $row
195196
* @return string
196197
*/
197198
public function getRowUrl($row)

Block/Adminhtml/System/Config/Form/Field/TaxIdMapping.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,12 @@ public function __construct(
4141
Context $context,
4242
Factory $elementFactory,
4343
Product $productTaxClassSource,
44-
Config $eavConfig,
4544
array $data = []
4645
) {
4746
parent::__construct($context, $data);
4847

4948
$this->elementFactory = $elementFactory;
5049
$this->productTaxClassSource = $productTaxClassSource;
51-
$this->eavConfig = $eavConfig;
5250
}
5351

5452
/**

Console/Command/SlackNotificationCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,7 @@ protected function configure()
3333
protected function execute(InputInterface $input, OutputInterface $output)
3434
{
3535
$this->runSlackMessage->execute($input, $output);
36+
37+
return self::SUCCESS;
3638
}
3739
}

Controller/Adminhtml/akeneo/NewAction.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class NewAction extends Action
1010
{
1111
/**
12-
* @var \Magento\Backend\Model\View\Result\Forward
12+
* @var \Magento\Backend\Model\View\Result\ForwardFactory
1313
*/
1414
protected $resultForwardFactory;
1515

@@ -21,8 +21,8 @@ public function __construct(
2121
Context $context,
2222
ForwardFactory $resultForwardFactory
2323
) {
24-
$this->resultForwardFactory = $resultForwardFactory;
2524
parent::__construct($context);
25+
$this->resultForwardFactory = $resultForwardFactory;
2626
}
2727

2828
/**

Helper/Import/Product.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected function getColumnsFromResult(array $result, array $keys = []): array
4242
return $mappedResult;
4343
}
4444

45-
protected function getFirstValue(array $values): string
45+
protected function getFirstValue(array $values): mixed
4646
{
4747
$array = array_reverse($values);
4848
return array_pop($array)['data'] ?? '';

Plugin/CheckWebsiteAssociation.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace JustBetter\AkeneoBundle\Plugin;
44

5-
use Akeneo\Pim\ApiClient\Search\SearchBuilderFactory;
65
use Magento\Framework\DB\Select;
76
use Magento\Framework\DB\Statement\Pdo\Mysql;
87
use Magento\Framework\Serialize\SerializerInterface;
@@ -20,6 +19,8 @@ class CheckWebsiteAssociation
2019
protected $entitiesHelper;
2120
protected $storeHelper;
2221
protected $config;
22+
protected $configHelper;
23+
protected $authenticator;
2324
protected $serializer;
2425

2526
/**
@@ -32,15 +33,13 @@ public function __construct(
3233
ScopeConfigInterface $config,
3334
ConfigHelper $configHelper,
3435
Authenticator $authenticator,
35-
SearchBuilderFactory $searchBuilderFactory,
3636
SerializerInterface $serializer
3737
) {
3838
$this->entitiesHelper = $entitiesHelper;
3939
$this->storeHelper = $storeHelper;
4040
$this->config = $config;
4141
$this->configHelper = $configHelper;
4242
$this->authenticator = $authenticator;
43-
$this->searchBuilderFactory = $searchBuilderFactory;
4443
$this->serializer = $serializer;
4544
}
4645

Plugin/SetTaxClassId.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,20 @@
77
use Akeneo\Connector\Helper\Store as StoreHelper;
88
use Akeneo\Connector\Helper\Config as ConfigHelper;
99
use Akeneo\Connector\Helper\Import\Product as ProductImportHelper;
10+
use Exception;
1011
use Magento\Store\Model\ScopeInterface as scope;
1112
use Magento\Framework\Serialize\Serializer\Json;
1213
use Magento\Framework\App\Config\ScopeConfigInterface;
13-
use Magento\Eav\Model\Config as EavConfig;
1414

1515
class SetTaxClassId
1616
{
1717
protected $entitiesHelper;
18+
protected $storeHelper;
19+
protected $serializer;
1820
protected $configHelper;
21+
protected $authenticator;
1922
protected $scopeConfig;
2023
protected $tax_id_columns;
21-
protected $storeHelper;
22-
protected $serializer;
2324

2425
/**
2526
* @param ProductImportHelper $entitiesHelper
@@ -28,7 +29,6 @@ class SetTaxClassId
2829
* @param ConfigHelper $configHelper
2930
* @param Authenticator $authenticator
3031
* @param ScopeConfigInterface $scopeConfig
31-
* @param EavConfig $eavConfig
3232
*/
3333
public function __construct(
3434
ProductImportHelper $entitiesHelper,
@@ -37,15 +37,13 @@ public function __construct(
3737
ConfigHelper $configHelper,
3838
Authenticator $authenticator,
3939
ScopeConfigInterface $scopeConfig,
40-
EavConfig $eavConfig
4140
) {
4241
$this->entitiesHelper = $entitiesHelper;
4342
$this->storeHelper = $storeHelper;
4443
$this->serializer = $serializer;
4544
$this->configHelper = $configHelper;
4645
$this->authenticator = $authenticator;
4746
$this->scopeConfig = $scopeConfig;
48-
$this->eavConfig = $eavConfig;
4947
}
5048

5149
/**
@@ -185,7 +183,7 @@ public function checkTaxColumnsExist($mappings, $tmpTable)
185183
/** @var AdapterInterface $connection */
186184
$connection = $this->entitiesHelper->getConnection();
187185

188-
foreach ($mappings as $key => $mapping) {
186+
foreach ($mappings as $mapping) {
189187

190188
$akeneoAttribute = $this->authenticator->getAkeneoApiClient()->getAttributeApi()->get($mapping);
191189

@@ -197,7 +195,7 @@ public function checkTaxColumnsExist($mappings, $tmpTable)
197195

198196
if (isset($akeneoAttribute['localizable'])) {
199197
$mappedChannels = $this->configHelper->getMappedChannels();
200-
foreach ($mappedChannels as $key => $channel) {
198+
foreach ($mappedChannels as $channel) {
201199
foreach ($this->storeHelper->getChannelStoreLangs($channel) as $locale) {
202200
if ($connection->tableColumnExists($tmpTable, $mapping . '-' . $locale . '-' . $channel)) {
203201
$newMappings[] = $mapping . '-' . $locale . '-' . $channel;

0 commit comments

Comments
 (0)