Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Testing Suite
name: GrumPHP
on: [push]
jobs:
linter:
Expand All @@ -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
3 changes: 3 additions & 0 deletions .grumphpinclude
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Add all files which should be included in here.
# Patterns are equal to .gitignore
*.php
17 changes: 5 additions & 12 deletions App/Response/FeedContent.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing

/**
* Tweakwise (https://www.tweakwise.com/) - All Rights Reserved
Expand All @@ -13,7 +13,6 @@
use Magento\Store\Api\Data\StoreInterface;
use Tweakwise\Magento2TweakwiseExport\Model\Export;
use Tweakwise\Magento2TweakwiseExport\Model\Logger;
use Magento\Store\Model\StoreManager;
use Exception;

/**
Expand All @@ -33,14 +32,10 @@ class FeedContent
*/
protected $log;

protected $type;

protected $store;

/**
* @var File
* @var StoreInterface|null
*/
protected File $driver;
protected $store;

/**
* SomeFeedResponse constructor.
Expand All @@ -54,15 +49,13 @@ class FeedContent
public function __construct(
Export $export,
Logger $log,
File $driver,
protected File $driver,
?StoreInterface $store = null,
$type = null
protected $type = null
) {
$this->export = $export;
$this->log = $log;
$this->type = $type;
$this->store = $store;
$this->driver = $driver;
}

/**
Expand Down
5 changes: 3 additions & 2 deletions Block/Config/Form/Field/ExportPriceStart.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing

/**
* Tweakwise (https://www.tweakwise.com/) - All Rights Reserved
Expand Down Expand Up @@ -27,6 +27,7 @@ class ExportPriceStart extends Field
* @param AbstractElement $element
* @return string
* @throws LocalizedException
* phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
*/
protected function _getElementHtml(AbstractElement $element): string
{
Expand All @@ -35,7 +36,7 @@ protected function _getElementHtml(AbstractElement $element): string
$button->setData(
[
'label' => __('Schedule'),
'onclick' => "setLocation('{$this->getUrl('tweakwise/export/trigger/type/price')}')",
'onclick' => sprintf("setLocation('%s')", $this->getUrl('tweakwise/export/trigger/type/price')),
]
);

Expand Down
6 changes: 3 additions & 3 deletions Block/Config/Form/Field/ExportStart.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing

/**
* Tweakwise (https://www.tweakwise.com/) - All Rights Reserved
Expand All @@ -10,7 +10,6 @@
namespace Tweakwise\Magento2TweakwiseExport\Block\Config\Form\Field;

use Magento\Backend\Block\Widget\Button;
use Magento\Config\Block\System\Config\Form;
use Magento\Config\Block\System\Config\Form\Field;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Magento\Framework\Exception\LocalizedException;
Expand All @@ -21,6 +20,7 @@ class ExportStart extends Field
* @param AbstractElement $element
* @return string
* @throws LocalizedException
* phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
*/
protected function _getElementHtml(AbstractElement $element): string
{
Expand All @@ -29,7 +29,7 @@ protected function _getElementHtml(AbstractElement $element): string
$button->setData(
[
'label' => __('Schedule'),
'onclick' => "setLocation('{$this->getUrl('tweakwise/export/trigger')}')",
'onclick' => sprintf("setLocation('%s')", $this->getUrl('tweakwise/export/trigger')),
]
);

Expand Down
3 changes: 2 additions & 1 deletion Block/Config/Form/Field/ExportState.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing

/**
* Tweakwise (https://www.tweakwise.com/) - All Rights Reserved
Expand Down Expand Up @@ -38,6 +38,7 @@ public function __construct(
/**
* @param AbstractElement $element
* @return string
* phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
*/
protected function _getElementHtml(AbstractElement $element): string
{
Expand Down
3 changes: 2 additions & 1 deletion Block/Config/Form/Field/ExportStatePrice.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing

/**
* Tweakwise (https://www.tweakwise.com/) - All Rights Reserved
Expand Down Expand Up @@ -38,6 +38,7 @@ public function __construct(
/**
* @param AbstractElement $element
* @return string
* phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
*/
protected function _getElementHtml(AbstractElement $element): string
{
Expand Down
3 changes: 2 additions & 1 deletion Block/Config/Form/Field/ExportStateStock.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing

/**
* Tweakwise (https://www.tweakwise.com/) - All Rights Reserved
Expand Down Expand Up @@ -38,6 +38,7 @@ public function __construct(
/**
* @param AbstractElement $element
* @return string
* phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
*/
protected function _getElementHtml(AbstractElement $element): string
{
Expand Down
5 changes: 3 additions & 2 deletions Block/Config/Form/Field/ExportStockStart.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing

/**
* Tweakwise (https://www.tweakwise.com/) - All Rights Reserved
Expand Down Expand Up @@ -27,6 +27,7 @@ class ExportStockStart extends Field
* @param AbstractElement $element
* @return string
* @throws LocalizedException
* phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
*/
protected function _getElementHtml(AbstractElement $element): string
{
Expand All @@ -35,7 +36,7 @@ protected function _getElementHtml(AbstractElement $element): string
$button->setData(
[
'label' => __('Schedule'),
'onclick' => "setLocation('{$this->getUrl('tweakwise/export/trigger/type/stock')}')",
'onclick' => sprintf("setLocation('%s')", $this->getUrl('tweakwise/export/trigger/type/stock')),
]
);

Expand Down
34 changes: 21 additions & 13 deletions Console/Command/ExportCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

<?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing
/**
* Tweakwise (https://www.tweakwise.com/) - All Rights Reserved
*
Expand Down Expand Up @@ -52,6 +51,7 @@ class ExportCommand extends Command
*/
protected $log;

// @phpstan-ignore-next-line
protected $type;

/**
Expand Down Expand Up @@ -109,8 +109,8 @@ protected function configure(): void
* {@inheritdoc}
* @throws Exception
* phpcs:disable Generic.Metrics.CyclomaticComplexity.TooHigh
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings("PHPMD.CyclomaticComplexity")
* @SuppressWarnings("PHPMD.ExcessiveMethodLength")
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
Expand All @@ -132,22 +132,24 @@ function () use ($input, $output) {
$type = $this->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');

Expand All @@ -167,7 +169,7 @@ function () use ($input, $output) {

return -1;
}

// @phpstan-ignore-next-line
if (!$this->config->isEnabled($store)) {
$output->writeln('<error>Tweakwise export does not enabled in this store</error>');

Expand All @@ -178,9 +180,9 @@ function () use ($input, $output) {
$feedFile = $this->config->getDefaultFeedFile($store, $type);
}

$output->writeln("<info>generatig feed for {$store->getCode()}</info>");
$output->writeln(sprintf('<info>generatig feed for %s</info>', $store->getCode()));
$this->export->generateToFile($feedFile, $validate, $store, $type);
$output->writeln("<info>feed file: {$feedFile}</info>");
$output->writeln(sprintf('<info>feed file: %s</info>', $feedFile));
} else {
if ($storeCode) {
$output->writeln('<error>Store level export disabled, remove --store parameter</error>');
Expand All @@ -191,9 +193,9 @@ function () use ($input, $output) {
$feedFile = $this->config->getDefaultFeedFile(null, $type);
}

$output->writeln("<info>generating single feed for export enabled stores</info>");
$output->writeln('<info>generating single feed for export enabled stores</info>');
$this->export->generateToFile($feedFile, $validate, null, $type);
$output->writeln("<info>feed file: {$feedFile}</info>");
$output->writeln(sprintf('<info>feed file: %s</info>', $feedFile));
}

$generateTime = round(microtime(true) - $startTime, 2);
Expand All @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion Controller/Adminhtml/Export/Trigger.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing

/**
* Tweakwise (https://www.tweakwise.com/) - All Rights Reserved
Expand Down
2 changes: 1 addition & 1 deletion Controller/Cache/Flush.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing

namespace Tweakwise\Magento2TweakwiseExport\Controller\Cache;

Expand Down
14 changes: 5 additions & 9 deletions Controller/Feed/Export.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing

/**
* Tweakwise (https://www.tweakwise.com/) - All Rights Reserved
Expand Down Expand Up @@ -53,11 +53,6 @@ class Export implements ActionInterface
*/
protected $storeManager;

/**
* @var File
*/
protected File $driver;

/**
* Export constructor.
*
Expand All @@ -76,15 +71,15 @@ public function __construct(
RequestValidator $requestValidator,
ResponseFactory $responseFactory,
StoreManagerInterface $storeManager,
File $driver
protected File $driver
) {
$this->context = $context;
// @phpstan-ignore-next-line
$this->export = $export;
$this->log = $log;
$this->requestValidator = $requestValidator;
$this->responseFactory = $responseFactory;
$this->storeManager = $storeManager;
$this->driver = $driver;
}

/**
Expand All @@ -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
{
Expand All @@ -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();
Expand Down
15 changes: 8 additions & 7 deletions Cron/Export.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing

/**
* Tweakwise (https://www.tweakwise.com/) - All Rights Reserved
Expand All @@ -9,8 +9,6 @@

namespace Tweakwise\Magento2TweakwiseExport\Cron;

use Tweakwise\Magento2TweakwiseExport\Console\Command\ExportCommand;
use Tweakwise\Magento2TweakwiseExport\Exception\FeedException;
use Tweakwise\Magento2TweakwiseExport\Model\Config;
use Tweakwise\Magento2TweakwiseExport\Model\Export as ExportService;
use Tweakwise\Magento2TweakwiseExport\Model\Logger;
Expand Down Expand Up @@ -81,7 +79,7 @@ public function executePrice(): void
* Export feed
* @throws \Exception
*/
public function generateFeed($type = null): void
public function generateFeed($type = null): void // @phpstan-ignore-line
{
if ($this->config->isRealTime()) {
$this->log->debug('Export set to real time, skipping cron export.');
Expand All @@ -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;
Expand Down
Loading