From 46f4a200ac6c69c390c5ab68d775ed9d44c663b3 Mon Sep 17 00:00:00 2001 From: Mario Lorenz Date: Thu, 4 Apr 2024 14:12:05 +0200 Subject: [PATCH] fix phpMD --- src/Controller/DispatcherController.php | 13 ++++++++----- src/Model/Order.php | 2 ++ src/Model/TmpOrder.php | 7 ++++--- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/Controller/DispatcherController.php b/src/Controller/DispatcherController.php index 3270f6c8..1a789d9d 100644 --- a/src/Controller/DispatcherController.php +++ b/src/Controller/DispatcherController.php @@ -11,10 +11,8 @@ use JsonException; use OxidEsales\Eshop\Application\Controller\FrontendController; use OxidEsales\Eshop\Application\Model\Order; -use OxidEsales\Eshop\Core\Counter; use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException; use OxidEsales\Eshop\Core\Exception\DatabaseErrorException; -use OxidEsales\Eshop\Core\Field; use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Request; use OxidSolutionCatalysts\Unzer\Model\TmpOrder; @@ -27,6 +25,10 @@ use UnzerSDK\Exceptions\UnzerApiException; use UnzerSDK\Resources\Payment; +/** + * TODO: Decrease count of dependencies to 13 + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class DispatcherController extends FrontendController { use ServiceContainer; @@ -158,6 +160,7 @@ public function updatePaymentTransStatus(): void * @param bool $error * @return void * @throws Exception + * @SuppressWarnings(PHPMD.BooleanArgumentFlag) */ protected function handleTmpOrder(Payment $unzerPayment, TmpOrder $tmpOrder, array $tmpData, bool $error = false): void { @@ -183,13 +186,13 @@ protected function handleTmpOrder(Payment $unzerPayment, TmpOrder $tmpOrder, arr */ protected function hasExceededTimeLimit(TmpOrder $tmpOrder): bool { - $UnzerWebhookTimeDifference = Registry::getConfig()->getConfigParam('UnzerWebhookTimeDifference', 5); - $TimeDifferenceSeconds = $UnzerWebhookTimeDifference * 60; + $defTimeDiffMin = Registry::getConfig()->getConfigParam('defTimeDiffMin', 5); + $timeDiffSec = $defTimeDiffMin * 60; $tmpOrderTime = is_string($tmpOrder->getFieldData('TIMESTAMP')) ? $tmpOrder->getFieldData('TIMESTAMP') : ''; $tmpOrderTimeUnix = strtotime($tmpOrderTime); $nowTimeUnix = time(); $difference = $nowTimeUnix - $tmpOrderTimeUnix; - return $difference >= $TimeDifferenceSeconds; + return $difference >= $timeDiffSec; } } diff --git a/src/Model/Order.php b/src/Model/Order.php index 239bd160..d338f1a4 100644 --- a/src/Model/Order.php +++ b/src/Model/Order.php @@ -292,6 +292,8 @@ public function getUnzerInvoiceNr() * @param $unzerPayment Payment * @return void * @throws Exception + * @SuppressWarnings(PHPMD.BooleanArgumentFlag) + * @SuppressWarnings(PHPMD.ElseExpression) */ public function finalizeTmpOrder(Payment $unzerPayment, bool $error = false): void { diff --git a/src/Model/TmpOrder.php b/src/Model/TmpOrder.php index d3c36232..5f75d37c 100644 --- a/src/Model/TmpOrder.php +++ b/src/Model/TmpOrder.php @@ -31,7 +31,6 @@ public function __construct() $this->init('oscunzertmporder'); } - public function save() { return parent::save(); @@ -41,8 +40,10 @@ public function prepareOrderForJson(CoreOrderModel $oOrder): void { $oConfig = Registry::getConfig(); $oOrderArticles = $oOrder->getOrderArticles(); - $completeOrder['order'] = $oOrder; - $completeOrder['orderArticles'] = $oOrderArticles->getArray(); + $completeOrder = [ + 'order' => $oOrder, + 'orderArticles' => $oOrderArticles->getArray() + ]; $serializedOrder = serialize($completeOrder); $base64Order = base64_encode($serializedOrder); /** @var Order $oOrder */