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

refactor: phpstan level 8

Übergeordneter 3ad8bd31
No related branches found
No related tags found
3 Merge Requests!22refactor(SimpleCheckoutWindow): style and UX,!18Next 2.x,!16Feat quiqqer v2
Pipeline #8547 bestanden mit Phase
in 9 Sekunden
......@@ -19,13 +19,20 @@ function ($orderHash) {
]);
$Order = $Checkout->getOrder();
if (!$Order) {
throw new QUI\Exception('Checkout has no order');
}
$InvoiceAddress = $Order->getInvoiceAddress();
$DefaultAddress = $SessionUser->getStandardAddress();
$hasDeliveryAddress = $Order->hasDeliveryAddress();
$isSameAddress = function (QUI\Users\Address $a, QUI\Users\Address $b) {
$isSameAddress = function (?QUI\Users\Address $a, ?QUI\Users\Address $b) {
if (
$a->getAttribute('firstname') === $b->getAttribute('firstname')
$a
&& $b
&& $a->getAttribute('firstname') === $b->getAttribute('firstname')
&& $a->getAttribute('lastname') === $b->getAttribute('lastname')
&& $a->getAttribute('street_no') === $b->getAttribute('street_no')
&& $a->getAttribute('zip') === $b->getAttribute('zip')
......@@ -53,7 +60,8 @@ function ($orderHash) {
// if default address is empty, we set it
if (
$DefaultAddress->getAttribute('firstname') === ''
$DefaultAddress
&& $DefaultAddress->getAttribute('firstname') === ''
&& $DefaultAddress->getAttribute('lastname') === ''
&& $DefaultAddress->getAttribute('street_no') === ''
&& $DefaultAddress->getAttribute('zip') === ''
......@@ -73,7 +81,8 @@ function ($orderHash) {
$Order->setInvoiceAddress($DefaultAddress);
$Order->save(QUI::getUsers()->getSystemUser());
} elseif (
$DefaultAddress->getAttribute('firstname') === ''
$DefaultAddress
&& $DefaultAddress->getAttribute('firstname') === ''
&& $DefaultAddress->getAttribute('lastname') === ''
&& $DefaultAddress->getAttribute('street_no') === ''
&& $DefaultAddress->getAttribute('zip') === ''
......@@ -95,7 +104,10 @@ function ($orderHash) {
} elseif (method_exists($SessionUser, 'addAddress') && !$userIsGuest) {
// add new address
$NewAddress = $SessionUser->addAddress($InvoiceAddress->getAttributes());
$Order->setInvoiceAddress($NewAddress);
if ($NewAddress) {
$Order->setInvoiceAddress($NewAddress);
}
}
$Order->save(QUI::getUsers()->getSystemUser());
......
......@@ -17,8 +17,8 @@ function ($orderHash, $currency) {
$Order = $Checkout->getOrder();
$Currency = QUI\ERP\Currency\Handler::getCurrency($currency);
$Order->setCurrency($Currency);
$Order->save();
$Order?->setCurrency($Currency);
$Order?->save();
},
['orderHash', 'currency']
);
......@@ -35,14 +35,14 @@ function ($orderHash, $orderData) {
]);
if (isset($orderData['billing_address']) && $orderData['billing_address'] === 'different') {
$Order->setDeliveryAddress($ErpAddress);
$Order?->setDeliveryAddress($ErpAddress);
// invoice address / billing address
if (isset($orderData['billing_street']) && isset($orderData['billing_street_number'])) {
$orderData['billing_street_no'] = $orderData['billing_street'] . ' ' . $orderData['billing_street_number'];
}
$Order->setInvoiceAddress(
$Order?->setInvoiceAddress(
new Address([
'firstname' => $orderData['billing_firstname'],
'lastname' => $orderData['billing_lastname'],
......@@ -53,25 +53,25 @@ function ($orderHash, $orderData) {
])
);
} else {
$Order->setInvoiceAddress($ErpAddress);
$Order->removeDeliveryAddress();
$Order?->setInvoiceAddress($ErpAddress);
$Order?->removeDeliveryAddress();
}
if (!empty($orderData['shipping']) && QUI::getPackageManager()->isInstalled('quiqqer/shipping')) {
$Order->setShipping(
$Order?->setShipping(
Shipping::getInstance()->getShippingEntry($orderData['shipping'])
);
} else {
$Order->removeShipping();
$Order?->removeShipping();
}
if (!empty($orderData['payment'])) {
$Order->setPayment($orderData['payment']);
$Order?->setPayment($orderData['payment']);
} else {
$Order->clearPayment();
$Order?->clearPayment();
}
$Order->save();
$Order?->save();
return $Checkout->isValid();
},
......
......@@ -11,6 +11,8 @@ class Basket extends QUI\Control
protected Checkout $Checkout;
/**
* @param Checkout $Checkout
* @param mixed[] $attributes
*/
public function __construct(Checkout $Checkout, array $attributes = [])
{
......@@ -29,10 +31,10 @@ public function getBody(): string
{
$Engine = QUI::getTemplateManager()->getEngine();
$Order = $this->Checkout->getOrder();
$Order->recalculate(); // because of price factors
$Articles = $Order->getArticles();
$Order?->recalculate(); // because of price factors
$Articles = $Order?->getArticles();
if (!$Articles->count()) {
if (!$Articles || !$Articles->count()) {
$Engine->assign([
'basketEmpty' => true
]);
......
......@@ -24,6 +24,9 @@
*/
class Checkout extends QUI\Control
{
/**
* @param mixed[] $attributes
*/
public function __construct(array $attributes = [])
{
$this->setAttributes([
......@@ -78,9 +81,12 @@ class_exists('QUI\ERP\Order\Guest\GuestOrder')
}
// put the basket articles to the order in process, if the current order has no articles
if (!$this->getOrder()->getArticles()->count()) {
if (!$this->getOrder()?->getArticles()->count()) {
$Basket = QUI\ERP\Order\Handler::getInstance()->getBasketFromUser($this->getUser());
$Basket->toOrder($this->getOrder());
if ($this->getOrder()) {
$Basket->toOrder($this->getOrder());
}
}
$Checkout = new QUI\ERP\Order\Controls\OrderProcess\Checkout();
......@@ -128,6 +134,10 @@ public function isValid(): bool
try {
$Order = $this->getOrder();
if (!$Order) {
return false;
}
QUI\ERP\Order\Controls\OrderProcess\CustomerData::validateAddress(
$Order->getInvoiceAddress()
);
......@@ -150,6 +160,9 @@ public function isValid(): bool
return true;
}
/**
* @return array<string>
*/
public function gatherMissingOrderDetails(): array
{
$missing = [];
......@@ -159,9 +172,13 @@ public function gatherMissingOrderDetails(): array
try {
$Order = $this->getOrder();
QUI\ERP\Order\Controls\OrderProcess\CustomerData::validateAddress(
$Order->getInvoiceAddress()
);
if ($Order?->getInvoiceAddress()) {
QUI\ERP\Order\Controls\OrderProcess\CustomerData::validateAddress(
$Order->getInvoiceAddress()
);
} else {
$missing[] = 'address';
}
} catch (QUI\Exception) {
$missing[] = 'address';
}
......@@ -188,6 +205,8 @@ public function gatherMissingOrderDetails(): array
}
/**
* @return mixed[]
*
* @throws QUI\ERP\Order\Exception
* @throws QUI\Permissions\Exception
* @throws Exception
......@@ -195,6 +214,14 @@ public function gatherMissingOrderDetails(): array
public function orderWithCosts(): array
{
$OrderInProcess = $this->getOrder();
if (!$OrderInProcess) {
throw new QUI\ERP\Order\Exception(
QUI::getLocale()->get('quiqqer/order', 'exception.order.not.found'),
QUI\ERP\Order\Handler::ERROR_ORDER_NOT_FOUND
);
}
$Order = $OrderInProcess->createOrder(QUI::getUsers()->getSystemUser());
$Order->setData('orderedWithCosts', true);
$Order->save(QUI::getUsers()->getSystemUser());
......@@ -204,6 +231,7 @@ public function orderWithCosts(): array
}
/**
* @return mixed[]
* @throws QUI\ERP\Order\Basket\Exception
* @throws \Exception
*/
......@@ -220,11 +248,7 @@ public function getOrderProcessStep(): array
]);
$result = $OrderProcess->create();
$current = false;
if ($OrderProcess->getCurrentStep()) {
$current = $OrderProcess->getCurrentStep()->getName();
}
$current = $OrderProcess->getCurrentStep()->getName();
return [
'html' => $result,
......
......@@ -14,7 +14,7 @@ interface CheckoutStepInterface
* Constructor for the class.
*
* @param Checkout $Checkout An instance of the Checkout class.
* @param array $attributes [optional] An array of attributes (default: empty array).
* @param mixed[] $attributes [optional] An array of attributes (default: empty array).
*/
public function __construct(Checkout $Checkout, array $attributes = []);
}
......@@ -23,7 +23,7 @@ class CheckoutBillingAddress extends QUI\Control implements CheckoutStepInterfac
* Constructor method for the SimpleCheckoutDelivery class.
*
* @param Checkout $Checkout
* @param array $attributes
* @param mixed[] $attributes
* @return void
*/
public function __construct(Checkout $Checkout, array $attributes = [])
......@@ -69,7 +69,7 @@ public function getBody(): string
*/
protected function getDeliveryAddress(): ?QUI\ERP\Address
{
return $this->Checkout->getOrder()->getDeliveryAddress();
return $this->Checkout->getOrder()?->getDeliveryAddress();
}
/**
......@@ -79,8 +79,16 @@ protected function getDeliveryAddress(): ?QUI\ERP\Address
*/
public function validate(): void
{
QUI\ERP\Order\Controls\OrderProcess\CustomerData::validateAddress(
$this->Checkout->getOrder()->getInvoiceAddress()
);
$Address = $this->Checkout->getOrder()?->getInvoiceAddress();
if ($Address instanceof QUI\Users\Address) {
QUI\ERP\Order\Controls\OrderProcess\CustomerData::validateAddress($Address);
} else {
throw new QUI\ERP\Order\Exception([
'quiqqer/order',
'exception.missing.address.field',
['field' => QUI::getLocale()->get('quiqqer/order', 'firstname')]
]);
}
}
}
......@@ -26,7 +26,7 @@ class CheckoutDelivery extends QUI\Control implements CheckoutStepInterface
* Constructor method for the SimpleCheckoutDelivery class.
*
* @param Checkout $Checkout
* @param array $attributes
* @param mixed[] $attributes
* @return void
*/
public function __construct(Checkout $Checkout, array $attributes = [])
......@@ -55,10 +55,6 @@ public function getBody(): string
$User = QUI::getUserBySession();
$isUserB2B = function () use ($User) {
if (!$User) {
return '';
}
if ($User->getAttribute('quiqqer.erp.isNettoUser') === QUI\ERP\Utils\User::IS_NETTO_USER) {
return ' selected="selected"';
}
......@@ -89,9 +85,9 @@ public function getBody(): string
// frontend users address profile settings
try {
$Conf = QUI::getPackage('quiqqer/frontend-users')->getConfig();
$settings = $Conf->getValue('profile', 'addressFields');
$settings = $Conf?->getValue('profile', 'addressFields');
if (!empty($settings)) {
if (!empty($settings) && is_string($settings)) {
$settings = json_decode($settings, true);
}
} catch (QUI\Exception) {
......@@ -136,11 +132,11 @@ protected function getInvoiceAddress(): ?Address
$User = QUI::getUserBySession();
$Order = $this->Checkout->getOrder();
$Address = $Order->getInvoiceAddress();
$attributes = $Address->getAttributes();
$Address = $Order?->getInvoiceAddress();
$attributes = $Address?->getAttributes();
// is not empty
if (count($attributes) > 3) {
if ($attributes && count($attributes) > 3) {
return $Address;
}
......@@ -169,8 +165,16 @@ protected function getInvoiceAddress(): ?Address
*/
public function validate(): void
{
QUI\ERP\Order\Controls\OrderProcess\CustomerData::validateAddress(
$this->Checkout->getOrder()->getInvoiceAddress()
);
$Address = $this->Checkout->getOrder()?->getInvoiceAddress();
if ($Address instanceof QUI\Users\Address) {
QUI\ERP\Order\Controls\OrderProcess\CustomerData::validateAddress($Address);
} else {
throw new QUI\ERP\Order\Exception([
'quiqqer/order',
'exception.missing.address.field',
['field' => QUI::getLocale()->get('quiqqer/order', 'firstname')]
]);
}
}
}
......@@ -13,6 +13,10 @@ class CheckoutPayment extends QUI\Control implements CheckoutStepInterface
{
protected Checkout $Checkout;
/**
* @param Checkout $Checkout
* @param mixed[] $attributes
*/
public function __construct(Checkout $Checkout, array $attributes = [])
{
$this->Checkout = $Checkout;
......
......@@ -12,6 +12,10 @@ class CheckoutShipping extends QUI\Control implements CheckoutStepInterface
{
protected Checkout $Checkout;
/**
* @param Checkout $Checkout
* @param mixed[] $attributes
*/
public function __construct(Checkout $Checkout, array $attributes = [])
{
$this->Checkout = $Checkout;
......
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