Skip to content

Commit

Permalink
Code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
srenon committed May 8, 2020
1 parent ad5824d commit 8095b43
Show file tree
Hide file tree
Showing 15 changed files with 167 additions and 292 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: PHPCS
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: PHPCS
run: docker run --rm -v $PWD:/code:ro domw/phpcs phpcs --colors --standard=Magento2 --report=full,summary,gitblame --extensions=php,phtml ./
- name: compatibility
run: docker run --rm -v $PWD:/code:ro domw/phpcompatibility phpcs --standard=PHPCompatibility --runtime-set testVersion 5.6-7.3 --colors --warning-severity=0 --report=full,summary --extensions=php,phtml ./
18 changes: 1 addition & 17 deletions Block/Adminhtml/System/Config/Form/Composer/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,8 @@
use Magento\Framework\Filesystem\Directory\ReadFactory;
use Magento\Framework\Phrase;

/**
* Class Version
* @package MagePal\PreviewCheckoutSuccessPage\Block\Adminhtml\System\Config\Form\Composer
*/
class Version extends Field
{

/**
* @var DeploymentConfig
*/
Expand Down Expand Up @@ -65,7 +60,6 @@ public function __construct(
*
* @param AbstractElement $element
* @return string
* @throws LocalizedException
*/
public function render(AbstractElement $element)
{
Expand Down Expand Up @@ -96,16 +90,6 @@ public function getVersion()
return $this->getComposerVersion($this->getModuleName());
}

/**
* @return string
*/
public function getModuleName()
{
$classArray = explode('\\', get_class($this));

return count($classArray) > 2 ? "{$classArray[0]}_{$classArray[1]}" : '';
}

/**
* Get module composer version
*
Expand All @@ -128,7 +112,7 @@ public function getComposerVersion($moduleName)
return !empty($data->version) ? $data->version : __('Unknown');
}
} catch (Exception $e) {
//
return 'Unknown';
}

return 'Unknown';
Expand Down
30 changes: 21 additions & 9 deletions Block/Adminhtml/System/Config/Form/Field/OrderIncrement.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@
use Magento\Config\Block\System\Config\Form\Field;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Magento\Framework\DataObject;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
use Magento\Store\Api\Data\StoreInterface;

/**
* Class OrderIncrement
* @package MagePal\PreviewCheckoutSuccessPage\Block\Adminhtml\System\Config\Form\Field
* @method setElement($element)
* @method getElement()
* @method getForm()
*/
class OrderIncrement extends Field
{

/**
* @var CollectionFactory
*/
Expand All @@ -50,28 +52,35 @@ public function __construct(
/**
* Get the grid and scripts contents
*
* @param AbstractElement $element
* @param AbstractElement $element
* @return string
*/
protected function _getElementHtml(AbstractElement $element)
{
$this->setElement($element);

if (!$element->getEscapedValue()) {
try {
if (!$element->getEscapedValue()) {

/** @var Order $order */
$order = $this->getLastOrder();
/** @var Order $order */
$order = $this->getLastOrder();

if ($order->getId()) {
$element->setValue($order->getIncrementId());
if ($order->getId()) {
$element->setValue($order->getIncrementId());
}
}
} catch (\Exception $e) {
return parent::_getElementHtml($element);
}

return parent::_getElementHtml($element);
}

/**
* @return StoreInterface|null
* @throws LocalizedException
* @throws NoSuchEntityException
* @return \Magento\Store\Api\Data\StoreInterface|null
*/
public function getCurrentStore()
{
Expand All @@ -89,6 +98,9 @@ public function getCurrentStore()

/**
* @return DataObject
* @throws LocalizedException
* @throws NoSuchEntityException
* @return Order
*/
public function getLastOrder()
{
Expand Down
15 changes: 10 additions & 5 deletions Block/Adminhtml/System/Config/Form/Field/Preview.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
use Magento\Framework\Url;
use Magento\Store\Api\Data\StoreInterface;

/**
* Class Preview
* @package MagePal\PreviewCheckoutSuccessPage\Block\Adminhtml\System\Config\Form\Field
*/
class Preview extends Field
{
/**
Expand Down Expand Up @@ -44,7 +40,6 @@ public function __construct(
parent::__construct($context, $data);
}


/**
* @param AbstractElement $element
* @return string
Expand Down Expand Up @@ -115,4 +110,14 @@ public function getSuccessPageUrl()

return $this->urlHelper->setScope($store->getId())->getUrl('checkout/onepage/success', $routeParams);
}

/**
* @return string
*/
public function getSpinnerTemplate()
{
$value = '<div data-role=\"spinner\" style=\"text-align: center\"><div class=\"spinner\"><span></span><span>';
$value .= '</span><span></span><span></span><span></span><span></span><span></span><span></span></div></div>';
return $value;
}
}
88 changes: 0 additions & 88 deletions Block/Adminhtml/System/Config/Form/Module/Version.php

This file was deleted.

13 changes: 0 additions & 13 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,10 @@
use Magento\Store\Model\ScopeInterface;
use MagePal\PreviewCheckoutSuccessPage\Model\Config\Backend\ValidFor;

/**
* Class Data
* @package MagePal\PreviewCheckoutSuccessPage\Helper
*/
class Data extends AbstractHelper
{
const XML_PATH_ACTIVE = 'magepal_checkout/preview_success_page/active';

/**
* @param Context $context
*/
public function __construct(
Context $context
) {
parent::__construct($context);
}

/**
* Whether is active
*
Expand Down
12 changes: 4 additions & 8 deletions Model/Config/Backend/AccessCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Config\Value;
use Magento\Framework\Data\Collection\AbstractDb;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Math\Random;
use Magento\Framework\Model\Context;
use Magento\Framework\Model\ResourceModel\AbstractResource;
use Magento\Framework\Registry;

/**
* Class AccessCode
* @package MagePal\PreviewCheckoutSuccessPage\Model\Config\Backend
*/
class AccessCode extends Value
{

Expand All @@ -34,29 +31,28 @@ class AccessCode extends Value
* @param Registry $registry
* @param ScopeConfigInterface $config
* @param TypeListInterface $cacheTypeList
* @param Random $random
* @param AbstractResource|null $resource
* @param AbstractDb|null $resourceCollection
* @param Random $random
* @param array $data
*/
public function __construct(
Context $context,
Registry $registry,
ScopeConfigInterface $config,
TypeListInterface $cacheTypeList,
Random $random,
AbstractResource $resource = null,
AbstractDb $resourceCollection = null,
Random $random,
array $data = []

) {
$this->random = $random;
parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
}

/**
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
* @throws LocalizedException
*/
public function beforeSave()
{
Expand Down
7 changes: 1 addition & 6 deletions Model/Config/Backend/ModifyTimestamp.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
use Magento\Framework\Registry;
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;

/**
* Class ModifyTimestamp
* @package MagePal\PreviewCheckoutSuccessPage\Model\Config\Backend
*/
class ModifyTimestamp extends Value
{

Expand All @@ -44,11 +40,10 @@ public function __construct(
Registry $registry,
ScopeConfigInterface $config,
TypeListInterface $cacheTypeList,
TimezoneInterface $localeDate,
AbstractResource $resource = null,
AbstractDb $resourceCollection = null,
TimezoneInterface $localeDate,
array $data = []

) {
$this->localeDate = $localeDate;
parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
Expand Down
4 changes: 0 additions & 4 deletions Model/Config/Backend/ValidFor.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@

use Magento\Framework\App\Config\Value;

/**
* Class ValidFor
* @package MagePal\PreviewCheckoutSuccessPage\Model\Config\Backend
*/
class ValidFor extends Value
{
const MAX_ACCESS_TIME = 15;
Expand Down
5 changes: 0 additions & 5 deletions Plugin/Model/Session/SuccessValidatorPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
use MagePal\PreviewCheckoutSuccessPage\Helper\Data;

/**
* Class SuccessValidatorPlugin
* @package MagePal\PreviewCheckoutSuccessPage\Plugin\Model\Session
*/
class SuccessValidatorPlugin
{

/** @var Data */
protected $dataHelper;

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"magepal/magento2-checkout-success-misc-script":"Add miscellaneous HTML and scripts to your checkout success page"
},
"type": "magento2-module",
"version": "1.0.9",
"version": "1.1.0",
"autoload": {
"files": [
"registration.php"
Expand Down
Loading

0 comments on commit 8095b43

Please sign in to comment.