Skip to content

Commit

Permalink
Fixing PHP sniffer and SonarQube issues
Browse files Browse the repository at this point in the history
  • Loading branch information
MarijaIv committed Nov 28, 2024
1 parent 6ba3b97 commit 95b557e
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 17 deletions.
22 changes: 15 additions & 7 deletions src/AdyenPaymentShopware6.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@

class AdyenPaymentShopware6 extends Plugin
{
public const SOFORT = 'Adyen\Shopware\Handlers\SofortPaymentMethodHandler';

public function installJsAssets($shopwareVersion)
{
$storefrontAssetPath = __DIR__ . '/Resources/app/storefront/dist/storefront/js/adyen-payment-shopware6.js';
Expand Down Expand Up @@ -203,8 +205,9 @@ private function addPaymentMethod(PaymentMethods\PaymentMethodInterface $payment
$paymentRepository = $this->container->get('payment_method.repository');

// Rename if Klarna Debit Risk doesnt exist from previous installations
if ($paymentMethod->getPaymentHandler() === KlarnaDebitRiskPaymentMethodHandler::class && $paymentMethodId === null) {
$sofortMethodId = $this->getPaymentMethodId('Adyen\Shopware\Handlers\SofortPaymentMethodHandler');
if ($paymentMethod->getPaymentHandler() === KlarnaDebitRiskPaymentMethodHandler::class
&& $paymentMethodId === null) {
$sofortMethodId = $this->getPaymentMethodId(self::SOFORT);

if ($sofortMethodId) {
// update Sofort to Klarna Debit Risk
Expand Down Expand Up @@ -585,17 +588,22 @@ private function updateTo3170(UpdateContext $updateContext): void

// Version 3.17.0 replaces Sofort with Klarna Debit Risk
$paymentRepository = $this->container->get('payment_method.repository');
$paymentMethodId = $this->getPaymentMethodId('Adyen\Shopware\Handlers\SofortPaymentMethodHandler');
$klarnaDebitRisktMethodId = $this->getPaymentMethodId('Adyen\Shopware\Handlers\KlarnaDebitRiskPaymentMethodHandler');
$paymentMethodId = $this->getPaymentMethodId(self::SOFORT);
$klarnaDebitRisktMethodId = $this->getPaymentMethodId(
'Adyen\Shopware\Handlers\KlarnaDebitRiskPaymentMethodHandler'
);

// If Sofort does not exist, return
if (!$paymentMethodId) {
return;
}

if($klarnaDebitRisktMethodId !== null) {
if ($klarnaDebitRisktMethodId !== null) {
// Klarna Debit Risk exists, deactivate Sofort and skip renaming
$this->deactivateAndRemovePaymentMethod($updateContext, 'Adyen\Shopware\Handlers\SofortPaymentMethodHandler');
$this->deactivateAndRemovePaymentMethod(
$updateContext,
self::SOFORT
);

return;
}
Expand Down Expand Up @@ -680,4 +688,4 @@ private function deactivateAndRemovePaymentMethod(

if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
require_once __DIR__ . '/../vendor/autoload.php';
}
}
4 changes: 2 additions & 2 deletions src/Handlers/AbstractPaymentMethodHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -602,9 +602,9 @@ protected function preparePaymentsRequest(
$paymentRequest->setMerchantAccount(
$this->configurationService->getMerchantAccount($salesChannelContext->getSalesChannel()->getId())
);
if($paymentMethodType === 'bcmc_mobile'){
if ($paymentMethodType === 'bcmc_mobile') {
$paymentRequest->setReturnUrl($this->getReturnUrl($transaction));
}else{
} else {
$paymentRequest->setReturnUrl($transaction->getReturnUrl());
}

Expand Down
4 changes: 2 additions & 2 deletions src/PaymentMethods/OnlineBankingFinlandPaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function getName(): string
*/
public function getDescription(): string
{
return 'Online Banking Finland';
return 'Online Banking Finland payment method';
}

/**
Expand Down Expand Up @@ -97,4 +97,4 @@ public function getType(): string
{
return 'redirect';
}
}
}
4 changes: 2 additions & 2 deletions src/PaymentMethods/OnlineBankingPolandPaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function getName(): string
*/
public function getDescription(): string
{
return 'Online Banking Poland';
return 'Online Banking Poland payment method';
}

/**
Expand Down Expand Up @@ -97,4 +97,4 @@ public function getType(): string
{
return 'redirect';
}
}
}
3 changes: 1 addition & 2 deletions src/Subscriber/PaymentSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,7 @@ public function onShoppingCartLoaded(PageLoadedEvent $event)
/** @var CheckoutCartPage|OffcanvasCartPage $page */
$page = $event->getPage();
$errorCodes = [];
if (
$event->getRequest()->get('errorCode')
if ($event->getRequest()->get('errorCode')
&& $event->getRequest()->get('errorCode') === 'UNSUCCESSFUL_ADYEN_TRANSACTION'
) {
$errorCodes['errorCode'] = 'UNSUCCESSFUL_ADYEN_TRANSACTION';
Expand Down
5 changes: 3 additions & 2 deletions src/Util/ShopwarePaymentTokenValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class ShopwarePaymentTokenValidator
/**
* @param TokenFactoryInterfaceV2 $tokenFactory
*/
public function __construct(TokenFactoryInterfaceV2 $tokenFactory){
public function __construct(TokenFactoryInterfaceV2 $tokenFactory)
{
$this->tokenFactory = $tokenFactory;
}

Expand All @@ -40,4 +41,4 @@ public function validateToken(?string $paymentToken): bool
return false;
}
}
}
}

0 comments on commit 95b557e

Please sign in to comment.