From 2213d3137198cddb847baa4a24b9d3e537ecede6 Mon Sep 17 00:00:00 2001 From: Dominic Watts Date: Tue, 24 Aug 2021 23:33:18 +0100 Subject: [PATCH 1/2] Additional test --- .github/workflows/phpcsfixer.yml | 9 ++++++++ .php-cs-fixer.dist.php | 39 ++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 .github/workflows/phpcsfixer.yml create mode 100644 .php-cs-fixer.dist.php diff --git a/.github/workflows/phpcsfixer.yml b/.github/workflows/phpcsfixer.yml new file mode 100644 index 0000000..a228d9d --- /dev/null +++ b/.github/workflows/phpcsfixer.yml @@ -0,0 +1,9 @@ +name: php-cs-fixer +on: [push] +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - name: PHP CS Fixer + run: docker run --rm -v $PWD:/code domw/php-cs-fixer php-cs-fixer fix --dry-run --diff --stop-on-violation --allow-risky=yes ./ diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..8394fad --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,39 @@ +in('Console') + ->in('Helper') + ->name('*.phtml'); + +$config = new PhpCsFixer\Config(); +$config->setFinder($finder) + ->setRules([ + '@PSR2' => true, + 'array_syntax' => ['syntax' => 'short'], + 'concat_space' => ['spacing' => 'one'], + 'include' => true, + 'new_with_braces' => true, + 'no_empty_statement' => true, + 'no_extra_blank_lines' => true, + 'no_leading_import_slash' => true, + 'no_leading_namespace_whitespace' => true, + 'no_multiline_whitespace_around_double_arrow' => true, + 'multiline_whitespace_before_semicolons' => true, + 'no_singleline_whitespace_before_semicolons' => true, + 'no_trailing_comma_in_singleline_array' => true, + 'no_unused_imports' => true, + 'no_whitespace_in_blank_line' => true, + 'object_operator_without_whitespace' => true, + 'ordered_imports' => true, + 'standardize_not_equals' => true, + 'ternary_operator_spaces' => true, + ]); +return $config; From 7df8f9fd798a6c2bf7a415d4c950988558e083f5 Mon Sep 17 00:00:00 2001 From: Dominic Watts Date: Tue, 24 Aug 2021 23:43:34 +0100 Subject: [PATCH 2/2] Coding standards --- Console/Command/Category.php | 3 +++ Console/Command/Customer.php | 3 +++ Console/Command/Order.php | 3 +++ Console/Command/Product.php | 3 +++ Console/Command/Review.php | 3 +++ Helper/Customer.php | 6 ++++-- Helper/Order.php | 8 +++----- Helper/Product.php | 6 ++++-- composer.json | 2 +- etc/module.xml | 2 +- 10 files changed, 28 insertions(+), 11 deletions(-) diff --git a/Console/Command/Category.php b/Console/Command/Category.php index bb95e29..a26a30a 100644 --- a/Console/Command/Category.php +++ b/Console/Command/Category.php @@ -86,6 +86,7 @@ public function __construct( /** * {@inheritdoc} + * @return int */ protected function execute( InputInterface $input, @@ -138,7 +139,9 @@ protected function execute( $progress->finish(); $this->output->writeln(''); $this->output->writeln('[' . $this->dateTime->gmtDate() . '] Finish'); + return Cli::RETURN_SUCCESS; } + return Cli::RETURN_FAILURE; } /** diff --git a/Console/Command/Customer.php b/Console/Command/Customer.php index 7705c81..7c6e2f3 100644 --- a/Console/Command/Customer.php +++ b/Console/Command/Customer.php @@ -85,6 +85,7 @@ public function __construct( /** * {@inheritdoc} + * @return int */ protected function execute( InputInterface $input, @@ -141,7 +142,9 @@ protected function execute( $progress->finish(); $this->output->writeln(''); $this->output->writeln('[' . $this->dateTime->gmtDate() . '] Finish'); + return Cli::RETURN_SUCCESS; } + return Cli::RETURN_FAILURE; } /** diff --git a/Console/Command/Order.php b/Console/Command/Order.php index 4e48f06..32f2f0a 100644 --- a/Console/Command/Order.php +++ b/Console/Command/Order.php @@ -87,6 +87,7 @@ public function __construct( /** * {@inheritdoc} + * @return int */ protected function execute( InputInterface $input, @@ -140,7 +141,9 @@ protected function execute( $progress->finish(); $this->output->writeln(''); $this->output->writeln('[' . $this->dateTime->gmtDate() . '] Finish'); + return Cli::RETURN_SUCCESS; } + return Cli::RETURN_FAILURE; } /** diff --git a/Console/Command/Product.php b/Console/Command/Product.php index 1c6f5e6..df24bff 100644 --- a/Console/Command/Product.php +++ b/Console/Command/Product.php @@ -89,6 +89,7 @@ public function __construct( /** * {@inheritdoc} + * @return int */ protected function execute( InputInterface $input, @@ -150,7 +151,9 @@ protected function execute( $progress->finish(); $this->output->writeln(''); $this->output->writeln('[' . $this->dateTime->gmtDate() . '] Finish'); + return Cli::RETURN_SUCCESS; } + return Cli::RETURN_FAILURE; } /** diff --git a/Console/Command/Review.php b/Console/Command/Review.php index 3d56fb2..7f6097b 100644 --- a/Console/Command/Review.php +++ b/Console/Command/Review.php @@ -86,6 +86,7 @@ public function __construct( /** * {@inheritdoc} + * @return int */ protected function execute( InputInterface $input, @@ -139,7 +140,9 @@ protected function execute( $progress->finish(); $this->output->writeln(''); $this->output->writeln('[' . $this->dateTime->gmtDate() . '] Finish'); + return Cli::RETURN_SUCCESS; } + return Cli::RETURN_FAILURE; } /** diff --git a/Helper/Customer.php b/Helper/Customer.php index fcf7765..d55667d 100644 --- a/Helper/Customer.php +++ b/Helper/Customer.php @@ -102,7 +102,7 @@ public function __construct( /** * Create random customer * @param int $websiteId - * @return \Magento\Customer\Api\Data\CustomerInterface + * @return \Magento\Customer\Api\Data\CustomerInterface|false */ public function createCustomer($websiteId = 1) { @@ -120,13 +120,14 @@ public function createCustomer($websiteId = 1) return $customer; } catch (\Exception $e) { $this->logger->critical($e); + return false; } } /** * Create address for supplied customerId. * @param \Magento\Customer\Model\Data\Customer $customer - * @return \Magento\Customer\Api\Data\AddressInterface + * @return \Magento\Customer\Api\Data\AddressInterface|false */ public function createCustomerAddress(\Magento\Customer\Model\Data\Customer $customer) { @@ -152,6 +153,7 @@ public function createCustomerAddress(\Magento\Customer\Model\Data\Customer $cus return $address; } catch (\Exception $e) { $this->logger->critical($e); + return false; } } } diff --git a/Helper/Order.php b/Helper/Order.php index 1e3e3ce..042c5cc 100644 --- a/Helper/Order.php +++ b/Helper/Order.php @@ -152,7 +152,7 @@ public function createOrder($storeId = 1, $customerId = null) try { $store = $this->storeManagerInterface->getStore($storeId); - + $websiteId = $store->getWebsiteId(); if ($customerId) { @@ -185,7 +185,6 @@ public function createOrder($storeId = 1, $customerId = null) $added = 0; foreach ($productIds as $productId) { - $product = $this->getProductById($productId); if ($product->isSalable()) { $qty = $this->stockItem->getStockQty($product->getId(), $websiteId); @@ -218,7 +217,7 @@ public function createOrder($storeId = 1, $customerId = null) $quote->collectTotals(); $quote = $this->cartRepositoryInterface->get($quote->getId()); - + $orderId = $this->cartManagementInterface->placeOrder($quote->getId()); $this->generateInvoice($orderId); if ($this->getRandomTrueOrFalse()) { @@ -226,7 +225,6 @@ public function createOrder($storeId = 1, $customerId = null) } return $orderId; - } catch (\Exception $e) { $this->logger->critical($e); return $e->getMessage(); @@ -279,7 +277,7 @@ public function generateShipment($orderId, $doNotify = true) if (!$order || !$order->canShip()) { return; } - + $orderShipment = $this->convertOrder->toShipment($order); foreach ($order->getAllItems() as $orderItem) { diff --git a/Helper/Product.php b/Helper/Product.php index e8d90cf..bee8e10 100644 --- a/Helper/Product.php +++ b/Helper/Product.php @@ -147,7 +147,7 @@ public function __construct( * @param int $websiteId * @param string $typeId * @param bool $applyImage - * @return \Magento\Catalog\Model\Product\Interceptor + * @return \Magento\Catalog\Model\Product\Interceptor|false */ public function createProduct( $websiteId = 1, @@ -205,13 +205,14 @@ public function createProduct( return $product; } catch (\Exception $e) { $this->logger->critical($e); + return false; } } /** * Reload product [might not actually need this]. * @param $product - * @return \Magento\Product\Model\Data\Product + * @return \Magento\Product\Model\Data\Product|false */ public function reloadProduct(Interceptor $product) { @@ -222,6 +223,7 @@ public function reloadProduct(Interceptor $product) return $product; } catch (\Exception $e) { $this->logger->critical($e); + return false; } } } diff --git a/composer.json b/composer.json index 1c89450..0d1aa9f 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "Console based fake data generator - just generate what you need", "type": "magento2-module", "license": "proprietary", - "version": "1.2.0", + "version": "1.2.1", "authors": [ { "name": "Dominic Xigen", diff --git a/etc/module.xml b/etc/module.xml index e2ce3b7..752d2fb 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,4 +1,4 @@ - +