Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix coding standard on Refactored branch #800

Merged
Merged
50 changes: 45 additions & 5 deletions .github/workflows/coding-standard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: extdn/github-actions-m2/magento-coding-standard/8.1@master
with:
phpcs_severity: 10
Expand All @@ -18,15 +18,55 @@ jobs:
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: extdn/github-actions-m2/magento-mess-detector@master

phpstan:
name: M2 PHPStan
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v2
- uses: extdn/github-actions-m2/magento-phpstan/8.1@master
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
composer_name: buckaroo/magento2
php-version: 8.1
tools: composer:v2

- uses: actions/checkout@v3

- name: Validate composer json
run: composer validate

- name: Clear Composer cache
run: composer clear-cache

- name: Setup Magento
run: |
pull_number=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")
url="https://api.github.com/repos/buckaroo-it/Magento2/pulls/$pull_number/files"
echo $url
curl $url > files_changed
cat files_changed | grep '"filename"' | sed 's/\"filename\"\: \"//' | sed 's/\",//' | xargs ls
echo '{"http-basic": {"repo.magento.com": {"username": "${{ secrets.REPO_USERNAME }}","password": "${{ secrets.REPO_PASS }}"}}}' > auth.json
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.4.6-p2 ~/m246
mkdir -p ~/m246/app/code/Buckaroo/Magento2/
rsync -r --exclude='m246' ./ ~/m246/app/code/Buckaroo/Magento2/
cd ~/m246
bin/magento module:enable --all
bin/magento setup:di:compile

- name: Install PHPStan
run: |
cd ~/m246
composer require --dev phpstan/phpstan:^1.10
ls -la vendor/bin/

- name: Install Buckaroo SDK
run: |
cd ~/m246
composer require buckaroo/sdk

- name: Run PHPStan
run: |
cd ~/m246
vendor/bin/phpstan analyse --level 1 app/code/Buckaroo/Magento2/ -c dev/tests/static/testsuite/Magento/Test/Php/_files/phpstan/phpstan.neon
6 changes: 3 additions & 3 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- 3306:3306
options: --tmpfs /tmp:rw --tmpfs /var/lib/mysql:rw --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
es:
image: docker.io/wardenenv/elasticsearch:7.16
image: docker.io/wardenenv/elasticsearch:7.8
ports:
- 9200:9200
env:
Expand All @@ -27,10 +27,10 @@ jobs:
ES_JAVA_OPTS: "-Xms64m -Xmx512m"
options: --health-cmd="curl localhost:9200/_cluster/health?wait_for_status=yellow&timeout=60s" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: M2 Integration Tests with Magento 2 (Php 8.1)
uses: extdn/github-actions-m2/magento-integration-tests/8.1@master
with:
module_name: Buckaroo_Magento2
composer_name: buckaroo/magento2
ce_version: '2.4.4'
ce_version: '2.4.6'
2 changes: 1 addition & 1 deletion Api/Data/BuckarooGiftcardDataInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ public function getGiftcardModel(): Giftcard;
* @return BuckarooGiftcardDataInterface
*/
public function setGiftcardModel(Giftcard $giftcard): BuckarooGiftcardDataInterface;
}
}
2 changes: 1 addition & 1 deletion Api/Data/BuckarooResponseDataInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ interface BuckarooResponseDataInterface
public function getResponse(): TransactionResponse;

