From 95b557ef8ed5160e7902ee9a936c34ee2f59841d Mon Sep 17 00:00:00 2001 From: Marija Date: Thu, 28 Nov 2024 16:55:24 +0100 Subject: [PATCH] Fixing PHP sniffer and SonarQube issues --- src/AdyenPaymentShopware6.php | 22 +++++++++++++------ src/Handlers/AbstractPaymentMethodHandler.php | 4 ++-- .../OnlineBankingFinlandPaymentMethod.php | 4 ++-- .../OnlineBankingPolandPaymentMethod.php | 4 ++-- src/Subscriber/PaymentSubscriber.php | 3 +-- src/Util/ShopwarePaymentTokenValidator.php | 5 +++-- 6 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/AdyenPaymentShopware6.php b/src/AdyenPaymentShopware6.php index b2a397bc..696cc940 100644 --- a/src/AdyenPaymentShopware6.php +++ b/src/AdyenPaymentShopware6.php @@ -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'; @@ -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 @@ -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; } @@ -680,4 +688,4 @@ private function deactivateAndRemovePaymentMethod( if (file_exists(__DIR__ . '/../vendor/autoload.php')) { require_once __DIR__ . '/../vendor/autoload.php'; -} \ No newline at end of file +} diff --git a/src/Handlers/AbstractPaymentMethodHandler.php b/src/Handlers/AbstractPaymentMethodHandler.php index 15ed4f6f..806a2170 100644 --- a/src/Handlers/AbstractPaymentMethodHandler.php +++ b/src/Handlers/AbstractPaymentMethodHandler.php @@ -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()); } diff --git a/src/PaymentMethods/OnlineBankingFinlandPaymentMethod.php b/src/PaymentMethods/OnlineBankingFinlandPaymentMethod.php index 0305e246..f9fa06f6 100644 --- a/src/PaymentMethods/OnlineBankingFinlandPaymentMethod.php +++ b/src/PaymentMethods/OnlineBankingFinlandPaymentMethod.php @@ -45,7 +45,7 @@ public function getName(): string */ public function getDescription(): string { - return 'Online Banking Finland'; + return 'Online Banking Finland payment method'; } /** @@ -97,4 +97,4 @@ public function getType(): string { return 'redirect'; } -} \ No newline at end of file +} diff --git a/src/PaymentMethods/OnlineBankingPolandPaymentMethod.php b/src/PaymentMethods/OnlineBankingPolandPaymentMethod.php index c3b50e8a..e369b656 100644 --- a/src/PaymentMethods/OnlineBankingPolandPaymentMethod.php +++ b/src/PaymentMethods/OnlineBankingPolandPaymentMethod.php @@ -45,7 +45,7 @@ public function getName(): string */ public function getDescription(): string { - return 'Online Banking Poland'; + return 'Online Banking Poland payment method'; } /** @@ -97,4 +97,4 @@ public function getType(): string { return 'redirect'; } -} \ No newline at end of file +} diff --git a/src/Subscriber/PaymentSubscriber.php b/src/Subscriber/PaymentSubscriber.php index 663b6c9d..4c4549dd 100644 --- a/src/Subscriber/PaymentSubscriber.php +++ b/src/Subscriber/PaymentSubscriber.php @@ -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'; diff --git a/src/Util/ShopwarePaymentTokenValidator.php b/src/Util/ShopwarePaymentTokenValidator.php index 4a69ad0d..3b613a4c 100644 --- a/src/Util/ShopwarePaymentTokenValidator.php +++ b/src/Util/ShopwarePaymentTokenValidator.php @@ -15,7 +15,8 @@ class ShopwarePaymentTokenValidator /** * @param TokenFactoryInterfaceV2 $tokenFactory */ - public function __construct(TokenFactoryInterfaceV2 $tokenFactory){ + public function __construct(TokenFactoryInterfaceV2 $tokenFactory) + { $this->tokenFactory = $tokenFactory; } @@ -40,4 +41,4 @@ public function validateToken(?string $paymentToken): bool return false; } } -} \ No newline at end of file +}