From 70b17465628f1a6a1766a176420275e1e8b38d3a Mon Sep 17 00:00:00 2001 From: Pete Eveleigh Date: Wed, 21 Aug 2024 16:39:49 +0100 Subject: [PATCH] rector fixes --- src/FosterCheckout.php | 10 +++++----- src/formatters/CheckoutAddressFormatter.php | 1 + src/services/Checkout.php | 17 +++++++++-------- src/web/assets/checkout/CheckoutAsset.php | 2 +- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/FosterCheckout.php b/src/FosterCheckout.php index 6e94655..c30e91b 100644 --- a/src/FosterCheckout.php +++ b/src/FosterCheckout.php @@ -31,14 +31,14 @@ class FosterCheckout extends Plugin public bool $hasCpSettings = false; - public function init() + public function init(): void { parent::init(); Craft::setAlias('@fostercheckout', __DIR__); // Defer most setup tasks until Craft is fully initialized - Craft::$app->onInit(function () { + Craft::$app->onInit(function (): void { $this->registerComponents(); $this->attachEventHandlers(); $this->registerCustomVariables(); @@ -83,7 +83,7 @@ private function attachEventHandlers(): void Event::on( CraftVariable::class, CraftVariable::EVENT_INIT, - function (Event $e) { + function (Event $e): void { /** @var CraftVariable $variable */ $variable = $e->sender; @@ -96,7 +96,7 @@ function (Event $e) { Event::on( View::class, View::EVENT_REGISTER_SITE_TEMPLATE_ROOTS, - function (RegisterTemplateRootsEvent $event) { + function (RegisterTemplateRootsEvent $event): void { $event->roots['foster-checkout'] = __DIR__ . '/templates'; } ); @@ -105,7 +105,7 @@ function (RegisterTemplateRootsEvent $event) { Event::on( UrlManager::class, UrlManager::EVENT_REGISTER_SITE_URL_RULES, - function (RegisterUrlRulesEvent $event) { + function (RegisterUrlRulesEvent $event): void { // Get the paths from the settings $paths = $this->checkout->paths(); $checkoutPath = $paths['checkout'] ?? 'checkout'; diff --git a/src/formatters/CheckoutAddressFormatter.php b/src/formatters/CheckoutAddressFormatter.php index 375ddd6..26fa1b5 100644 --- a/src/formatters/CheckoutAddressFormatter.php +++ b/src/formatters/CheckoutAddressFormatter.php @@ -14,6 +14,7 @@ public function format(AddressInterface $address, array $options = []): string if (property_exists($address, 'firstName')) { $address->firstName = null; } + if (property_exists($address, 'lastName')) { $address->lastName = null; } diff --git a/src/services/Checkout.php b/src/services/Checkout.php index bfbd453..9577254 100644 --- a/src/services/Checkout.php +++ b/src/services/Checkout.php @@ -65,7 +65,7 @@ public function note($page): ?string $note = null; - if ($elementHandle and $fieldHandle) { + if ($elementHandle && $fieldHandle) { $global = GlobalSet::find()->handle($elementHandle)->one() ?? null; $entry = Entry::find()->section($elementHandle)->one() ?? null; $element = $global ?? $entry; @@ -79,7 +79,7 @@ public function note($page): ?string } else { $note = null; } - } catch (InvalidFieldException $e) { + } catch (InvalidFieldException) { $note = null; } } @@ -130,13 +130,13 @@ public function lineItemImage(LineItem $lineItem): ?Asset if ($fieldInfo['level'] === 'variant') { try { $image = $variant->getFieldValue($fieldInfo['handle'])->one(); - } catch (InvalidFieldException $e) { + } catch (InvalidFieldException) { $image = null; } } else { try { $image = $product->getFieldValue($fieldInfo['handle'])->one(); - } catch (InvalidFieldException $e) { + } catch (InvalidFieldException) { $image = null; } } @@ -151,7 +151,7 @@ public function getCountries(): array { try { return Plugin::getInstance()->getStore()->getStore()->getCountriesList(); - } catch (InvalidConfigException $e) { + } catch (InvalidConfigException) { return []; } } @@ -163,7 +163,7 @@ public function getRegions(): array { try { return Plugin::getInstance()->getStore()->getStore()->getAdministrativeAreasListByCountryCode(); - } catch (InvalidConfigException $e) { + } catch (InvalidConfigException) { return []; } } @@ -175,7 +175,7 @@ public function getDiscounts(): array { try { return Plugin::getInstance()->getDiscounts()->allDiscounts; - } catch (InvalidConfigException $e) { + } catch (InvalidConfigException) { return []; } } @@ -187,9 +187,10 @@ public function getGateways(): array { try { $gateways = Plugin::getInstance()->gateways->getAllCustomerEnabledGateways(); - } catch (InvalidConfigException $e) { + } catch (InvalidConfigException) { $gateways = []; } + $gatewaysArr = []; foreach ($gateways as $gateway) { $gatewaysArr[] = [ diff --git a/src/web/assets/checkout/CheckoutAsset.php b/src/web/assets/checkout/CheckoutAsset.php index 9c81e5e..69f0299 100644 --- a/src/web/assets/checkout/CheckoutAsset.php +++ b/src/web/assets/checkout/CheckoutAsset.php @@ -9,7 +9,7 @@ */ class CheckoutAsset extends AssetBundle { - public function init() + public function init(): void { $this->sourcePath = __DIR__ . '/dist'; $this->js = ['js/app.js'];