public function setResponse(TransactionResponse $transactionResponse): BuckarooResponseDataInterface;
}
}
2 changes: 1 addition & 1 deletion Api/PushProcessorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ interface PushProcessorInterface
* @return bool
*/
public function processPush(PushRequestInterface $pushRequest): bool;
}
}
5 changes: 2 additions & 3 deletions Block/Adminhtml/Config/Support/SupportTab.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class SupportTab extends Template implements RendererInterface
* Override the parent constructor to require our own dependencies.
*
* @param Context $context
* @param ModuleResource $moduleContext
* @param SoftwareData $softwareData
* @param Curl $curl
* @param array $data
*/
public function __construct(
Expand Down Expand Up @@ -118,8 +118,7 @@ public function phpVersionCheck()
$phpMajorMinor = $phpVersion[0] . '.' . $phpVersion[1];
$phpPatch = (int)$phpVersion[2];

if (
!isset($this->phpVersionSupport[$magentoMajorMinor]) ||
if (!isset($this->phpVersionSupport[$magentoMajorMinor]) ||
!isset($this->phpVersionSupport[$magentoMajorMinor][$phpMajorMinor])
) {
return 0;
Expand Down
84 changes: 44 additions & 40 deletions Block/Adminhtml/System/Config/Fieldset/Payment.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* NOTICE OF LICENSE
*
Expand All @@ -21,36 +20,43 @@

namespace Buckaroo\Magento2\Block\Adminhtml\System\Config\Fieldset;

use Magento\Backend\Block\Context;
use Magento\Backend\Model\Auth\Session;
use Magento\Config\Block\System\Config\Form\Fieldset;
use Magento\Config\Model\Config;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Magento\Framework\View\Helper\Js;

/**
* Fieldset renderer for Buckaroo solution
*/
class Payment extends \Magento\Config\Block\System\Config\Form\Fieldset
class Payment extends Fieldset
{
/**
* @var \Magento\Config\Model\Config
* @var Config
*/
protected $_backendConfig;
protected Config $backendConfig;

/**
* @param \Magento\Backend\Block\Context $context
* @param \Magento\Backend\Model\Auth\Session $authSession
* @param \Magento\Framework\View\Helper\Js $jsHelper
* @param \Magento\Config\Model\Config $backendConfig
* @param Context $context
* @param Session $authSession
* @param Js $jsHelper
* @param Config $backendConfig
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Context $context,
\Magento\Backend\Model\Auth\Session $authSession,
\Magento\Framework\View\Helper\Js $jsHelper,
\Magento\Config\Model\Config $backendConfig,
Context $context,
Session $authSession,
Js $jsHelper,
Config $backendConfig,
array $data = []
) {
$this->_backendConfig = $backendConfig;
$this->backendConfig = $backendConfig;
parent::__construct($context, $authSession, $jsHelper, $data);
}

/**
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @param AbstractElement $element
* @return string
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
Expand All @@ -60,8 +66,8 @@ protected function _getHeaderTitleHtml($element)

$groupConfig = $element->getGroup();

$disabledAttributeString = $this->_isPaymentEnabled($element) ? '' : ' disabled="disabled"';
$disabledClassString = $this->_isPaymentEnabled($element) ? '' : ' disabled';
$disabledAttributeString = $this->isPaymentEnabled($element) ? '' : ' disabled="disabled"';
$disabledClassString = $this->isPaymentEnabled($element) ? '' : ' disabled';
$htmlId = $element->getHtmlId();
$html .= '<div class="button-container"><button type="button"' .
$disabledAttributeString .
Expand All @@ -81,14 +87,12 @@ protected function _getHeaderTitleHtml($element)
) . '</span></button>';

if (!empty($groupConfig['more_url'])) {
$html .= '<a class="link-more" href="' . $groupConfig['more_url'] . '" target="_blank">' . __(
'Learn More'
) . '</a>';
$html .= '<a class="link-more" href="' . $groupConfig['more_url'] . '" target="_blank">'
. __('Learn More') . '</a>';
}
if (!empty($groupConfig['demo_url'])) {
$html .= '<a class="link-demo" href="' . $groupConfig['demo_url'] . '" target="_blank">' . __(
'View Demo'
) . '</a>';
$html .= '<a class="link-demo" href="' . $groupConfig['demo_url'] . '" target="_blank">'
. __('View Demo') . '</a>';
}

$html .= '</div>';
Expand All @@ -104,7 +108,20 @@ protected function _getHeaderTitleHtml($element)
}

/**
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* Check whether current payment method is enabled
*
* @param AbstractElement $element
* @return bool
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
protected function isPaymentEnabled($element)
{
return (bool)(string)$this->backendConfig->getConfigDataValue('buckaroo_magento2/account/active') > 0;
}

/**
* @param AbstractElement $element
* @return string
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
Expand All @@ -114,7 +131,7 @@ protected function _getHeaderCommentHtml($element)
}

/**
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @param AbstractElement $element
* @return false
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
Expand All @@ -124,7 +141,7 @@ protected function _isCollapseState($element)
}

/**
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @param AbstractElement $element
* @return string
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
Expand Down Expand Up @@ -153,25 +170,12 @@ protected function _getExtraJs($element)
}

/**
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @param AbstractElement $element
* @return string
*/
protected function _getFrontendClass($element)
{
$enabledString = $this->_isPaymentEnabled($element) ? ' enabled' : '';
$enabledString = $this->isPaymentEnabled($element) ? ' enabled' : '';
return parent::_getFrontendClass($element) . ' with-button' . $enabledString;
}

/**
* Check whether current payment method is enabled
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return bool
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
protected function _isPaymentEnabled($element)
{
return (bool)(string) $this->_backendConfig->getConfigDataValue('buckaroo_magento2/account/active') > 0;
}
}
2 changes: 1 addition & 1 deletion Block/Config/Form/Field/ColorPicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ protected function _getElementHtml(AbstractElement $element): string
$element->setData('type', 'color');
return $element->getElementHtml();
}
}
}
3 changes: 1 addition & 2 deletions Block/Config/Form/Field/Fieldset.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ private function getScopeValue(): array
*/
protected function _getHeaderTitleHtml($element): string
{
if (
!isset($element->getGroup()['id']) ||
if (!isset($element->getGroup()['id']) ||
!is_string($element->getGroup()['id'])
) {
return parent::_getHeaderTitleHtml($element);
Expand Down
10 changes: 5 additions & 5 deletions Block/Config/Form/Field/LogoSelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class LogoSelector extends Field
{
protected $_template = 'Buckaroo_Magento2::in3_logo.phtml';

protected Repository $assetRepo;
protected Repository $assetRepo;

/**
* @param Context $context
Expand All @@ -56,8 +56,8 @@ protected function _getElementHtml(AbstractElement $element)
{
$element->setData('type', 'hidden');
$this->assign("input", $element->getElementHtml());
$this->assign("inputId", $element->getHtmlId());
$this->assign("inputValue", $element->getEscapedValue());
$this->assign("inputId", $element->getHtmlId());
$this->assign("inputValue", $element->getEscapedValue());
return $this->_toHtml();
}

Expand All @@ -66,6 +66,6 @@ public function getLogos(): array
return [
"in3.svg" => $this->assetRepo->getUrl("Buckaroo_Magento2::images/svg/in3.svg"),
"in3-ideal.svg" => $this->assetRepo->getUrl("Buckaroo_Magento2::images/svg/in3-ideal.svg")
];
];
}
}
}
3 changes: 1 addition & 2 deletions Block/Config/Form/Field/VerificationMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ protected function _getFrontendClass($element): string
*/
protected function _getHeaderTitleHtml($element): string
{
if (
!isset($element->getGroup()['id']) ||
if (!isset($element->getGroup()['id']) ||
!is_string($element->getGroup()['id'])
) {
return parent::_getHeaderTitleHtml($element);
Expand Down
1 change: 0 additions & 1 deletion Controller/Adminhtml/Giftcard/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public function execute()

if ($this->getRequest()->getParam('back')) {
return $this->_redirect('*/*/edit', ['entity_id' => $giftcardModel->getId(), '_current' => true]);

}

return $this->_redirect('*/*/');
Expand Down
3 changes: 2 additions & 1 deletion Controller/Adminhtml/Notification/MarkUserNotified.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@

use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\FlagManager;
use Psr\Log\LoggerInterface;

class MarkUserNotified extends Action
class MarkUserNotified extends Action implements HttpPostActionInterface
{
/**
* @var FlagManager $flagManager
Expand Down
6 changes: 4 additions & 2 deletions Controller/Applepay/Add.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public function execute()
{
$this->logger->addDebug(sprintf(
'[ApplePay] | [Controller] | [%s:%s] - Add Product to Cart | request: %s',
__METHOD__, __LINE__,
__METHOD__,
__LINE__,
var_export($this->getParams(), true)
));

Expand All @@ -72,7 +73,8 @@ public function execute()

$this->logger->addDebug(sprintf(
'[ApplePay] | [Controller] | [%s:%s] - Add Product to Cart | response: %s',
__METHOD__, __LINE__,
__METHOD__,
__LINE__,
var_export($data, true)
));

Expand Down
Loading