diff --git a/.github/workflows/testing-suite.yaml b/.github/workflows/grumphp.yaml
similarity index 72%
rename from .github/workflows/testing-suite.yaml
rename to .github/workflows/grumphp.yaml
index f33b374..af31d25 100644
--- a/.github/workflows/testing-suite.yaml
+++ b/.github/workflows/grumphp.yaml
@@ -1,4 +1,4 @@
-name: Testing Suite
+name: GrumPHP
on: [push]
jobs:
linter:
@@ -13,10 +13,11 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- - name: Testing Suite
+ - 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/.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/App/Response/FeedContent.php b/App/Response/FeedContent.php
index d5c5da1..c3e346a 100644
--- a/App/Response/FeedContent.php
+++ b/App/Response/FeedContent.php
@@ -1,4 +1,4 @@
-export = $export;
$this->log = $log;
- $this->type = $type;
$this->store = $store;
- $this->driver = $driver;
}
/**
diff --git a/Block/Config/Form/Field/ExportPriceStart.php b/Block/Config/Form/Field/ExportPriceStart.php
index 1829664..2667e44 100644
--- a/Block/Config/Form/Field/ExportPriceStart.php
+++ b/Block/Config/Form/Field/ExportPriceStart.php
@@ -1,4 +1,4 @@
-setData(
[
'label' => __('Schedule'),
- 'onclick' => "setLocation('{$this->getUrl('tweakwise/export/trigger/type/price')}')",
+ 'onclick' => sprintf("setLocation('%s')", $this->getUrl('tweakwise/export/trigger/type/price')),
]
);
diff --git a/Block/Config/Form/Field/ExportStart.php b/Block/Config/Form/Field/ExportStart.php
index c5f5b4e..61e127b 100644
--- a/Block/Config/Form/Field/ExportStart.php
+++ b/Block/Config/Form/Field/ExportStart.php
@@ -1,4 +1,4 @@
-setData(
[
'label' => __('Schedule'),
- 'onclick' => "setLocation('{$this->getUrl('tweakwise/export/trigger')}')",
+ 'onclick' => sprintf("setLocation('%s')", $this->getUrl('tweakwise/export/trigger')),
]
);
diff --git a/Block/Config/Form/Field/ExportState.php b/Block/Config/Form/Field/ExportState.php
index 3106dba..8f01932 100644
--- a/Block/Config/Form/Field/ExportState.php
+++ b/Block/Config/Form/Field/ExportState.php
@@ -1,4 +1,4 @@
-setData(
[
'label' => __('Schedule'),
- 'onclick' => "setLocation('{$this->getUrl('tweakwise/export/trigger/type/stock')}')",
+ 'onclick' => sprintf("setLocation('%s')", $this->getUrl('tweakwise/export/trigger/type/stock')),
]
);
diff --git a/Console/Command/ExportCommand.php b/Console/Command/ExportCommand.php
index 782a29e..e771122 100644
--- a/Console/Command/ExportCommand.php
+++ b/Console/Command/ExportCommand.php
@@ -1,5 +1,4 @@
-type;
}
- if ($type !== "stock" && $type !== "" && $type !== "price") {
+ if ($type !== 'stock' && $type !== '' && $type !== 'price') {
$output->writeln('Type option should be stock, price or not set');
return -1;
- } elseif (empty($type)) {
+ }
+
+ if (empty($type)) {
$type = null;
}
$validate = (string)$input->getOption('validate');
- if ($validate !== 'y' && $validate !== 'n' && $validate !== "") {
+ if ($validate !== 'y' && $validate !== 'n' && $validate !== '') {
$output->writeln('Validate option can only contain y or n');
return -1;
}
- $validate = $validate === "" ? $this->config->isValidate() : $validate === 'y';
+ $validate = $validate === '' ? $this->config->isValidate() : $validate === 'y';
$startTime = microtime(true);
$feedFile = (string)$input->getOption('file');
@@ -167,7 +169,7 @@ function () use ($input, $output) {
return -1;
}
-
+ // @phpstan-ignore-next-line
if (!$this->config->isEnabled($store)) {
$output->writeln('Tweakwise export does not enabled in this store');
@@ -178,9 +180,9 @@ function () use ($input, $output) {
$feedFile = $this->config->getDefaultFeedFile($store, $type);
}
- $output->writeln("generatig feed for {$store->getCode()}");
+ $output->writeln(sprintf('generatig feed for %s', $store->getCode()));
$this->export->generateToFile($feedFile, $validate, $store, $type);
- $output->writeln("feed file: {$feedFile}");
+ $output->writeln(sprintf('feed file: %s', $feedFile));
} else {
if ($storeCode) {
$output->writeln('Store level export disabled, remove --store parameter');
@@ -191,9 +193,9 @@ function () use ($input, $output) {
$feedFile = $this->config->getDefaultFeedFile(null, $type);
}
- $output->writeln("generating single feed for export enabled stores");
+ $output->writeln('generating single feed for export enabled stores');
$this->export->generateToFile($feedFile, $validate, null, $type);
- $output->writeln("feed file: {$feedFile}");
+ $output->writeln(sprintf('feed file: %s', $feedFile));
}
$generateTime = round(microtime(true) - $startTime, 2);
@@ -215,6 +217,12 @@ function () use ($input, $output) {
);
}
+ /**
+ * @param InputInterface $input
+ * @param OutputInterface $output
+ * @return void
+ * @throws Exception
+ */
public function executeStock(InputInterface $input, OutputInterface $output)
{
$this->type = 'stock';
diff --git a/Controller/Adminhtml/Export/Trigger.php b/Controller/Adminhtml/Export/Trigger.php
index d83d190..e3b2aac 100644
--- a/Controller/Adminhtml/Export/Trigger.php
+++ b/Controller/Adminhtml/Export/Trigger.php
@@ -1,4 +1,4 @@
-context = $context;
+ // @phpstan-ignore-next-line
$this->export = $export;
$this->log = $log;
$this->requestValidator = $requestValidator;
$this->responseFactory = $responseFactory;
$this->storeManager = $storeManager;
- $this->driver = $driver;
}
/**
@@ -99,7 +94,7 @@ public function __construct(
* phpcs:disable Squiz.Commenting.FunctionComment.InvalidNoReturn
* @return Response
* phpcs:disable Magento2.Security.LanguageConstruct.ExitUsage
- * @SuppressWarnings(PHPMD.ExitExpression)
+ * @SuppressWarnings("PHPMD.ExitExpression")
*/
public function execute(): Response
{
@@ -119,6 +114,7 @@ public function execute(): Response
$store = $this->storeManager->getStore($storeId);
}
+ // @phpstan-ignore-next-line
(new FeedContent($this->export, $this->log, $this->driver, $store, $request->getParam('type')))->__toString();
exit();
diff --git a/Cron/Export.php b/Cron/Export.php
index 2aaeef0..3a56547 100644
--- a/Cron/Export.php
+++ b/Cron/Export.php
@@ -1,4 +1,4 @@
-config->isRealTime()) {
$this->log->debug('Export set to real time, skipping cron export.');
@@ -95,10 +93,13 @@ public function generateFeed($type = null): void
$validate = $this->config->isValidate();
if ($this->config->isStoreLevelExportEnabled()) {
foreach ($this->storeManager->getStores() as $store) {
- if ($this->config->isEnabled($store)) {
- $feedFile = $this->config->getDefaultFeedFile($store, $type);
- $this->export->generateToFile($feedFile, $validate, $store, $type);
+ // @phpstan-ignore-next-line
+ if (!$this->config->isEnabled($store)) {
+ continue;
}
+
+ $feedFile = $this->config->getDefaultFeedFile($store, $type);
+ $this->export->generateToFile($feedFile, $validate, $store, $type);
}
return;
diff --git a/Exception/ExportExceptionInterface.php b/Exception/ExportExceptionInterface.php
index abd7069..9cf004d 100644
--- a/Exception/ExportExceptionInterface.php
+++ b/Exception/ExportExceptionInterface.php
@@ -1,4 +1,4 @@
-optionId = $optionId;
- $this->isRequired = $isRequired;
}
/**
@@ -59,6 +53,7 @@ public function isRequired(): ?bool
*/
public function setIsRequired(bool $isRequired): void
{
+ // @phpstan-ignore-next-line
$this->isRequired = $isRequired;
}
}
diff --git a/Model/Config.php b/Model/Config.php
index 359da4e..23ea86f 100644
--- a/Model/Config.php
+++ b/Model/Config.php
@@ -1,4 +1,4 @@
-config = $config;
$this->directoryList = $directoryList;
$this->deployConfig = $deployConfig;
- $this->driver = $driver;
}
/**
@@ -100,6 +94,7 @@ public function __construct(
*/
public function isEnabled($store = null): bool
{
+ // @phpstan-ignore-next-line
return (bool) $this->config->isSetFlag(self::PATH_ENABLED, ScopeInterface::SCOPE_STORE, $store);
}
@@ -142,7 +137,7 @@ public function getMaxArchiveFiles(): int
/**
* @return string
*/
- public function getApiImportUrl($store = null, $type = null): string
+ public function getApiImportUrl($store = null, $type = null): string // @phpstan-ignore-line
{
if ($type === 'stock') {
return (string) $this->config->getValue(
@@ -161,6 +156,7 @@ public function getApiImportUrl($store = null, $type = null): string
*/
public function isOutOfStockChildren($store = null): bool
{
+ // @phpstan-ignore-next-line
return (bool) $this->config->isSetFlag(self::PATH_OUT_OF_STOCK_CHILDREN, ScopeInterface::SCOPE_STORE, $store);
}
@@ -188,7 +184,7 @@ public function getPriceFields($store = null): array
{
$data = (array) explode(
',',
- (string) $this->config->getValue(self::PATH_PRICE_FIELD, ScopeInterface::SCOPE_STORE, $store)
+ (string) $this->config->getValue(self::PATH_PRICE_FIELD, ScopeInterface::SCOPE_STORE, $store) // @phpstan-ignore-line
);
return array_filter($data);
}
@@ -201,6 +197,7 @@ public function getPriceFields($store = null): array
public function getSkipChildAttribute($attribute = null, $store = null)
{
if (!$this->skipAttributes) {
+ // @phpstan-ignore-next-line
$value = $this->config->getValue(self::PATH_EXCLUDE_CHILD_ATTRIBUTES, ScopeInterface::SCOPE_STORE, $store);
$skipAttributes = explode(',', (string) $value);
$this->skipAttributes = array_flip($skipAttributes);
@@ -224,7 +221,7 @@ public function getSkipChildByCompositeTypes($store = null): array
(string) $this->config->getValue(
self::PATH_SKIP_CHILD_BY_COMPOSITE_TYPE,
ScopeInterface::SCOPE_STORE,
- $store
+ $store // @phpstan-ignore-line
)
);
@@ -244,7 +241,7 @@ public function getDefaultFeedFile(?StoreInterface $store = null, ?string $type
if (
!$this->driver->isDirectory($dir) &&
!$this->driver->createDirectory($dir) &&
- !$this->driver->isDirectory($dir)
+ !$this->driver->isDirectory($dir) // @phpstan-ignore-line
) {
throw new RuntimeException(sprintf('Directory "%s" was not created', $dir));
}
@@ -263,7 +260,7 @@ public function getDefaultFeedFile(?StoreInterface $store = null, ?string $type
* @param StoreInterface|null $store
* @return string
*/
- public function getFeedLockFile($file = null, $store = null, $type = null): string
+ public function getFeedLockFile($file = null, $store = null, $type = null): string // @phpstan-ignore-line
{
if (!$file) {
$file = $this->getDefaultFeedFile($store, $type);
@@ -317,7 +314,7 @@ public function isGroupedExport(?StoreInterface $store = null): bool
return (bool) $this->config->getValue(
self::PATH_GROUPED_EXPORT_ENABLED,
ScopeInterface::SCOPE_STORE,
- $store
+ $store // @phpstan-ignore-line
);
}
@@ -327,6 +324,7 @@ public function isGroupedExport(?StoreInterface $store = null): bool
*/
public function calculateCombinedPrices(?StoreInterface $store = null): bool
{
+ // @phpstan-ignore-next-line
return (bool) $this->config->isSetFlag(self::CALCULATE_COMPOSITE_PRICES, ScopeInterface::SCOPE_STORE, $store);
}
diff --git a/Model/Config/Source/CompositeTypes.php b/Model/Config/Source/CompositeTypes.php
index 05ea401..3d20dce 100644
--- a/Model/Config/Source/CompositeTypes.php
+++ b/Model/Config/Source/CompositeTypes.php
@@ -1,4 +1,4 @@
-config = $config;
$this->validator = $validator;
$this->writer = $writer;
$this->log = $log;
$this->storeManager = $storeManager;
- $this->driver = $driver;
}
/**
@@ -97,7 +91,7 @@ public function __construct(
* phpcs:disable Generic.PHP.NoSilencedErrors.Discouraged
* phpcs:disable Magento2.Functions.DiscouragedFunction.Discouraged
* phpcs:disable Magento2.Functions.DiscouragedFunction.DiscouragedWithAlternative
- * @SuppressWarnings(PHPMD.ErrorControlOperator)
+ * @SuppressWarnings("PHPMD.ErrorControlOperator")
*/
protected function executeLocked(callable $action, ?StoreInterface $store = null, ?string $type = null): void
{
@@ -112,11 +106,14 @@ protected function executeLocked(callable $action, ?StoreInterface $store = null
);
}
+ // @phpstan-ignore-next-line
if ($this->driver->fileLock($lockHandle)) {
try {
$action();
} finally {
+ // @phpstan-ignore-next-line
$this->driver->fileLock($lockHandle, LOCK_UN);
+ // @phpstan-ignore-next-line
$this->driver->fileClose($lockHandle);
}
} else {
@@ -162,7 +159,7 @@ function () use ($targetHandle, $store, $type) {
* phpcs:disable Generic.PHP.NoSilencedErrors.Discouraged
* phpcs:disable Magento2.Functions.DiscouragedFunction.Discouraged
* phpcs:disable Magento2.Functions.DiscouragedFunction.DiscouragedWithAlternative
- * @SuppressWarnings(PHPMD.ErrorControlOperator)
+ * @SuppressWarnings("PHPMD.ErrorControlOperator")
*/
public function getFeed($targetHandle, ?StoreInterface $store = null, ?string $type = null): void
{
@@ -182,10 +179,13 @@ public function getFeed($targetHandle, ?StoreInterface $store = null, ?string $t
header('Content-type: text/xml');
header('Cache-Control: no-cache');
+ // @phpstan-ignore-next-line
while (!$this->driver->endOfFile($sourceHandle)) {
+ // @phpstan-ignore-next-line
$this->driver->fileWrite($targetHandle, fread($sourceHandle, self::FEED_COPY_BUFFER_SIZE));
}
+ // @phpstan-ignore-next-line
$this->driver->fileClose($sourceHandle);
} else {
$this->generateToFile($feedFile, $this->config->isValidate(), $store, $type);
@@ -198,9 +198,9 @@ public function getFeed($targetHandle, ?StoreInterface $store = null, ?string $t
* @param bool $validate
* @param null|StoreInterface $store
* @throws Exception
- * @SuppressWarnings(PHPMD.ErrorControlOperator)
+ * @SuppressWarnings("PHPMD.ErrorControlOperator")
*/
- public function generateToFile($feedFile, $validate, $store = null, $type = null): void
+ public function generateToFile($feedFile, $validate, $store = null, $type = null): void // @phpstan-ignore-line
{
$this->executeLocked(
function () use ($feedFile, $validate, $store, $type) {
@@ -216,9 +216,11 @@ function () use ($feedFile, $validate, $store, $type) {
try {
// Write
try {
+ // @phpstan-ignore-next-line
$this->writer->write($sourceHandle, $store, $type);
$this->log->debug('Feed exported to ' . $tmpFeedFile);
} finally {
+ // @phpstan-ignore-next-line
fclose($sourceHandle);
}
@@ -269,7 +271,7 @@ function () use ($feedFile, $validate, $store, $type) {
/**
* Trigger TW import call if configured
*/
- protected function triggerTweakwiseImport($store = null, $type = null): void
+ protected function triggerTweakwiseImport($store = null, $type = null): void // @phpstan-ignore-line
{
$apiImportUrl = $this->config->getApiImportUrl($store, $type);
if (empty($apiImportUrl)) {
@@ -291,7 +293,7 @@ protected function triggerTweakwiseImport($store = null, $type = null): void
*
* Update last modified time from feed file
*/
- protected function touchFeedGenerateDate($store = null, $type = null): void
+ protected function touchFeedGenerateDate($store = null, $type = null): void // @phpstan-ignore-line
{
touch($this->config->getDefaultFeedFile($store, $type));
}
diff --git a/Model/Helper.php b/Model/Helper.php
index 57574cc..dfe9347 100644
--- a/Model/Helper.php
+++ b/Model/Helper.php
@@ -1,4 +1,4 @@
-log->emergency('[TweakWise] ' . $message, $context);
}
@@ -52,7 +53,7 @@ public function emergency($message, array $context = []): void
/**
* {@inheritdoc}
*/
- public function alert($message, array $context = []): void
+ public function alert($message, array $context = []): void // @phpstan-ignore-line
{
$this->log->alert('[TweakWise] ' . $message, $context);
}
@@ -60,7 +61,7 @@ public function alert($message, array $context = []): void
/**
* {@inheritdoc}
*/
- public function critical($message, array $context = []): void
+ public function critical($message, array $context = []): void // @phpstan-ignore-line
{
$this->log->critical('[TweakWise] ' . $message, $context);
}
@@ -68,7 +69,7 @@ public function critical($message, array $context = []): void
/**
* {@inheritdoc}
*/
- public function error($message, array $context = []): void
+ public function error($message, array $context = []): void // @phpstan-ignore-line
{
$this->log->error('[TweakWise] ' . $message, $context);
}
@@ -76,7 +77,7 @@ public function error($message, array $context = []): void
/**
* {@inheritdoc}
*/
- public function warning($message, array $context = []): void
+ public function warning($message, array $context = []): void // @phpstan-ignore-line
{
$this->log->warning('[TweakWise] ' . $message, $context);
}
@@ -84,7 +85,7 @@ public function warning($message, array $context = []): void
/**
* {@inheritdoc}
*/
- public function notice($message, array $context = []): void
+ public function notice($message, array $context = []): void // @phpstan-ignore-line
{
$this->log->notice('[TweakWise] ' . $message, $context);
}
@@ -92,7 +93,7 @@ public function notice($message, array $context = []): void
/**
* {@inheritdoc}
*/
- public function info($message, array $context = []): void
+ public function info($message, array $context = []): void // @phpstan-ignore-line
{
$this->log->info('[TweakWise] ' . $message, $context);
}
@@ -100,17 +101,19 @@ public function info($message, array $context = []): void
/**
* {@inheritdoc}
*/
- public function debug($message, array $context = []): void
+ public function debug($message, array $context = []): void // @phpstan-ignore-line
{
- if ($this->enableDebugLog) {
- $this->log->debug('[TweakWise] ' . $message, $context);
+ if (!$this->enableDebugLog) {
+ return;
}
+
+ $this->log->debug('[TweakWise] ' . $message, $context);
}
/**
* {@inheritdoc}
*/
- public function log($level, $message, array $context = []): void
+ public function log($level, $message, array $context = []): void // @phpstan-ignore-line
{
$this->log->log($level, '[TweakWise] ' . $message, $context);
}
diff --git a/Model/ProductAttributes.php b/Model/ProductAttributes.php
index 095d0da..52a6d20 100644
--- a/Model/ProductAttributes.php
+++ b/Model/ProductAttributes.php
@@ -1,4 +1,4 @@
-summaryCollectionFactory->create()
->addStoreFilter($collection->getStore()->getId())
- ->addEntityFilter($collection->getAllIds());
+ ->addEntityFilter($collection->getAllIds()); // @phpstan-ignore-line
$reviews = [];
- /** @var Summary $rating */
foreach ($summaryCollection as $summary) {
$reviews[] = $this->createProductReviewSummary($summary);
}
@@ -49,7 +48,7 @@ public function getProductReviews(Collection $collection): array
protected function createProductReviewSummary(Summary $summary): ProductReviewSummary
{
return new ProductReviewSummary(
- $summary->getRatingSummary(),
+ $summary->getRatingSummary(), // @phpstan-ignore-line
$summary->getReviewsCount(),
$summary->getEntityPkValue()
);
diff --git a/Model/Review/ProductReviewSummary.php b/Model/Review/ProductReviewSummary.php
index d012248..de7fd27 100644
--- a/Model/Review/ProductReviewSummary.php
+++ b/Model/Review/ProductReviewSummary.php
@@ -1,4 +1,4 @@
-setCreatedAt(date('Y-m-d H:i:s', $createdAtTime))
->setScheduledAt(date('Y-m-d H:i', $scheduledAtTime));
+ // @phpstan-ignore-next-line
$schedule->save();
+ // @phpstan-ignore-next-line
return $schedule;
}
diff --git a/Model/StockItem.php b/Model/StockItem.php
index f4b9ba0..8374fe9 100644
--- a/Model/StockItem.php
+++ b/Model/StockItem.php
@@ -1,4 +1,4 @@
-iterator = $iterator;
$this->storeManager = $storeManager;
@@ -121,7 +118,7 @@ public function write(Writer $writer, XMLWriter $xml, ?StoreInterface $store = n
* @param XMLWriter $xml
* @param Store $store
* @param int[] $entityIds
- * @SuppressWarnings(PHPMD.CyclomaticComplexity)
+ * @SuppressWarnings("PHPMD.CyclomaticComplexity")
*/
public function exportStore(Writer $writer, XMLWriter $xml, Store $store, array $entityIds = []): void
{
@@ -170,9 +167,11 @@ public function exportStore(Writer $writer, XMLWriter $xml, Store $store, array
$exportedCategories[$data['entity_id']] = true;
$this->writeCategory($xml, $storeId, $data);
// Flush every so often
- if ($index % 100 === 0) {
- $writer->flush();
+ if ($index % 100 !== 0) {
+ continue;
}
+
+ $writer->flush();
}
// Flush any remaining categories
@@ -187,7 +186,7 @@ public function exportStore(Writer $writer, XMLWriter $xml, Store $store, array
protected function writeCategory(XMLWriter $xml, int $storeId, array $data): void
{
$tweakwiseId = $this->helper->getTweakwiseId($storeId, $data['entity_id']);
- $xml->addCategoryExport($tweakwiseId);
+ $xml->addCategoryExport((int)$tweakwiseId);
$xml->startElement('category');
$xml->writeElement('categoryid', $tweakwiseId);
diff --git a/Model/Write/Categories/Iterator.php b/Model/Write/Categories/Iterator.php
index 0356fae..0f1efa4 100644
--- a/Model/Write/Categories/Iterator.php
+++ b/Model/Write/Categories/Iterator.php
@@ -1,4 +1,4 @@
-eavConfig->getAttribute($this->entityCode, $attributeCode);
/** @noinspection NullPointerExceptionInspection */
- $attributeKey = $attribute->getId() ?: $attributeCode;
+ $attributeKey = $attribute->getId() ? $attribute->getId() : $attributeCode;
$this->attributes[$attributeKey] = $attribute;
$this->attributesByCode[$attributeCode] = $attribute;
@@ -168,7 +168,7 @@ public function removeAttribute(string $attributeCode): void
{
$attribute = $this->eavConfig->getAttribute($this->entityCode, $attributeCode);
/** @noinspection NullPointerExceptionInspection */
- $attributeKey = $attribute->getId() ?: $attributeCode;
+ $attributeKey = $attribute->getId() ? $attribute->getId() : $attributeCode;
if (!isset($this->attributes[$attributeKey])) {
throw new InvalidArgumentException(sprintf('Attribute %s not found', $attributeCode));
@@ -244,9 +244,11 @@ protected function loopUnionRows(MysqlStatement $stmt)
}
}
- if ($entity['entity_id']) {
- yield $entity;
+ if (!$entity['entity_id']) {
+ return;
}
+
+ yield $entity;
}
/**
@@ -318,7 +320,7 @@ public function getIterator(): \Traversable
/**
* @return int[]|null
- * @SuppressWarnings(PHPMD.MissingImport)
+ * @SuppressWarnings("PHPMD.MissingImport")
*/
protected function getEntityBatch(): ?array
{
@@ -333,8 +335,10 @@ protected function getEntityBatch(): ?array
$select->where('entity_id IN (?)', $this->getEntityIds());
}
+ // @phpstan-ignore-next-line
$result = $select->query()->fetchAll();
$entityIds = array_column($result, 'entity_id');
+ // @phpstan-ignore-next-line
$this->entitySet[$storeId] = new \ArrayIterator(array_chunk($entityIds, $this->batchSize));
$this->entityData = array_combine($entityIds, $result);
}
@@ -420,6 +424,7 @@ protected function getStaticAttributeSelect(array $attributes): array
]
);
if ($this->entityIds) {
+ // phpcs:disable Squiz.Strings.DoubleQuoteUsage.ContainsVar
$select->where("{$attribute->getBackendTable()}.entity_id IN (?)", $this->entityIds);
}
@@ -449,6 +454,7 @@ protected function getAttributeSelectCommunity(string $table, array $attributes)
}
if ($this->entityIds) {
+ // phpcs:disable Squiz.Strings.DoubleQuoteUsage.ContainsVar
$select->where("{$table}.entity_id IN (?)", $this->entityIds);
}
diff --git a/Model/Write/Price.php b/Model/Write/Price.php
index 81887a6..01acd1b 100644
--- a/Model/Write/Price.php
+++ b/Model/Write/Price.php
@@ -1,4 +1,4 @@
-iterator as $index => $data) {
$this->writeProduct($xml, $store->getId(), $data);
// Flush every so often
- if ($index % 100 === 0) {
- $writer->flush();
+ if ($index % 100 !== 0) {
+ continue;
}
+
+ $writer->flush();
}
// Flush any remaining products
@@ -203,6 +201,7 @@ protected function scalarValue($value)
}
if (is_numeric($value)) {
+ // @phpstan-ignore-next-line
$value = $this->normalizeExponent($value);
}
@@ -219,6 +218,7 @@ protected function scalarValue($value)
*/
protected function normalizeExponent($value)
{
+ // @phpstan-ignore-next-line
if (stripos($value, 'E+') !== false) {
// Assume integer value
$decimals = 0;
diff --git a/Model/Write/Price/Collection.php b/Model/Write/Price/Collection.php
index ad9a419..f0a96ff 100644
--- a/Model/Write/Price/Collection.php
+++ b/Model/Write/Price/Collection.php
@@ -1,4 +1,4 @@
-getId();
$skus[] = $entity->getAttribute('sku', false);
- if ($entity instanceof CompositeExportEntityInterface) {
- foreach ($entity->getAllChildren() as $child) {
- $ids[] = $child->getId();
- $skus[] = $child->getAttribute('sku', false);
- }
+ if (!($entity instanceof CompositeExportEntityInterface)) {
+ continue;
+ }
+
+ foreach ($entity->getAllChildren() as $child) {
+ $ids[] = $child->getId();
+ $skus[] = $child->getAttribute('sku', false);
}
}
// Make unique
$this->ids = array_flip($ids);
+ // @phpstan-ignore-next-line
$this->skus = array_flip($skus);
}
diff --git a/Model/Write/Price/ExportEntity.php b/Model/Write/Price/ExportEntity.php
index 38b686a..e8f6251 100644
--- a/Model/Write/Price/ExportEntity.php
+++ b/Model/Write/Price/ExportEntity.php
@@ -1,4 +1,4 @@
-getStockItem() !== null ? $this->getStockItem()->getIsInStock() : false;
}
diff --git a/Model/Write/Price/ExportEntityFactory.php b/Model/Write/Price/ExportEntityFactory.php
index 311a7e5..a075fb7 100644
--- a/Model/Write/Price/ExportEntityFactory.php
+++ b/Model/Write/Price/ExportEntityFactory.php
@@ -1,4 +1,4 @@
-add($entity);
- if ($batch->count() === $this->batchSize) {
- // After PHP7+ we can use yield from
- foreach ($this->processBatch($batch) as $processedEntity) {
- yield $processedEntity;
- }
+ if ($batch->count() !== $this->batchSize) {
+ continue;
+ }
- $batch = $this->collectionFactory->create(['store' => $this->store]);
+ // After PHP7+ we can use yield from
+ foreach ($this->processBatch($batch) as $processedEntity) {
+ yield $processedEntity;
}
+
+ $batch = $this->collectionFactory->create(['store' => $this->store]);
}
// After PHP7+ we can use yield from
@@ -122,6 +123,7 @@ protected function processBatch(Collection $collection)
{
if ($collection->count()) {
foreach ($this->collectionDecorators as $decorator) {
+ // @phpstan-ignore-next-line
$decorator->decorate($collection);
}
}
diff --git a/Model/Write/Price/IteratorInitializer.php b/Model/Write/Price/IteratorInitializer.php
index 505b3f1..d090112 100644
--- a/Model/Write/Price/IteratorInitializer.php
+++ b/Model/Write/Price/IteratorInitializer.php
@@ -1,4 +1,4 @@
-iterator as $index => $data) {
$this->writeProduct($xml, $store->getId(), $data);
// Flush every so often
- if ($index % 100 === 0) {
- $writer->flush();
+ if ($index % 100 !== 0) {
+ continue;
}
+
+ $writer->flush();
}
// Flush any remaining products
@@ -171,6 +173,7 @@ protected function writeProduct(XMLWriter $xml, $storeId, array $data): void
$xml->startElement('categories');
foreach ($data['categories'] as $categoryId) {
$categoryTweakwiseId = $this->helper->getTweakwiseId($storeId, $categoryId);
+ // @phpstan-ignore-next-line
if ($xml->hasCategoryExport($categoryTweakwiseId)) {
$xml->writeElement('categoryid', $categoryTweakwiseId);
} else {
@@ -211,7 +214,7 @@ public function writeAttribute(
$values = array_unique($values);
foreach ($values as $value) {
- if (empty($value) && $value !== "0") {
+ if (empty($value) && $value !== '0') {
continue;
}
@@ -277,6 +280,7 @@ protected function scalarValue($value)
}
if (is_numeric($value)) {
+ // @phpstan-ignore-next-line
$value = $this->normalizeExponent($value);
}
@@ -293,6 +297,7 @@ protected function scalarValue($value)
*/
protected function normalizeExponent($value)
{
+ // @phpstan-ignore-next-line
if (stripos($value, 'E+') !== false) {
// Assume integer value
$decimals = 0;
@@ -325,7 +330,8 @@ protected function explodeValues(array $data, string $delimiter = ','): array
{
$result = [];
foreach ($data as $value) {
- $result[] = explode($delimiter, $value) ?: [];
+ // @phpstan-ignore-next-line
+ $result[] = explode($delimiter, $value) ? explode($delimiter, $value) : [];
}
return !empty($result) ? array_merge([], ...$result) : [];
@@ -357,6 +363,7 @@ function ($value) {
}
// Attribute does not exists so just return value
+ // @phpstan-ignore-next-line
if (!$attribute || !$attribute->getId()) {
return $values;
}
@@ -367,6 +374,7 @@ function ($value) {
}
// Explode values if source is used (multi select)
+ // @phpstan-ignore-next-line
$values = $this->explodeValues($values);
try {
$attributeSource = $attribute->getSource();
@@ -375,6 +383,7 @@ function ($value) {
return $values;
}
+ // @phpstan-ignore-next-line
if (!$attributeSource instanceof SourceInterface) {
return $values;
}
diff --git a/Model/Write/Products/Collection.php b/Model/Write/Products/Collection.php
index 4be6180..2c14fc9 100644
--- a/Model/Write/Products/Collection.php
+++ b/Model/Write/Products/Collection.php
@@ -1,4 +1,4 @@
-getId();
$skus[] = $entity->getAttribute('sku', false);
- if ($entity instanceof CompositeExportEntityInterface) {
- foreach ($entity->getAllChildren() as $child) {
- $ids[] = $child->getId();
- $skus[] = $child->getAttribute('sku', false);
- }
+ if (!($entity instanceof CompositeExportEntityInterface)) {
+ continue;
+ }
+
+ foreach ($entity->getAllChildren() as $child) {
+ $ids[] = $child->getId();
+ $skus[] = $child->getAttribute('sku', false);
}
}
// Make unique
$this->ids = array_flip($ids);
+ // @phpstan-ignore-next-line
$this->skus = array_flip($skus);
}
diff --git a/Model/Write/Products/CollectionDecorator/CategoryReference.php b/Model/Write/Products/CollectionDecorator/CategoryReference.php
index bc33678..ba5a200 100644
--- a/Model/Write/Products/CollectionDecorator/CategoryReference.php
+++ b/Model/Write/Products/CollectionDecorator/CategoryReference.php
@@ -1,4 +1,4 @@
-where('product_id IN(' . implode(',', $collection->getIds()) . ')');
$resultSet = $select->query();
+ // @phpstan-ignore-next-line
while ($row = $resultSet->fetch()) {
$entityId = (int) $row['product_id'];
$entity = $collection->get($entityId);
diff --git a/Model/Write/Products/CollectionDecorator/Children.php b/Model/Write/Products/CollectionDecorator/Children.php
index b51ccf4..9fefd6c 100644
--- a/Model/Write/Products/CollectionDecorator/Children.php
+++ b/Model/Write/Products/CollectionDecorator/Children.php
@@ -1,4 +1,4 @@
-query();
+ // @phpstan-ignore-next-line
while ($row = $query->fetch()) {
$bundleOption = new ChildOptions(
(int) $row['option_id'],
- (bool) $row['required']
+ (bool) $row['required'] // @phpstan-ignore-line
);
$this->addChild(
$collection,
@@ -251,6 +252,7 @@ protected function addLinkChildren(
}
$query = $select->query();
+ // @phpstan-ignore-next-line
while ($row = $query->fetch()) {
$this->addChild($collection, (int) $row['product_id'], (int) $row['linked_product_id']);
}
@@ -286,6 +288,7 @@ protected function addConfigurableChildren(
}
$query = $select->query();
+ // @phpstan-ignore-next-line
while ($row = $query->fetch()) {
$this->addChild($collection, (int) $row['parent_id'], (int) $row['product_id']);
}
@@ -331,6 +334,7 @@ protected function addChild(
if ($this->config->isGroupedExport($collection->getStore())) {
$childEntity = $collection->get($childId);
+ // @phpstan-ignore-next-line
$childEntity->setGroupCode($parentId);
$childEntity->addAttribute(
'parent_url_key',
diff --git a/Model/Write/Products/CollectionDecorator/ChildrenAttributes.php b/Model/Write/Products/CollectionDecorator/ChildrenAttributes.php
index 0dec318..cce8c3f 100644
--- a/Model/Write/Products/CollectionDecorator/ChildrenAttributes.php
+++ b/Model/Write/Products/CollectionDecorator/ChildrenAttributes.php
@@ -1,4 +1,4 @@
-config->getDateAttributes(), true)) {
+ // @phpstan-ignore-next-line
$exportEntity->addDate($attributeData['attribute'], $attributeData['value']);
continue;
}
diff --git a/Model/Write/Products/CollectionDecorator/DecoratorInterface.php b/Model/Write/Products/CollectionDecorator/DecoratorInterface.php
index ffbce86..08025a0 100644
--- a/Model/Write/Products/CollectionDecorator/DecoratorInterface.php
+++ b/Model/Write/Products/CollectionDecorator/DecoratorInterface.php
@@ -1,4 +1,4 @@
-getWebsiteId();
$priceSelect = $this->createPriceSelect($collection->getIds(), (int)$websiteId);
+ // @phpstan-ignore-next-line
$priceQueryResult = $priceSelect->getSelect()->query()->fetchAll();
$currency = $store->getCurrentCurrency();
@@ -190,7 +192,7 @@ protected function getPriceValue(array $priceData, array $priceFields): float
}
/**
- * @param DataObject$product
+ * @param DataObject $product
* @return bool
*/
protected function isGroupedProduct(DataObject $product): bool
@@ -273,8 +275,9 @@ protected function calculateBundleProductPrice(int $entityId): array
return $price;
}
+ // @phpstan-ignore-next-line
$selections = $product->getTypeInstance()->getSelectionsCollection(
- $product->getTypeInstance()->getOptionsIds($product),
+ $product->getTypeInstance()->getOptionsIds($product), // @phpstan-ignore-line
$product
);
diff --git a/Model/Write/Products/CollectionDecorator/Review.php b/Model/Write/Products/CollectionDecorator/Review.php
index ab66cce..d54d428 100644
--- a/Model/Write/Products/CollectionDecorator/Review.php
+++ b/Model/Write/Products/CollectionDecorator/Review.php
@@ -1,9 +1,8 @@
-metaData = $metaData;
+ // @phpstan-ignore-next-line
$this->stockMapProviders = $stockMapProviders;
$this->stockItemFactory = $stockItemFactory;
$this->config = $config;
@@ -96,15 +97,18 @@ protected function addStockItems(int $storeId, Collection|StockCollection $colle
}
$stockMapProvider = $this->resolveStockMapProvider();
+ // @phpstan-ignore-next-line
$stockItemMap = $stockMapProvider->getStockItemMap($collection, $storeId);
foreach ($collection as $entity) {
$this->assignStockItem($stockItemMap, $entity);
- if ($entity instanceof CompositeExportEntityInterface) {
- foreach ($entity->getAllChildren() as $childEntity) {
- $this->assignStockItem($stockItemMap, $childEntity);
- }
+ if (!($entity instanceof CompositeExportEntityInterface)) {
+ continue;
+ }
+
+ foreach ($entity->getAllChildren() as $childEntity) {
+ $this->assignStockItem($stockItemMap, $childEntity);
}
}
}
@@ -159,7 +163,7 @@ protected function calculateStockPercentage(ExportEntity|StockExportEntity $enti
}
$inStockChildrenCount = \count(\array_filter($children, [$this, 'isInStock']));
- return round(($inStockChildrenCount / $childrenCount) * 100, 2);
+ return round($inStockChildrenCount / $childrenCount * 100, 2);
}
/**
@@ -169,6 +173,7 @@ protected function calculateStockPercentage(ExportEntity|StockExportEntity $enti
protected function isInStock(ExportEntity|StockExportEntity $entity): bool
{
$stockItem = $entity->getStockItem();
+ // @phpstan-ignore-next-line
return (int)(!$stockItem || $stockItem->getIsInStock());
}
@@ -184,6 +189,7 @@ protected function resolveStockMapProvider(): StockMapProviderInterface
$version = $this->metaData->getVersion();
// In case of magento 2.2.X use magento stock items
if (version_compare($version, '2.3.0', '<')) {
+ // @phpstan-ignore-next-line
return $this->stockMapProviders['stockItemMapProvider'];
}
@@ -192,10 +198,12 @@ protected function resolveStockMapProvider(): StockMapProviderInterface
!$this->moduleManager->isEnabled('Magento_Inventory') ||
!$this->moduleManager->isEnabled('Magento_InventoryApi')
) {
+ // @phpstan-ignore-next-line
return $this->stockMapProviders['stockItemMapProvider'];
}
// Use sourceItems to determine stock
+ // @phpstan-ignore-next-line
return $this->stockMapProviders['sourceItemMapProvider'];
}
}
diff --git a/Model/Write/Products/CollectionDecorator/StockData/SourceItemMapProvider.php b/Model/Write/Products/CollectionDecorator/StockData/SourceItemMapProvider.php
index 7cbf845..677c6c7 100644
--- a/Model/Write/Products/CollectionDecorator/StockData/SourceItemMapProvider.php
+++ b/Model/Write/Products/CollectionDecorator/StockData/SourceItemMapProvider.php
@@ -1,4 +1,4 @@
-query();
$map = [];
+ // @phpstan-ignore-next-line
while ($row = $result->fetch()) {
$map[$row['product_entity_id']] = $this->getTweakwiseStockItem($row);
}
@@ -201,6 +202,7 @@ public function getStockItemMap(Collection|StockCollection $collection): array
*/
protected function getStockSourceProvider(): GetSourcesAssignedToStockOrderedByPriorityInterface
{
+ // @phpstan-ignore-next-line
if (!$this->stockSourceProvider) {
$this->stockSourceProvider = $this->stockSourceProviderFactory->create();
}
@@ -213,6 +215,7 @@ protected function getStockSourceProvider(): GetSourcesAssignedToStockOrderedByP
*/
protected function getDefaultStockProvider(): DefaultStockProviderInterface
{
+ // @phpstan-ignore-next-line
if (!$this->defaultStockProvider) {
$this->defaultStockProvider = $this->defaultStockProviderFactory->create();
}
@@ -227,6 +230,7 @@ protected function getDefaultStockProvider(): DefaultStockProviderInterface
*/
protected function getStockIdForStoreId(Store $store): ?int
{
+ // @phpstan-ignore-next-line
$websiteCode = $store->getWebsite()->getCode();
return $this->getStockResolver()->execute('website', $websiteCode)->getStockId();
}
@@ -239,6 +243,7 @@ protected function getStockIdForStoreId(Store $store): ?int
*/
protected function getStockResolver(): StockResolverInterface
{
+ // @phpstan-ignore-next-line
if (!$this->stockResolver) {
$this->stockResolver = $this->stockResolverFactory->create();
}
diff --git a/Model/Write/Products/CollectionDecorator/StockData/StockItemMapProvider.php b/Model/Write/Products/CollectionDecorator/StockData/StockItemMapProvider.php
index 4f3bde1..8489ca2 100644
--- a/Model/Write/Products/CollectionDecorator/StockData/StockItemMapProvider.php
+++ b/Model/Write/Products/CollectionDecorator/StockData/StockItemMapProvider.php
@@ -1,4 +1,4 @@
-criteriaFactory->create();
+ // @phpstan-ignore-next-line
$criteria->setProductsFilter([$entityIds]);
$items = $this->stockItemRepository->getList($criteria)->getItems();
@@ -71,6 +72,7 @@ public function getStockItemMap(Collection|StockCollection $collection): array
$map[$productId] = $tweakwiseStockItem;
}
+ // @phpstan-ignore-next-line
return $map;
}
diff --git a/Model/Write/Products/CollectionDecorator/StockData/StockMapProviderInterface.php b/Model/Write/Products/CollectionDecorator/StockData/StockMapProviderInterface.php
index 31e9a94..aad1cb9 100644
--- a/Model/Write/Products/CollectionDecorator/StockData/StockMapProviderInterface.php
+++ b/Model/Write/Products/CollectionDecorator/StockData/StockMapProviderInterface.php
@@ -1,10 +1,9 @@
-where('product_id in(' . implode(',', $collection->getIds()) . ')');
$query = $select->query();
+ // @phpstan-ignore-next-line
while ($row = $query->fetch()) {
$productId = (int)$row['product_id'];
$collection->get($productId)->addLinkedWebsiteId((int)$row['website_id']);
diff --git a/Model/Write/Products/CompositeExportEntityInterface.php b/Model/Write/Products/CompositeExportEntityInterface.php
index 6eff0b6..514835f 100644
--- a/Model/Write/Products/CompositeExportEntityInterface.php
+++ b/Model/Write/Products/CompositeExportEntityInterface.php
@@ -1,4 +1,4 @@
-attributes[$attribute]));
if (
- ($dateFieldType === DateFieldType::MIN && $valueTime < $currentTime) ||
- ($dateFieldType === DateFieldType::MAX && $valueTime > $currentTime)
+ ($dateFieldType !== DateFieldType::MIN || $valueTime >= $currentTime) &&
+ ($dateFieldType !== DateFieldType::MAX || $valueTime <= $currentTime)
) {
- $this->attributes[$attribute] = [$value];
+ return;
}
+
+ $this->attributes[$attribute] = [$value];
}
/**
@@ -376,9 +378,11 @@ public function addAttributeSetName(int $attributeSetId): void
{
$attributeSetNames = $this->helper->getAttributeSetNames();
- if (isset($attributeSetNames[$attributeSetId])) {
- $this->addAttribute('attribute_set_name', $attributeSetNames[$attributeSetId]);
+ if (!isset($attributeSetNames[$attributeSetId])) {
+ return;
}
+
+ $this->addAttribute('attribute_set_name', $attributeSetNames[$attributeSetId]);
}
/**
diff --git a/Model/Write/Products/ExportEntityBundle.php b/Model/Write/Products/ExportEntityBundle.php
index fbb8876..346ec19 100644
--- a/Model/Write/Products/ExportEntityBundle.php
+++ b/Model/Write/Products/ExportEntityBundle.php
@@ -1,4 +1,4 @@
-getStockItem()->getIsInStock();
- if (!$childOptions->isRequired()) {
- $optionGroups[$optionId]['is_in_stock'] = 1;
+ if ($childOptions->isRequired()) {
+ continue;
}
+
+ $optionGroups[$optionId]['is_in_stock'] = 1;
}
if (empty($optionGroups)) {
@@ -95,6 +97,6 @@ protected function shouldExportByChildStatus(): bool
$optionGroupStatus[$optionId] = $childStatus;
}
- return (empty($optionGroupStatus)) || array_product($optionGroupStatus) === 1;
+ return empty($optionGroupStatus) || array_product($optionGroupStatus) === 1;
}
}
diff --git a/Model/Write/Products/ExportEntityChild.php b/Model/Write/Products/ExportEntityChild.php
index fbba4fc..f06c935 100644
--- a/Model/Write/Products/ExportEntityChild.php
+++ b/Model/Write/Products/ExportEntityChild.php
@@ -1,4 +1,4 @@
-add($entity);
- if ($batch->count() === $this->batchSize) {
- // After PHP7+ we can use yield from
- foreach ($this->processBatch($batch) as $processedEntity) {
- yield $processedEntity;
- }
+ if ($batch->count() !== $this->batchSize) {
+ continue;
+ }
- $batch = $this->collectionFactory->create(['store' => $this->store]);
+ // After PHP7+ we can use yield from
+ foreach ($this->processBatch($batch) as $processedEntity) {
+ yield $processedEntity;
}
+
+ $batch = $this->collectionFactory->create(['store' => $this->store]);
}
// After PHP7+ we can use yield from
diff --git a/Model/Write/Products/IteratorInitializer.php b/Model/Write/Products/IteratorInitializer.php
index 2f310cf..73eda25 100644
--- a/Model/Write/Products/IteratorInitializer.php
+++ b/Model/Write/Products/IteratorInitializer.php
@@ -1,4 +1,4 @@
-iterator as $index => $data) {
$this->writeProduct($xml, $store->getId(), $data);
// Flush every so often
- if ($index % 100 === 0) {
- $writer->flush();
+ if ($index % 100 !== 0) {
+ continue;
}
+
+ $writer->flush();
}
// Flush any remaining products
@@ -198,6 +196,7 @@ protected function scalarValue($value)
}
if (is_numeric($value)) {
+ // @phpstan-ignore-next-line
$value = $this->normalizeExponent($value);
}
@@ -214,6 +213,7 @@ protected function scalarValue($value)
*/
protected function normalizeExponent($value)
{
+ // @phpstan-ignore-next-line
if (stripos($value, 'E+') !== false) {
// Assume integer value
$decimals = 0;
diff --git a/Model/Write/Stock/Collection.php b/Model/Write/Stock/Collection.php
index 54bd334..104b07a 100644
--- a/Model/Write/Stock/Collection.php
+++ b/Model/Write/Stock/Collection.php
@@ -1,4 +1,4 @@
-getId();
$skus[] = $entity->getAttribute('sku', false);
- if ($entity instanceof CompositeExportEntityInterface) {
- foreach ($entity->getAllChildren() as $child) {
- $ids[] = $child->getId();
- $skus[] = $child->getAttribute('sku', false);
- }
+ if (!($entity instanceof CompositeExportEntityInterface)) {
+ continue;
+ }
+
+ foreach ($entity->getAllChildren() as $child) {
+ $ids[] = $child->getId();
+ $skus[] = $child->getAttribute('sku', false);
}
}
// Make unique
$this->ids = array_flip($ids);
+ // @phpstan-ignore-next-line
$this->skus = array_flip($skus);
}
diff --git a/Model/Write/Stock/ExportEntity.php b/Model/Write/Stock/ExportEntity.php
index 1c434cb..ca2e88f 100644
--- a/Model/Write/Stock/ExportEntity.php
+++ b/Model/Write/Stock/ExportEntity.php
@@ -1,4 +1,4 @@
-getStockItem() !== null ? $this->getStockItem()->getIsInStock() : false;
}
diff --git a/Model/Write/Stock/ExportEntityFactory.php b/Model/Write/Stock/ExportEntityFactory.php
index c079227..9aec3db 100644
--- a/Model/Write/Stock/ExportEntityFactory.php
+++ b/Model/Write/Stock/ExportEntityFactory.php
@@ -1,4 +1,4 @@
-add($entity);
- if ($batch->count() === $this->batchSize) {
- // After PHP7+ we can use yield from
- foreach ($this->processBatch($batch) as $processedEntity) {
- yield $processedEntity;
- }
+ if ($batch->count() !== $this->batchSize) {
+ continue;
+ }
- $batch = $this->collectionFactory->create(['store' => $this->store]);
+ // After PHP7+ we can use yield from
+ foreach ($this->processBatch($batch) as $processedEntity) {
+ yield $processedEntity;
}
+
+ $batch = $this->collectionFactory->create(['store' => $this->store]);
}
// After PHP7+ we can use yield from
@@ -122,6 +123,7 @@ protected function processBatch(Collection $collection)
{
if ($collection->count()) {
foreach ($this->collectionDecorators as $decorator) {
+ // @phpstan-ignore-next-line
$decorator->decorate($collection);
}
}
diff --git a/Model/Write/Stock/IteratorInitializer.php b/Model/Write/Stock/IteratorInitializer.php
index cc58aaa..87d66cc 100644
--- a/Model/Write/Stock/IteratorInitializer.php
+++ b/Model/Write/Stock/IteratorInitializer.php
@@ -1,4 +1,4 @@
-storeManager = $storeManager;
$this->appState = $appState;
- $this->writers = $writers;
$this->composerInformation = $composerInformation;
- $this->driver = $driver;
}
/**
@@ -89,6 +77,7 @@ public function __construct(
*/
public function getNow(): DateTime
{
+ // @phpstan-ignore-next-line
if (!$this->now) {
$this->now = new DateTime();
}
@@ -156,6 +145,7 @@ public function write($resource, ?StoreInterface $store = null, ?string $type =
*/
protected function getXml(): XMLWriter
{
+ // @phpstan-ignore-next-line
if (!$this->xml) {
$xml = new XMLWriter();
$xml->openMemory();
@@ -177,7 +167,9 @@ protected function getXml(): XMLWriter
*/
protected function close(): void
{
+ // @phpstan-ignore-next-line
$this->xml = null;
+ // @phpstan-ignore-next-line
$this->resource = null;
}
@@ -195,11 +187,20 @@ public function __destruct()
public function flush(): void
{
$output = $this->getXml()->flush();
- if ($output) {
- $this->driver->fileWrite($this->resource, $output);
+ if (!$output) {
+ return;
}
+
+ // @phpstan-ignore-next-line
+ $this->driver->fileWrite($this->resource, $output);
}
+ /**
+ * @param StoreInterface|null $store
+ * @param string|null $type
+ * @return void
+ * phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
+ */
protected function startDocumentType(?StoreInterface $store = null, ?string $type = null)
{
if ($type === 'stock' || $type === 'price') {
@@ -265,16 +266,23 @@ protected function endDocument(): void
$this->flush();
}
- protected function determineWriters($type = null): void
+ /**
+ * @param $type
+ * @return void
+ * @SuppressWarnings("PHPMD.UnusedLocalVariable")
+ */
+ protected function determineWriters($type = null): void // @phpstan-ignore-line
{
if ($type === null) {
unset($this->writers['stock']);
unset($this->writers['price']);
} else {
foreach ($this->writers as $key => $value) {
- if ($type !== $key) {
- unset($this->writers[$key]);
+ if ($type === $key) {
+ continue;
}
+
+ unset($this->writers[$key]);
}
}
}
diff --git a/Model/Write/WriterInterface.php b/Model/Write/WriterInterface.php
index 60fff4b..9d03bc4 100644
--- a/Model/Write/WriterInterface.php
+++ b/Model/Write/WriterInterface.php
@@ -1,4 +1,4 @@
-xmlPrepare($value);
}
+ // @phpstan-ignore-next-line
$this->text((string) $value);
if (!is_numeric($value) && !empty($value)) {
@@ -63,6 +64,7 @@ protected function xmlPrepare($value)
public function addCategoryExport($categoryId): void
{
$categoryId = (int) $categoryId;
+ // @phpstan-ignore-next-line
$this->categories[$categoryId] = true;
}
diff --git a/Profiler/Driver/ConsoleDriver.php b/Profiler/Driver/ConsoleDriver.php
index ac89605..07de16c 100644
--- a/Profiler/Driver/ConsoleDriver.php
+++ b/Profiler/Driver/ConsoleDriver.php
@@ -1,4 +1,4 @@
-stat->start($timerId, microtime(true), memory_get_usage(true), memory_get_usage());
$this->display($timerId);
}
@@ -51,6 +53,7 @@ public function start($timerId, ?array $tags = null)
*/
public function stop($timerId)
{
+ // @phpstan-ignore-next-line
$this->stat->stop($timerId, microtime(true), memory_get_usage(true), memory_get_usage());
$this->display($timerId);
}
@@ -66,6 +69,7 @@ public function clear($timerId = null)
/**
* @param string $timerId
+ * @return void
*/
protected function display($timerId)
{
diff --git a/Test/Integration/Export/MultiStore/BasicTest.php b/Test/Integration/Export/MultiStore/BasicTest.php
index db1ca4e..09ea889 100644
--- a/Test/Integration/Export/MultiStore/BasicTest.php
+++ b/Test/Integration/Export/MultiStore/BasicTest.php
@@ -1,4 +1,4 @@
-create(StoreProvider::class);
+ $storeProvider = Bootstrap::getObjectManager()->create(StoreProvider::class); // @phpstan-ignore-line
$website = $storeProvider->createWebsite(['code' => self::STORE_WEBSITE_CODE]);
$group = $storeProvider->createStoreGroup($website, ['code' => self::STORE_GROUP_CODE]);
@@ -65,11 +66,12 @@ public static function createMultiStoreFixture()
/**
* Fixture for rollback multi store
+ * @return void
*/
public static function createMultistoryFixtureRollback()
{
/** @var StoreProvider $storeProvider */
- $storeProvider = Bootstrap::getObjectManager()->create(StoreProvider::class);
+ $storeProvider = Bootstrap::getObjectManager()->create(StoreProvider::class); // @phpstan-ignore-line
$storeProvider->removeStoreView(self::STORE_STORE_CODE);
$storeProvider->removeStoreGroup(self::STORE_GROUP_CODE);
diff --git a/Test/Integration/Export/Product/AttributeOptionTest.php b/Test/Integration/Export/Product/AttributeOptionTest.php
index 02c5ddf..6ffd1a9 100644
--- a/Test/Integration/Export/Product/AttributeOptionTest.php
+++ b/Test/Integration/Export/Product/AttributeOptionTest.php
@@ -1,4 +1,4 @@
-getInstalledMagentoPackages();
$version = $installedPackages['tweakwise/magento2-tweakwise-export']['version'];
$emptyFile = file_get_contents($file);
+ // @phpstan-ignore-next-line
$emptyFile = str_replace('GENERATED_BY', $version, $emptyFile);
$this->assertEquals($emptyFile, (string) $this->exportFeed());
@@ -37,6 +38,7 @@ public function testEmptyExport()
/**
* Test export with one product and check on product data
+ * @return void
*/
public function testOneProduct()
{
diff --git a/Test/Integration/Export/Product/Configurable/ChildExportedTest.php b/Test/Integration/Export/Product/Configurable/ChildExportedTest.php
index eeb4b34..8c11a26 100644
--- a/Test/Integration/Export/Product/Configurable/ChildExportedTest.php
+++ b/Test/Integration/Export/Product/Configurable/ChildExportedTest.php
@@ -1,4 +1,4 @@
-setConfig(StockConfiguration::XML_PATH_MANAGE_STOCK, false, 0);
+ // @phpstan-ignore-next-line
$this->setConfig(StockConfiguration::XML_PATH_SHOW_OUT_OF_STOCK, false, 0);
$product = $this->productData->create(['qty' => 0, 'is_in_stock' => 1]);
@@ -66,6 +71,7 @@ public function testDisableStockManagement()
/**
* - Product with qty > 0 but less then configured qty threshold should not be exported.
* - Product with qty > qty threshold should be exported.
+ * @return void
*/
public function testInStockWithQtyThreshold()
{
@@ -84,6 +90,7 @@ public function testInStockWithQtyThreshold()
/**
* - Product with qty < General qty threshold but qty threshold on product < qty should be exported.
* - Product with qty > General qty threshold but qty threshold on product > qty should not be exported.
+ * @return void
*/
public function testInStockWithQtyThresholdOnProduct()
{
diff --git a/Test/Integration/ExportTest.php b/Test/Integration/ExportTest.php
index 0564dbb..d60f139 100644
--- a/Test/Integration/ExportTest.php
+++ b/Test/Integration/ExportTest.php
@@ -1,4 +1,4 @@
-get($type);
}
@@ -37,19 +38,26 @@ protected function getObject(string $type)
*/
protected function createObject(string $type, array $arguments = [])
{
+ // @phpstan-ignore-next-line
return Bootstrap::getObjectManager()->create($type, $arguments);
}
/**
* Ensure all objects are destroyed
* @param string $type
+ * @return void
*/
protected function clearObject(string $type)
{
+ // @phpstan-ignore-next-line
$objectManager = Bootstrap::getObjectManager();
- if ($objectManager instanceof ObjectManager) {
- $objectManager->removeSharedInstance($type);
+ // @phpstan-ignore-next-line
+ if (!($objectManager instanceof ObjectManager)) {
+ return;
}
+
+ // @phpstan-ignore-next-line
+ $objectManager->removeSharedInstance($type);
}
/**
diff --git a/Test/TestCase.php b/Test/TestCase.php
index 23d3778..1ce36e3 100644
--- a/Test/TestCase.php
+++ b/Test/TestCase.php
@@ -1,4 +1,4 @@
- $value) {
$method = $this->getSetMethod($class, $field);
- if ($method) {
- $object->$method($value);
+ if (!$method) {
+ continue;
}
+
+ $object->$method($value);
}
return $object;
@@ -57,15 +56,19 @@ public function hydrate(array $data, $object)
* @return FilterInterface
* @throws InvalidArgumentException
*/
- protected function getFieldToMethodFilter(): FilterInterface
+ protected function getFieldToMethodFilter(): FilterInterface // @phpstan-ignore-line
{
if ($this->fieldToMethodFilter === null) {
+ // @phpstan-ignore-next-line
$filter = new FilterChain();
+ // @phpstan-ignore-next-line
$filter->attach(new UnderscoreToCamelCase());
+ // @phpstan-ignore-next-line
$this->fieldToMethodFilter = $filter;
}
+ // @phpstan-ignore-next-line
return $this->fieldToMethodFilter;
}
@@ -76,7 +79,9 @@ protected function getFieldToMethodFilter(): FilterInterface
*/
protected function getReflectionClass(string $class): ReflectionClass
{
+ // @phpstan-ignore-next-line
if (!isset($this->reflectionCache[$class])) {
+ // @phpstan-ignore-next-line
$this->reflectionCache[$class] = new ReflectionClass($class);
}
@@ -88,16 +93,16 @@ protected function getReflectionClass(string $class): ReflectionClass
* @param string $field
* @return string|false
* @throws ReflectionException
- * @throws InvalidArgumentException
- * @throws RuntimeException
*/
protected function getSetMethod(string $class, string $field)
{
$key = $class . $field;
if (!isset($this->methodCache[$key])) {
+ // @phpstan-ignore-next-line
$method = 'set' . $this->getFieldToMethodFilter()->filter($field);
$reflection = $this->getReflectionClass($class);
+ // @phpstan-ignore-next-line
$this->methodCache[$key] = $reflection->hasMethod($method) ? $method : false;
}
diff --git a/TestHelper/Data/Product/AttributeProvider.php b/TestHelper/Data/Product/AttributeProvider.php
index 4cf5a27..bc3c09b 100644
--- a/TestHelper/Data/Product/AttributeProvider.php
+++ b/TestHelper/Data/Product/AttributeProvider.php
@@ -1,4 +1,4 @@
-setExtensionAttributes($extensionAttributes);
$product = $this->productRepository->save($product);
+ // @phpstan-ignore-next-line
$product->addData([self::GENERATED_CHILD_PRODUCTS => $simpleProducts]);
return $product;
}
@@ -141,14 +142,16 @@ protected function createSimpleProduct(array $data, array $configurableAttribute
sprintf(
'Attribute code %s does not exists in simple data %s',
$attributeCode,
- Json::encode($data)
+ Json::encode($data) // @phpstan-ignore-line
)
);
}
- if (!\is_int($data[$attributeCode])) {
- $data[$attributeCode] = $this->attributeProvider->getOptionId($attributeCode, $data[$attributeCode]);
+ if (\is_int($data[$attributeCode])) {
+ continue;
}
+
+ $data[$attributeCode] = $this->attributeProvider->getOptionId($attributeCode, $data[$attributeCode]);
}
if (!isset($data['visibility'])) {
diff --git a/TestHelper/Data/ProductProvider.php b/TestHelper/Data/ProductProvider.php
index 78de048..c46efec 100644
--- a/TestHelper/Data/ProductProvider.php
+++ b/TestHelper/Data/ProductProvider.php
@@ -1,4 +1,4 @@
-save();
return $website;
@@ -202,6 +203,7 @@ public function createStoreGroup(WebsiteInterface $website = null, array $data =
return $existingGroup;
}
+ // @phpstan-ignore-next-line
$group->save();
return $group;
@@ -261,6 +263,7 @@ public function createStoreView(GroupInterface $group = null, array $data = []):
$store->setWebsiteId($group->getWebsiteId());
$store->setGroupId($group->getId());
$store->setSortOrder(10);
+ // @phpstan-ignore-next-line
$store->setIsActive(true);
$this->hydrator->hydrate($data, $store);
@@ -270,6 +273,7 @@ public function createStoreView(GroupInterface $group = null, array $data = []):
return $existingStore;
}
+ // @phpstan-ignore-next-line
$store->save();
$this->reindex();
@@ -303,6 +307,7 @@ public function removeStoreView(string $code): bool
/**
* Reindex flat and full text so we have the required tables
+ * @return void
*/
protected function reindex()
{
diff --git a/TestHelper/FeedData.php b/TestHelper/FeedData.php
index 94682ea..33d4046 100644
--- a/TestHelper/FeedData.php
+++ b/TestHelper/FeedData.php
@@ -1,4 +1,4 @@
-products = [];
$xml = simplexml_load_string($this->feed);
+ // @phpstan-ignore-next-line
foreach ($xml->xpath('//category') as $element) {
$id = (string) $element->id;
+ // @phpstan-ignore-next-line
$this->products[$id] = $this->categoryDataFactory->create(['test' => $this->test, 'element' => $element]);
}
}
/**
* Parse product data
+ * @return void
*/
protected function parseProducts()
{
@@ -187,6 +192,7 @@ protected function parseProducts()
$this->products = [];
$xml = simplexml_load_string($this->feed);
+ // @phpstan-ignore-next-line
foreach ($xml->xpath('//item') as $element) {
$id = (string) $element->id;
$this->products[$id] = $this->productDataFactory->create(['test' => $this->test, 'element' => $element]);
diff --git a/TestHelper/FeedData/CategoryData.php b/TestHelper/FeedData/CategoryData.php
index c890fb4..b6f89da 100644
--- a/TestHelper/FeedData/CategoryData.php
+++ b/TestHelper/FeedData/CategoryData.php
@@ -1,4 +1,4 @@
-
- # is defined.
- - /^phpcs.xml$/
- - /^phpmd.xml$/
- - /^phpunit.xml$/
- - /^pdepend.xml$/
-
- yamllint.parse_constant: true
-
- phpcs.standard: ./phpcs.xml
- phpcs.triggered_by: [php,phtml]
-
- phplint.exclude: ['vendor']
- phplint.jobs: ~
- phplint.short_open_tag: false
- phplint.ignore_patterns: [ ]
- phplint.triggered_by: ['php']
-
- phpmd.exclude: []
- phpmd.ruleset:
- - ./phpmd.xml
- phpmd.triggered_by: [php]
-
- phpstan.autoload_file: ~
- phpstan.configuration: ./phpstan.neon
- phpstan.level: 4
- phpstan.triggered_by: [php]
-
- phpunit.config_file: ./phpunit.xml
-
- securitychecker.lockfile: ./composer.lock
- securitychecker.run_always: true
-
- git_blacklist.keywords:
- - "die("
- - "dd("
- - "var_dump("
- - "console.log("
- - "print_r("
- - "phpinfo("
- - "exit("
- - "exit;"
- - "<<<<<<<"
- - ">>>>>>>"
- - "======="
- - "
-
-
-
- memory
-
-
-
diff --git a/phpcs.xml b/phpcs.xml
deleted file mode 100644
index 1b47977..0000000
--- a/phpcs.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
- PHPCS
-
-
-
-
-
-
-
-
-
-
-
-
-
-
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/phpmd.xml b/phpmd.xml
deleted file mode 100644
index 1b454e9..0000000
--- a/phpmd.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
- PHPMD
-
-
-
diff --git a/phpstan.neon b/phpstan.neon
index 9314954..fb3ba23 100644
--- a/phpstan.neon
+++ b/phpstan.neon
@@ -1,3 +1,27 @@
+services:
+ - class: Emico\CodeQuality\PHPStan\VarModelExtension
+ tags:
+ - phpstan.broker.methodsClassReflectionExtension
+
parameters:
- excludePaths:
-# - %rootDir%/../../../path/to/exclude/*
+ 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/registration.php b/registration.php
index f8f0e7c..956be54 100644
--- a/registration.php
+++ b/registration.php
@@ -1,4 +1,4 @@
-