Skip to content
Code-Schnipsel Gruppen Projekte
Bestätigt Commit bef1e7d8 erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

refactor: code style

Übergeordneter 3552307e
No related branches found
No related tags found
Keine zugehörigen Merge Requests gefunden
...@@ -2,11 +2,22 @@ ...@@ -2,11 +2,22 @@
namespace QUI\ERP\Coupons; namespace QUI\ERP\Coupons;
use DateTime;
use Exception;
use QUI; use QUI;
use QUI\ERP\Discount\Handler as DiscountHandler; use QUI\ERP\Discount\Handler as DiscountHandler;
use QUI\ERP\Order\OrderInterface; use QUI\ERP\Order\OrderInterface;
use QUI\Permissions\Permission; use QUI\Permissions\Permission;
use function array_key_first;
use function count;
use function current;
use function in_array;
use function is_array;
use function is_null;
use function json_decode;
use function method_exists;
/** /**
* Class CouponCode * Class CouponCode
*/ */
...@@ -80,7 +91,7 @@ class CouponCode ...@@ -80,7 +91,7 @@ class CouponCode
* *
* @var bool * @var bool
*/ */
protected $valid = true; protected bool $valid = true;
/** /**
* Max usages * Max usages
...@@ -93,7 +104,9 @@ class CouponCode ...@@ -93,7 +104,9 @@ class CouponCode
* CouponCode constructor. * CouponCode constructor.
* *
* @param int $id - Invite Code ID * @param int $id - Invite Code ID
*
* @throws CouponCodeException * @throws CouponCodeException
* @throws \Exception
*/ */
public function __construct(int $id) public function __construct(int $id)
{ {
...@@ -126,22 +139,22 @@ public function __construct(int $id) ...@@ -126,22 +139,22 @@ public function __construct(int $id)
], 404); ], 404);
} }
$data = \current($result); $data = current($result);
$this->id = (int)$data['id']; $this->id = (int)$data['id'];
$this->code = $data['code']; $this->code = $data['code'];
$this->title = $data['title']; $this->title = $data['title'];
if (!empty($data['usages'])) { if (!empty($data['usages'])) {
$this->usages = \json_decode($data['usages'], true); $this->usages = json_decode($data['usages'], true);
} }
if (!empty($data['userIds'])) { if (!empty($data['userIds'])) {
$this->userIds = \json_decode($data['userIds'], true); $this->userIds = json_decode($data['userIds'], true);
} }
if (!empty($data['groupIds'])) { if (!empty($data['groupIds'])) {
$this->groupIds = \json_decode($data['groupIds'], true); $this->groupIds = json_decode($data['groupIds'], true);
} }
if (!empty($data['maxUsages'])) { if (!empty($data['maxUsages'])) {
...@@ -149,13 +162,13 @@ public function __construct(int $id) ...@@ -149,13 +162,13 @@ public function __construct(int $id)
} }
if (!empty($data['discountIds'])) { if (!empty($data['discountIds'])) {
$this->discountIds = \json_decode($data['discountIds'], true); $this->discountIds = json_decode($data['discountIds'], true);
} }
$this->CreateDate = new \DateTime($data['createDate']); $this->CreateDate = new DateTime($data['createDate']);
if (!empty($data['validUntilDate'])) { if (!empty($data['validUntilDate'])) {
$this->ValidUntilDate = new \DateTime($data['validUntilDate']); $this->ValidUntilDate = new DateTime($data['validUntilDate']);
$this->ValidUntilDate->setTime(23, 59, 59); $this->ValidUntilDate->setTime(23, 59, 59);
} }
...@@ -181,7 +194,7 @@ public function getCode(): string ...@@ -181,7 +194,7 @@ public function getCode(): string
/** /**
* @return \DateTime * @return \DateTime
*/ */
public function getCreateDate(): \DateTime public function getCreateDate(): DateTime
{ {
return $this->CreateDate; return $this->CreateDate;
} }
...@@ -199,7 +212,7 @@ public function getUsages(): array ...@@ -199,7 +212,7 @@ public function getUsages(): array
/** /**
* @return \DateTime|null * @return \DateTime|null
*/ */
public function getValidUntilDate(): ?\DateTime public function getValidUntilDate(): ?DateTime
{ {
return $this->ValidUntilDate; return $this->ValidUntilDate;
} }
...@@ -233,7 +246,7 @@ public function getDiscounts(): array ...@@ -233,7 +246,7 @@ public function getDiscounts(): array
foreach ($this->discountIds as $discountId) { foreach ($this->discountIds as $discountId) {
try { try {
$discounts[] = $DiscountHandler->getChild($discountId); $discounts[] = $DiscountHandler->getChild($discountId);
} catch (\Exception $Exception) { } catch (Exception $Exception) {
QUI\System\Log::writeDebugException($Exception); QUI\System\Log::writeDebugException($Exception);
} }
} }
...@@ -270,13 +283,13 @@ public function getGroupIds(): array ...@@ -270,13 +283,13 @@ public function getGroupIds(): array
*/ */
public function redeem($User = null, $Order = null) public function redeem($User = null, $Order = null)
{ {
if (\is_null($User)) { if (is_null($User)) {
$User = QUI::getUserBySession(); $User = QUI::getUserBySession();
} }
$this->checkRedemption($User); $this->checkRedemption($User);
$Now = new \DateTime(); $Now = new DateTime();
$usage = [ $usage = [
'userId' => $User->getId(), 'userId' => $User->getId(),
...@@ -284,7 +297,7 @@ public function redeem($User = null, $Order = null) ...@@ -284,7 +297,7 @@ public function redeem($User = null, $Order = null)
'orderPrefixedId' => false 'orderPrefixedId' => false
]; ];
if (!\is_null($Order) && $Order instanceof QUI\ERP\Order\Order) { if ($Order instanceof QUI\ERP\Order\Order) {
$usage['orderPrefixedId'] = $Order->getPrefixedId(); $usage['orderPrefixedId'] = $Order->getPrefixedId();
} }
...@@ -331,7 +344,7 @@ public function checkRedemption($User) ...@@ -331,7 +344,7 @@ public function checkRedemption($User)
try { try {
/** @var QUI\ERP\Discount\Discount $Discount */ /** @var QUI\ERP\Discount\Discount $Discount */
$Discount = $DiscountHandler->getChild($discountId); $Discount = $DiscountHandler->getChild($discountId);
} catch (\Exception $Exception) { } catch (Exception $Exception) {
$discountError = $Exception->getMessage(); $discountError = $Exception->getMessage();
continue; continue;
} }
...@@ -343,7 +356,7 @@ public function checkRedemption($User) ...@@ -343,7 +356,7 @@ public function checkRedemption($User)
} }
if (!$discountsValid) { if (!$discountsValid) {
if (\count($this->discountIds) === 1) { if (count($this->discountIds) === 1) {
throw new CouponCodeException([ throw new CouponCodeException([
'quiqqer/coupons', 'quiqqer/coupons',
'exception.CouponCode.discount_invalid', 'exception.CouponCode.discount_invalid',
...@@ -382,7 +395,7 @@ public function checkRedemption($User) ...@@ -382,7 +395,7 @@ public function checkRedemption($User)
// Restriction to QUIQQER user(s) // Restriction to QUIQQER user(s)
if (!empty($this->userIds)) { if (!empty($this->userIds)) {
if (\in_array($User->getId(), $this->userIds)) { if (in_array($User->getId(), $this->userIds)) {
if ($this->maxUsages !== Handler::MAX_USAGE_UNLIMITED if ($this->maxUsages !== Handler::MAX_USAGE_UNLIMITED
&& $this->hasUserRedeemed($User)) { && $this->hasUserRedeemed($User)) {
throw new CouponCodeException([ throw new CouponCodeException([
...@@ -446,7 +459,7 @@ public function checkOrderRedemption($Order) ...@@ -446,7 +459,7 @@ public function checkOrderRedemption($Order)
try { try {
/** @var QUI\ERP\Discount\Discount $Discount */ /** @var QUI\ERP\Discount\Discount $Discount */
$Discount = $DiscountHandler->getChild($discountId); $Discount = $DiscountHandler->getChild($discountId);
} catch (\Exception $Exception) { } catch (Exception $Exception) {
$discountError = $Exception->getMessage(); $discountError = $Exception->getMessage();
continue; continue;
} }
...@@ -458,7 +471,7 @@ public function checkOrderRedemption($Order) ...@@ -458,7 +471,7 @@ public function checkOrderRedemption($Order)
} }
if (!$discountsValid) { if (!$discountsValid) {
if (\count($this->discountIds) === 1) { if (count($this->discountIds) === 1) {
throw new CouponCodeException([ throw new CouponCodeException([
'quiqqer/coupons', 'quiqqer/coupons',
'exception.CouponCode.discount_invalid', 'exception.CouponCode.discount_invalid',
...@@ -556,7 +569,7 @@ public function delete() ...@@ -556,7 +569,7 @@ public function delete()
if (!empty($Discount->getAttribute('hidden'))) { if (!empty($Discount->getAttribute('hidden'))) {
try { try {
$Discount->delete(); $Discount->delete();
} catch (\Exception $Exception) { } catch (Exception $Exception) {
QUI\System\Log::writeException($Exception); QUI\System\Log::writeException($Exception);
} }
} }
...@@ -602,7 +615,7 @@ protected function checkValidity() ...@@ -602,7 +615,7 @@ protected function checkValidity()
{ {
// Check if the expiration date has been reached // Check if the expiration date has been reached
if (!empty($this->ValidUntilDate)) { if (!empty($this->ValidUntilDate)) {
$Now = new \DateTime(); $Now = new DateTime();
if ($Now > $this->ValidUntilDate) { if ($Now > $this->ValidUntilDate) {
$this->valid = false; $this->valid = false;
...@@ -655,7 +668,7 @@ public function addToOrder(QUI\ERP\Order\OrderInProcess $Order) ...@@ -655,7 +668,7 @@ public function addToOrder(QUI\ERP\Order\OrderInProcess $Order)
return; return;
} }
if (!\is_array($coupons)) { if (!is_array($coupons)) {
return; return;
} }
...@@ -665,15 +678,15 @@ public function addToOrder(QUI\ERP\Order\OrderInProcess $Order) ...@@ -665,15 +678,15 @@ public function addToOrder(QUI\ERP\Order\OrderInProcess $Order)
$vatArray = $calculations['vatArray']; $vatArray = $calculations['vatArray'];
$vat = false; $vat = false;
if (\count($vatArray) === 1) { if (count($vatArray) === 1) {
$vat = \array_key_first($vatArray); $vat = array_key_first($vatArray);
} }
foreach ($coupons as $coupon) { foreach ($coupons as $coupon) {
/* @var $Coupon CouponCode */ /* @var $Coupon CouponCode */
try { try {
$Coupon = Handler::getCouponCodeByCode($coupon); $Coupon = Handler::getCouponCodeByCode($coupon);
} catch (\Exception $Exception) { } catch (Exception $Exception) {
continue; continue;
} }
...@@ -731,13 +744,13 @@ public function addToOrder(QUI\ERP\Order\OrderInProcess $Order) ...@@ -731,13 +744,13 @@ public function addToOrder(QUI\ERP\Order\OrderInProcess $Order)
$code = $Article->getCustomData()['code']; $code = $Article->getCustomData()['code'];
foreach ($articles as $Entry) { foreach ($articles as $Entry) {
if (!\method_exists($Entry, 'getCustomData')) { if (!method_exists($Entry, 'getCustomData')) {
continue; continue;
} }
$customData = $Entry->getCustomData(); $customData = $Entry->getCustomData();
if (!$customData || !\is_array($customData)) { if (!$customData || !is_array($customData)) {
continue; continue;
} }
......
0% oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren