From 80fefb67c81d933528a9e6474b331d40832a3d09 Mon Sep 17 00:00:00 2001 From: Robin Rijkeboer Date: Sun, 8 Mar 2026 19:26:31 +0100 Subject: [PATCH] Make plugin PHP 8.4 compatible using Rector --- Config/Config.php | 22 ++---------- Config/XmlConfig/Converter.php | 6 ++-- Config/XmlConfig/SchemaLocator.php | 10 ++---- Cron/RetryFailedWebhooks.php | 26 ++------------ CustomerData/GtmCheckout.php | 9 ++--- DataLayer/Event/AddPaymentInfo.php | 14 ++------ DataLayer/Event/AddShippingInfo.php | 22 ++++-------- DataLayer/Event/AddToCart.php | 19 +++------- DataLayer/Event/AddToWishlist.php | 8 ++--- DataLayer/Event/BeginCheckout.php | 18 ++-------- DataLayer/Event/Login.php | 8 ++--- DataLayer/Event/Logout.php | 1 + DataLayer/Event/Promotion/PromotionItem.php | 20 ++--------- DataLayer/Event/Purchase.php | 14 ++------ DataLayer/Event/PurchaseWebhookEvent.php | 26 ++------------ DataLayer/Event/Refund.php | 14 ++------ DataLayer/Event/RemoveFromCart.php | 5 ++- DataLayer/Event/SelectPromotion.php | 1 + DataLayer/Event/SignUp.php | 1 + DataLayer/Event/UserData.php | 15 ++------ DataLayer/Event/ViewCart.php | 18 ++-------- DataLayer/Event/ViewPromotion.php | 1 + DataLayer/Event/ViewSearchResult.php | 1 + DataLayer/Mapper/CartItemDataMapper.php | 33 ++++------------- DataLayer/Mapper/CategoryDataMapper.php | 11 ++---- DataLayer/Mapper/CustomerDataMapper.php | 14 ++------ DataLayer/Mapper/GuestDataMapper.php | 11 ++---- DataLayer/Mapper/OrderDataMapper.php | 22 ++---------- DataLayer/Mapper/OrderItemDataMapper.php | 36 ++++--------------- DataLayer/Mapper/ProductDataMapper.php | 31 +++------------- DataLayer/Processor/Base.php | 9 ++--- DataLayer/Processor/Cart.php | 1 + DataLayer/Processor/Category.php | 1 + DataLayer/Processor/Checkout.php | 1 + DataLayer/Processor/Product.php | 1 + DataLayer/Processor/SuccessPage.php | 1 + DataLayer/Tag/AccountId.php | 9 ++--- DataLayer/Tag/Cart/CartItems.php | 15 ++------ DataLayer/Tag/Cart/CartValue.php | 12 ++----- DataLayer/Tag/Category/CategorySize.php | 1 + DataLayer/Tag/Category/CurrentCategory.php | 12 ++----- DataLayer/Tag/Category/Products.php | 15 ++------ DataLayer/Tag/CurrencyCode.php | 15 ++------ DataLayer/Tag/EnhancedConversions.php | 12 ++----- .../Sha256EmailAddress.php | 12 ++----- DataLayer/Tag/Event.php | 1 + DataLayer/Tag/LiveOnly.php | 6 ++-- DataLayer/Tag/Order/Order.php | 18 ++-------- DataLayer/Tag/Order/OrderItems.php | 11 ++---- DataLayer/Tag/Order/UserData.php | 12 ++----- DataLayer/Tag/Page/Breadcrumbs.php | 9 ++--- DataLayer/Tag/Page/VirtualPage.php | 9 ++--- DataLayer/Tag/PagePath.php | 9 ++--- DataLayer/Tag/PageTitle.php | 9 ++--- DataLayer/Tag/PageType.php | 9 ++--- DataLayer/Tag/Product/CurrentCategoryName.php | 12 ++----- DataLayer/Tag/Product/CurrentPrice.php | 12 ++----- DataLayer/Tag/Product/CurrentProduct.php | 11 ++---- DataLayer/Tag/Product/ProductCategory.php | 11 +++--- DataLayer/Tag/Store/CurrentStore.php | 11 +++--- DataLayer/Tag/Version.php | 9 ++--- DataLayer/TagParser.php | 5 ++- Logger/Debugger.php | 21 ++--------- MageWire/Checkout.php | 17 ++------- Model/Collector/DynamicTaggingCollector.php | 8 ++--- Model/Config/Backend/ContainerConfig.php | 1 + Model/Config/Source/CategoryAttributes.php | 11 +++--- Model/Config/Source/CustomerAttributes.php | 11 +++--- Model/Config/Source/ProductAttributes.php | 12 +++---- .../Source/ViewCartOccurancesOptions.php | 1 + Model/Config/Source/WebhookTriggerOptions.php | 1 + Observer/AddAdditionalLayoutHandles.php | 12 ++----- Observer/TriggerAddToCartDataLayerEvent.php | 12 ++----- .../TriggerAddToWishlistDataLayerEvent.php | 12 ++----- Observer/TriggerCheckoutSessionSaveEvent.php | 17 +++------ Observer/TriggerLoginDataLayerEvent.php | 12 ++----- Observer/TriggerLogoutDataLayerEvent.php | 12 ++----- Observer/TriggerPurchaseDataLayerEvent.php | 15 ++------ Observer/TriggerPurchaseWebhookEvent.php | 18 ++-------- .../TriggerRemoveFromCartDataLayerEvent.php | 12 ++----- Observer/TriggerSignUpDataLayerEvent.php | 12 ++----- Plugin/AddDataToCartSection.php | 14 ++------ Plugin/AddDataToCustomerSection.php | 35 ++---------------- Plugin/AddProductDetails.php | 13 +++---- Plugin/GetProductsFromCategoryBlockPlugin.php | 14 ++------ ...iggerAddGuestPaymentInfoDataLayerEvent.php | 18 +++------- .../TriggerAddPaymentInfoDataLayerEvent.php | 21 ++++------- .../TriggerAddShippingInfoDataLayerEvent.php | 14 ++------ .../TriggerViewSearchResultDataLayerEvent.php | 11 ++---- .../CheckoutSessionDataProvider.php | 11 +++--- .../CustomerSessionDataProvider.php | 14 +++----- Setup/UpgradeSchema.php | 1 + Test/Integration/Block/DataLayerTest.php | 4 +-- Test/Integration/Block/ScriptTest.php | 12 +++---- .../DataLayer/Event/ViewCartTest.php | 2 +- .../Integration/DataLayer/Tag/VersionTest.php | 2 +- .../FixtureTrait/CreateCategory.php | 2 +- .../FixtureTrait/CreateProduct.php | 2 +- .../Page/CheckoutOnepageSuccessTest.php | 2 +- Util/Attribute/GetAttributeValue.php | 22 ++++-------- Util/CamelCase.php | 2 +- Util/CategoryProvider.php | 28 +++------------ Util/Debug.php | 18 ++-------- Util/GetCategoryPath.php | 4 +-- Util/GetCurrentCategory.php | 16 ++------- Util/GetCurrentProduct.php | 14 ++------ Util/ProductProvider.php | 11 ++---- ViewModel/Commons.php | 14 ++------ ViewModel/DataLayer.php | 30 +++------------- composer.json | 2 +- 110 files changed, 302 insertions(+), 986 deletions(-) diff --git a/Config/Config.php b/Config/Config.php index d690c4e9..19d65f44 100644 --- a/Config/Config.php +++ b/Config/Config.php @@ -16,12 +16,6 @@ class Config implements ArgumentInterface { - private ScopeConfigInterface $scopeConfig; - private CookieHelper $cookieHelper; - private StoreManagerInterface $storeManager; - private AppState $appState; - private Version $version; - /** * Config constructor. * @@ -29,18 +23,8 @@ class Config implements ArgumentInterface * @param StoreManagerInterface $storeManager * @param CookieHelper $cookieHelper */ - public function __construct( - ScopeConfigInterface $scopeConfig, - StoreManagerInterface $storeManager, - CookieHelper $cookieHelper, - AppState $appState, - Version $version - ) { - $this->scopeConfig = $scopeConfig; - $this->storeManager = $storeManager; - $this->cookieHelper = $cookieHelper; - $this->appState = $appState; - $this->version = $version; + public function __construct(private readonly ScopeConfigInterface $scopeConfig, private readonly StoreManagerInterface $storeManager, private readonly CookieHelper $cookieHelper, private readonly AppState $appState, private readonly Version $version) + { } /** @@ -189,7 +173,7 @@ public function getConfigValue(string $key, $defaultValue = null) ScopeInterface::SCOPE_STORE, $this->storeManager->getStore() ); - } catch (NoSuchEntityException $e) { + } catch (NoSuchEntityException) { return $defaultValue; } diff --git a/Config/XmlConfig/Converter.php b/Config/XmlConfig/Converter.php index 1c5e4cca..f7b70802 100644 --- a/Config/XmlConfig/Converter.php +++ b/Config/XmlConfig/Converter.php @@ -10,11 +10,8 @@ class Converter implements ConverterInterface { - private ObjectManagerInterface $objectManager; - - public function __construct(ObjectManagerInterface $objectManager) + public function __construct(private readonly ObjectManagerInterface $objectManager) { - $this->objectManager = $objectManager; } /** @@ -23,6 +20,7 @@ public function __construct(ObjectManagerInterface $objectManager) * @param DOMDocument $source * @return array */ + #[\Override] public function convert($source): array { $result = [ diff --git a/Config/XmlConfig/SchemaLocator.php b/Config/XmlConfig/SchemaLocator.php index 8945923f..eeeb472c 100644 --- a/Config/XmlConfig/SchemaLocator.php +++ b/Config/XmlConfig/SchemaLocator.php @@ -8,22 +8,17 @@ class SchemaLocator implements SchemaLocatorInterface { - /** - * @var Reader - */ - private Reader $moduleReader; - /** * @param Reader $moduleReader */ - public function __construct(Reader $moduleReader) + public function __construct(private readonly Reader $moduleReader) { - $this->moduleReader = $moduleReader; } /** * @inheritdoc */ + #[\Override] public function getSchema() { return $this->getXsdPath(); @@ -32,6 +27,7 @@ public function getSchema() /** * @inheritdoc */ + #[\Override] public function getPerFileSchema() { return $this->getXsdPath(); diff --git a/Cron/RetryFailedWebhooks.php b/Cron/RetryFailedWebhooks.php index ac68e728..182ad1a6 100644 --- a/Cron/RetryFailedWebhooks.php +++ b/Cron/RetryFailedWebhooks.php @@ -15,30 +15,8 @@ class RetryFailedWebhooks { - private OrderRepositoryInterface $orderRepository; - private OrderPaymentRepositoryInterface $orderPaymentRepository; - private SearchCriteriaBuilder $searchCriteriaBuilder; - private FilterBuilder $filterBuilder; - private PurchaseWebhookEvent $webhookEvent; - private Debugger $debugger; - private LoggerInterface $logger; - - public function __construct( - OrderRepositoryInterface $orderRepository, - OrderPaymentRepositoryInterface $orderPaymentRepository, - SearchCriteriaBuilder $searchCriteriaBuilder, - FilterBuilder $filterBuilder, - PurchaseWebhookEvent $webhookEvent, - Debugger $debugger, - LoggerInterface $logger - ) { - $this->orderRepository = $orderRepository; - $this->orderPaymentRepository = $orderPaymentRepository; - $this->searchCriteriaBuilder = $searchCriteriaBuilder; - $this->filterBuilder = $filterBuilder; - $this->webhookEvent = $webhookEvent; - $this->debugger = $debugger; - $this->logger = $logger; + public function __construct(private readonly OrderRepositoryInterface $orderRepository, private readonly OrderPaymentRepositoryInterface $orderPaymentRepository, private readonly SearchCriteriaBuilder $searchCriteriaBuilder, private readonly FilterBuilder $filterBuilder, private readonly PurchaseWebhookEvent $webhookEvent, private readonly Debugger $debugger, private readonly LoggerInterface $logger) + { } /** diff --git a/CustomerData/GtmCheckout.php b/CustomerData/GtmCheckout.php index 77952f8d..6d7379fe 100644 --- a/CustomerData/GtmCheckout.php +++ b/CustomerData/GtmCheckout.php @@ -7,20 +7,17 @@ class GtmCheckout implements SectionSourceInterface { - private CheckoutSessionDataProviderInterface $checkoutSessionDataProvider; - /** * @param CheckoutSessionDataProviderInterface $checkoutSessionDataProvider */ - public function __construct( - CheckoutSessionDataProviderInterface $checkoutSessionDataProvider - ) { - $this->checkoutSessionDataProvider = $checkoutSessionDataProvider; + public function __construct(private readonly CheckoutSessionDataProviderInterface $checkoutSessionDataProvider) + { } /** * @return array */ + #[\Override] public function getSectionData(): array { $gtmEvents = $this->checkoutSessionDataProvider->get(); diff --git a/DataLayer/Event/AddPaymentInfo.php b/DataLayer/Event/AddPaymentInfo.php index 39d2b468..8a078ed0 100644 --- a/DataLayer/Event/AddPaymentInfo.php +++ b/DataLayer/Event/AddPaymentInfo.php @@ -10,9 +10,6 @@ class AddPaymentInfo implements EventInterface { - private CartItems $cartItems; - private CartRepositoryInterface $cartRepository; - private PriceFormatter $priceFormatter; private int $cartId; private string $paymentMethod; @@ -20,19 +17,14 @@ class AddPaymentInfo implements EventInterface * @param CartRepositoryInterface $cartRepository * @param CartItems $cartItems */ - public function __construct( - CartRepositoryInterface $cartRepository, - CartItems $cartItems, - PriceFormatter $priceFormatter - ) { - $this->cartItems = $cartItems; - $this->cartRepository = $cartRepository; - $this->priceFormatter = $priceFormatter; + public function __construct(private readonly CartRepositoryInterface $cartRepository, private readonly CartItems $cartItems, private readonly PriceFormatter $priceFormatter) + { } /** * @return string[] */ + #[\Override] public function get(): array { /** @var Cart $cart */ diff --git a/DataLayer/Event/AddShippingInfo.php b/DataLayer/Event/AddShippingInfo.php index 3e562418..da94f769 100644 --- a/DataLayer/Event/AddShippingInfo.php +++ b/DataLayer/Event/AddShippingInfo.php @@ -14,28 +14,19 @@ class AddShippingInfo implements EventInterface { - private CartItems $cartItems; - private ShippingMethodManagementInterface $shippingMethodManagement; - private CheckoutSession $checkoutSession; - /** * @param CartItems $cartItems * @param ShippingMethodManagementInterface $shippingMethodManagement * @param CheckoutSession $checkoutSession */ - public function __construct( - CartItems $cartItems, - ShippingMethodManagementInterface $shippingMethodManagement, - CheckoutSession $checkoutSession - ) { - $this->cartItems = $cartItems; - $this->shippingMethodManagement = $shippingMethodManagement; - $this->checkoutSession = $checkoutSession; + public function __construct(private readonly CartItems $cartItems, private readonly ShippingMethodManagementInterface $shippingMethodManagement, private readonly CheckoutSession $checkoutSession) + { } /** * @return string[] */ + #[\Override] public function get(): array { if (false === $this->checkoutSession->hasQuote()) { @@ -44,7 +35,7 @@ public function get(): array try { $quote = $this->checkoutSession->getQuote(); - } catch (NoSuchEntityException|LocalizedException $e) { + } catch (NoSuchEntityException|LocalizedException) { return []; } @@ -74,14 +65,13 @@ public function getShippingMethodFromQuote(CartInterface $quote): ?string if ($shippingMethod instanceof ShippingMethodInterface) { return $shippingMethod->getCarrierCode().'_'.$shippingMethod->getMethodCode(); } - } catch (NoSuchEntityException $e) { - } catch (StateException $e) { + } catch (NoSuchEntityException|StateException) { } try { // @phpstan-ignore-next-line return $quote->getShippingAddress()->getShippingMethod(); - } catch (NoSuchEntityException $e) { + } catch (NoSuchEntityException) { } return null; diff --git a/DataLayer/Event/AddToCart.php b/DataLayer/Event/AddToCart.php index 2b2fc838..503280e2 100644 --- a/DataLayer/Event/AddToCart.php +++ b/DataLayer/Event/AddToCart.php @@ -14,27 +14,15 @@ class AddToCart implements EventInterface { - private ProductDataMapper $productDataMapper; - private CurrencyCode $currencyCode; - private PriceFormatter $priceFormatter; private Product $product; - private ProductRepositoryInterface $productRepository; private int $qty = 1; /** * @param ProductDataMapper $productDataMapper * @param CurrencyCode $currencyCode */ - public function __construct( - ProductDataMapper $productDataMapper, - CurrencyCode $currencyCode, - PriceFormatter $priceFormatter, - ProductRepositoryInterface $productRepository - ) { - $this->productDataMapper = $productDataMapper; - $this->currencyCode = $currencyCode; - $this->priceFormatter = $priceFormatter; - $this->productRepository = $productRepository; + public function __construct(private readonly ProductDataMapper $productDataMapper, private readonly CurrencyCode $currencyCode, private readonly PriceFormatter $priceFormatter, private readonly ProductRepositoryInterface $productRepository) + { } /** @@ -42,6 +30,7 @@ public function __construct( * @throws LocalizedException * @throws NoSuchEntityException */ + #[\Override] public function get(): array { $qty = ($this->qty > 0) ? $this->qty : 1; @@ -50,7 +39,7 @@ public function get(): array try { $product = $this->productRepository->get($this->product->getSku()); - } catch (Exception $e) { + } catch (Exception) { // Continue normal product flow since the sku is not found. } diff --git a/DataLayer/Event/AddToWishlist.php b/DataLayer/Event/AddToWishlist.php index 78f5e1b2..ec06a214 100644 --- a/DataLayer/Event/AddToWishlist.php +++ b/DataLayer/Event/AddToWishlist.php @@ -10,16 +10,13 @@ class AddToWishlist implements EventInterface { - private ProductDataMapper $productDataMapper; private ProductInterface $product; /** * @param ProductDataMapper $productDataMapper */ - public function __construct( - ProductDataMapper $productDataMapper - ) { - $this->productDataMapper = $productDataMapper; + public function __construct(private readonly ProductDataMapper $productDataMapper) + { } /** @@ -27,6 +24,7 @@ public function __construct( * @throws LocalizedException * @throws NoSuchEntityException */ + #[\Override] public function get(): array { $itemData = $this->productDataMapper->mapByProduct($this->product); diff --git a/DataLayer/Event/BeginCheckout.php b/DataLayer/Event/BeginCheckout.php index c73e8ea1..40d54725 100644 --- a/DataLayer/Event/BeginCheckout.php +++ b/DataLayer/Event/BeginCheckout.php @@ -10,29 +10,17 @@ class BeginCheckout implements EventInterface { - private Quote $quote; - private CartItems $cartItems; - private CartValue $cartValue; - private CurrencyCode $currencyCode; - /** * @param Quote $quote * @param CartItems $cartItems * @param CartValue $cartValue * @param CurrencyCode $currencyCode */ - public function __construct( - Quote $quote, - CartItems $cartItems, - CartValue $cartValue, - CurrencyCode $currencyCode - ) { - $this->quote = $quote; - $this->cartItems = $cartItems; - $this->cartValue = $cartValue; - $this->currencyCode = $currencyCode; + public function __construct(private readonly Quote $quote, private readonly CartItems $cartItems, private readonly CartValue $cartValue, private readonly CurrencyCode $currencyCode) + { } + #[\Override] public function get(): array { return [ diff --git a/DataLayer/Event/Login.php b/DataLayer/Event/Login.php index 10da504d..f4e5909c 100644 --- a/DataLayer/Event/Login.php +++ b/DataLayer/Event/Login.php @@ -10,12 +10,9 @@ class Login implements EventInterface { private CustomerInterface $customer; - private CustomerDataMapper $customerDataMapper; - public function __construct( - CustomerDataMapper $customerDataMapper - ) { - $this->customerDataMapper = $customerDataMapper; + public function __construct(private readonly CustomerDataMapper $customerDataMapper) + { } public function setCustomer(CustomerInterface $customer): Login @@ -24,6 +21,7 @@ public function setCustomer(CustomerInterface $customer): Login return $this; } + #[\Override] public function get(): array { return [ diff --git a/DataLayer/Event/Logout.php b/DataLayer/Event/Logout.php index 05059179..497f77f7 100644 --- a/DataLayer/Event/Logout.php +++ b/DataLayer/Event/Logout.php @@ -6,6 +6,7 @@ class Logout implements EventInterface { + #[\Override] public function get(): array { return [ diff --git a/DataLayer/Event/Promotion/PromotionItem.php b/DataLayer/Event/Promotion/PromotionItem.php index 2a9d9d90..9ec8df9a 100644 --- a/DataLayer/Event/Promotion/PromotionItem.php +++ b/DataLayer/Event/Promotion/PromotionItem.php @@ -4,12 +4,6 @@ class PromotionItem { - private string $id; - private string $name; - private string $createName; - private string $createSlot; - private string $locationId; - /** * @param string $id * @param string $name @@ -17,18 +11,8 @@ class PromotionItem * @param string $createSlot * @param string $locationId */ - public function __construct( - string $id, - string $name, - string $createName = '', - string $createSlot = '', - string $locationId = '' - ) { - $this->id = $id; - $this->name = $name; - $this->createName = $createName; - $this->createSlot = $createSlot; - $this->locationId = $locationId; + public function __construct(private readonly string $id, private readonly string $name, private readonly string $createName = '', private readonly string $createSlot = '', private readonly string $locationId = '') + { } public function get(): array diff --git a/DataLayer/Event/Purchase.php b/DataLayer/Event/Purchase.php index d7e60cca..c57e2bd9 100644 --- a/DataLayer/Event/Purchase.php +++ b/DataLayer/Event/Purchase.php @@ -13,23 +13,15 @@ class Purchase implements EventInterface { private ?OrderInterface $order = null; - private OrderItems $orderItems; - private Config $config; - private PriceFormatter $priceFormatter; - public function __construct( - OrderItems $orderItems, - Config $config, - PriceFormatter $priceFormatter - ) { - $this->orderItems = $orderItems; - $this->config = $config; - $this->priceFormatter = $priceFormatter; + public function __construct(private readonly OrderItems $orderItems, private readonly Config $config, private readonly PriceFormatter $priceFormatter) + { } /** * @return string[] */ + #[\Override] public function get(): array { $order = $this->order; diff --git a/DataLayer/Event/PurchaseWebhookEvent.php b/DataLayer/Event/PurchaseWebhookEvent.php index cda540c3..2f8d9b8a 100644 --- a/DataLayer/Event/PurchaseWebhookEvent.php +++ b/DataLayer/Event/PurchaseWebhookEvent.php @@ -15,30 +15,8 @@ class PurchaseWebhookEvent { - private $json; - private $clientFactory; - private $config; - private $orderItems; - private $priceFormatter; - private LoggerInterface $logger; - private Debugger $debugger; - - public function __construct( - Json $json, - ClientFactory $clientFactory, - OrderItems $orderItems, - Config $config, - PriceFormatter $priceFormatter, - LoggerInterface $logger, - Debugger $debugger - ) { - $this->json = $json; - $this->clientFactory = $clientFactory; - $this->orderItems = $orderItems; - $this->config = $config; - $this->priceFormatter = $priceFormatter; - $this->logger = $logger; - $this->debugger = $debugger; + public function __construct(private readonly Json $json, private readonly ClientFactory $clientFactory, private readonly OrderItems $orderItems, private readonly Config $config, private readonly PriceFormatter $priceFormatter, private readonly LoggerInterface $logger, private readonly Debugger $debugger) + { } public function purchase(OrderInterface $order) diff --git a/DataLayer/Event/Refund.php b/DataLayer/Event/Refund.php index a6eed045..8cba0559 100644 --- a/DataLayer/Event/Refund.php +++ b/DataLayer/Event/Refund.php @@ -12,23 +12,15 @@ class Refund implements EventInterface { private ?OrderInterface $order = null; - private OrderItems $orderItems; - private Config $config; - private PriceFormatter $priceFormatter; - public function __construct( - OrderItems $orderItems, - Config $config, - PriceFormatter $priceFormatter - ) { - $this->orderItems = $orderItems; - $this->config = $config; - $this->priceFormatter = $priceFormatter; + public function __construct(private readonly OrderItems $orderItems, private readonly Config $config, private readonly PriceFormatter $priceFormatter) + { } /** * @return string[] */ + #[\Override] public function get(): array { $order = $this->order; diff --git a/DataLayer/Event/RemoveFromCart.php b/DataLayer/Event/RemoveFromCart.php index abe6359b..2457ce6c 100644 --- a/DataLayer/Event/RemoveFromCart.php +++ b/DataLayer/Event/RemoveFromCart.php @@ -8,20 +8,19 @@ class RemoveFromCart implements EventInterface { - private CartItemDataMapper $cartItemDataMapper; private CartItemInterface $cartItem; /** * @param CartItemDataMapper $cartItemDataMapper */ - public function __construct(CartItemDataMapper $cartItemDataMapper) + public function __construct(private readonly CartItemDataMapper $cartItemDataMapper) { - $this->cartItemDataMapper = $cartItemDataMapper; } /** * @return array */ + #[\Override] public function get(): array { $cartItemData = $this->cartItemDataMapper->mapByCartItem($this->cartItem); diff --git a/DataLayer/Event/SelectPromotion.php b/DataLayer/Event/SelectPromotion.php index 67117b42..69d69caf 100644 --- a/DataLayer/Event/SelectPromotion.php +++ b/DataLayer/Event/SelectPromotion.php @@ -16,6 +16,7 @@ class SelectPromotion implements EventInterface /** * @return array */ + #[\Override] public function get(): array { $promotionsItemsData = []; diff --git a/DataLayer/Event/SignUp.php b/DataLayer/Event/SignUp.php index 9fb7b306..40630a75 100644 --- a/DataLayer/Event/SignUp.php +++ b/DataLayer/Event/SignUp.php @@ -6,6 +6,7 @@ class SignUp implements EventInterface { + #[\Override] public function get(): array { return [ diff --git a/DataLayer/Event/UserData.php b/DataLayer/Event/UserData.php index b67553c1..f93d1a91 100644 --- a/DataLayer/Event/UserData.php +++ b/DataLayer/Event/UserData.php @@ -13,21 +13,11 @@ class UserData implements EventInterface { - private PageTitle $pageTitle; - private PageType $pageType; - private CurrentStore $currentStore; - /** * @param Customer $cartItems */ - public function __construct( - PageTitle $pageTitle, - PageType $pageType, - CurrentStore $currentStore - ) { - $this->pageTitle = $pageTitle; - $this->pageType = $pageType; - $this->currentStore = $currentStore; + public function __construct(private readonly PageTitle $pageTitle, private readonly PageType $pageType, private readonly CurrentStore $currentStore) + { } /** @@ -35,6 +25,7 @@ public function __construct( * @throws LocalizedException * @throws NoSuchEntityException */ + #[\Override] public function get(): array { return [ diff --git a/DataLayer/Event/ViewCart.php b/DataLayer/Event/ViewCart.php index 4fbd09b4..31ae4658 100644 --- a/DataLayer/Event/ViewCart.php +++ b/DataLayer/Event/ViewCart.php @@ -13,27 +13,14 @@ class ViewCart implements EventInterface { - private CartItems $cartItems; - private CartValue $cartValue; - private CurrencyCode $currencyCode; - private Config $config; - /** * @param CartItems $cartItems * @param CartValue $cartValue * @param CurrencyCode $currencyCode * @param Config $config */ - public function __construct( - CartItems $cartItems, - CartValue $cartValue, - CurrencyCode $currencyCode, - Config $config - ) { - $this->cartItems = $cartItems; - $this->cartValue = $cartValue; - $this->currencyCode = $currencyCode; - $this->config = $config; + public function __construct(private readonly CartItems $cartItems, private readonly CartValue $cartValue, private readonly CurrencyCode $currencyCode, private readonly Config $config) + { } /** @@ -41,6 +28,7 @@ public function __construct( * @throws LocalizedException * @throws NoSuchEntityException */ + #[\Override] public function get(): array { return [ diff --git a/DataLayer/Event/ViewPromotion.php b/DataLayer/Event/ViewPromotion.php index 65f5f92e..4475171b 100644 --- a/DataLayer/Event/ViewPromotion.php +++ b/DataLayer/Event/ViewPromotion.php @@ -16,6 +16,7 @@ class ViewPromotion implements EventInterface /** * @return array */ + #[\Override] public function get(): array { $promotionsItemsData = []; diff --git a/DataLayer/Event/ViewSearchResult.php b/DataLayer/Event/ViewSearchResult.php index c22006c6..bb7d57b9 100644 --- a/DataLayer/Event/ViewSearchResult.php +++ b/DataLayer/Event/ViewSearchResult.php @@ -8,6 +8,7 @@ class ViewSearchResult implements EventInterface { private ?string $searchTerm = null; + #[\Override] public function get(): array { return [ diff --git a/DataLayer/Mapper/CartItemDataMapper.php b/DataLayer/Mapper/CartItemDataMapper.php index b37acb60..021e18ae 100644 --- a/DataLayer/Mapper/CartItemDataMapper.php +++ b/DataLayer/Mapper/CartItemDataMapper.php @@ -13,27 +13,14 @@ class CartItemDataMapper { - private ProductDataMapper $productDataMapper; - private ProductProvider $productProvider; - private PriceFormatter $priceFormatter; - private ScopeConfigInterface $scopeConfig; - /** * @param ProductDataMapper $productDataMapper * @param ProductProvider $productProvider * @param PriceFormatter $priceFormatter * @param ScopeConfigInterface $scopeConfig */ - public function __construct( - ProductDataMapper $productDataMapper, - ProductProvider $productProvider, - PriceFormatter $priceFormatter, - ScopeConfigInterface $scopeConfig - ) { - $this->productDataMapper = $productDataMapper; - $this->productProvider = $productProvider; - $this->priceFormatter = $priceFormatter; - $this->scopeConfig = $scopeConfig; + public function __construct(private readonly ProductDataMapper $productDataMapper, private readonly ProductProvider $productProvider, private readonly PriceFormatter $priceFormatter, private readonly ScopeConfigInterface $scopeConfig) + { } /** @@ -46,7 +33,7 @@ public function mapByCartItem(CartItemInterface $cartItem): array try { $product = $this->productProvider->getBySku($cartItem->getSku()); $cartItemData = $this->productDataMapper->mapByProduct($product); - } catch (NoSuchEntityException $e) { + } catch (NoSuchEntityException) { $cartItemData = []; } @@ -71,16 +58,10 @@ private function getPrice(CartItemInterface $cartItem): float $cartItem->getStoreId() // @phpstan-ignore-line ); - switch ($displayType) { - case Config::DISPLAY_TYPE_EXCLUDING_TAX: - case Config::DISPLAY_TYPE_BOTH: - $price = $cartItem->getConvertedPrice(); // @phpstan-ignore-line - break; - case Config::DISPLAY_TYPE_INCLUDING_TAX: - default: - $price = $cartItem->getPriceInclTax(); // @phpstan-ignore-line - break; - } + $price = match ($displayType) { + Config::DISPLAY_TYPE_EXCLUDING_TAX, Config::DISPLAY_TYPE_BOTH => $cartItem->getConvertedPrice(), + default => $cartItem->getPriceInclTax(), + }; return $this->priceFormatter->format((float)$price); } diff --git a/DataLayer/Mapper/CategoryDataMapper.php b/DataLayer/Mapper/CategoryDataMapper.php index 006f7ec7..fa005940 100644 --- a/DataLayer/Mapper/CategoryDataMapper.php +++ b/DataLayer/Mapper/CategoryDataMapper.php @@ -9,19 +9,12 @@ class CategoryDataMapper { - private Config $config; - private GetAttributeValue $getAttributeValue; - /** * @param Config $config * @param GetAttributeValue $getAttributeValue */ - public function __construct( - Config $config, - GetAttributeValue $getAttributeValue - ) { - $this->config = $config; - $this->getAttributeValue = $getAttributeValue; + public function __construct(private readonly Config $config, private readonly GetAttributeValue $getAttributeValue) + { } /** diff --git a/DataLayer/Mapper/CustomerDataMapper.php b/DataLayer/Mapper/CustomerDataMapper.php index 63fe5b84..e0b38e7c 100644 --- a/DataLayer/Mapper/CustomerDataMapper.php +++ b/DataLayer/Mapper/CustomerDataMapper.php @@ -9,23 +9,13 @@ class CustomerDataMapper { - private CamelCase $camelCase; - private Config $config; - private GetAttributeValue $getAttributeValue; - /** * @param CamelCase $camelCase * @param Config $config * @param GetAttributeValue $getAttributeValue */ - public function __construct( - CamelCase $camelCase, - Config $config, - GetAttributeValue $getAttributeValue - ) { - $this->camelCase = $camelCase; - $this->config = $config; - $this->getAttributeValue = $getAttributeValue; + public function __construct(private readonly CamelCase $camelCase, private readonly Config $config, private readonly GetAttributeValue $getAttributeValue) + { } /** diff --git a/DataLayer/Mapper/GuestDataMapper.php b/DataLayer/Mapper/GuestDataMapper.php index a01b5ac2..799f072a 100644 --- a/DataLayer/Mapper/GuestDataMapper.php +++ b/DataLayer/Mapper/GuestDataMapper.php @@ -9,19 +9,12 @@ class GuestDataMapper { - private Config $config; - private GetAttributeValue $getAttributeValue; - /** * @param Config $config * @param GetAttributeValue $getAttributeValue */ - public function __construct( - Config $config, - GetAttributeValue $getAttributeValue - ) { - $this->config = $config; - $this->getAttributeValue = $getAttributeValue; + public function __construct(private readonly Config $config, private readonly GetAttributeValue $getAttributeValue) + { } /** diff --git a/DataLayer/Mapper/OrderDataMapper.php b/DataLayer/Mapper/OrderDataMapper.php index fb48f604..3b6a6781 100644 --- a/DataLayer/Mapper/OrderDataMapper.php +++ b/DataLayer/Mapper/OrderDataMapper.php @@ -11,12 +11,6 @@ class OrderDataMapper { - private PriceFormatter $priceFormatter; - private GuestDataMapper $guestDataMapper; - private CustomerDataMapper $customerDataMapper; - private CustomerRepositoryInterface $customerRepository; - private Config $config; - /** * @param PriceFormatter $priceFormatter * @param GuestDataMapper $guestDataMapper @@ -24,18 +18,8 @@ class OrderDataMapper * @param CustomerRepositoryInterface $customerRepository * @param Config $config */ - public function __construct( - PriceFormatter $priceFormatter, - GuestDataMapper $guestDataMapper, - CustomerDataMapper $customerDataMapper, - CustomerRepositoryInterface $customerRepository, - Config $config - ) { - $this->priceFormatter = $priceFormatter; - $this->guestDataMapper = $guestDataMapper; - $this->customerDataMapper = $customerDataMapper; - $this->customerRepository = $customerRepository; - $this->config = $config; + public function __construct(private readonly PriceFormatter $priceFormatter, private readonly GuestDataMapper $guestDataMapper, private readonly CustomerDataMapper $customerDataMapper, private readonly CustomerRepositoryInterface $customerRepository, private readonly Config $config) + { } /** @@ -56,7 +40,7 @@ public function mapByOrder(OrderInterface $order): array 'shipping' => $this->priceFormatter->format((float)$order->getShippingInclTax()), 'tax' => $this->priceFormatter->format((float)$order->getTaxAmount()), 'coupon' => $order->getCouponCode(), - 'date' => date("Y-m-d", strtotime($order->getCreatedAt())), + 'date' => date("Y-m-d", strtotime((string) $order->getCreatedAt())), 'paymentType' => $this->getPaymentType($order), 'customer' => $this->getCustomerData($order), ]; diff --git a/DataLayer/Mapper/OrderItemDataMapper.php b/DataLayer/Mapper/OrderItemDataMapper.php index 979bf351..87662cf2 100644 --- a/DataLayer/Mapper/OrderItemDataMapper.php +++ b/DataLayer/Mapper/OrderItemDataMapper.php @@ -15,12 +15,6 @@ class OrderItemDataMapper { - private OrderRepositoryInterface $orderRepository; - private ProductDataMapper $productDataMapper; - private ProductRepositoryInterface $productRepository; - private PriceFormatter $priceFormatter; - private ScopeConfigInterface $scopeConfig; - /** * @param OrderRepositoryInterface $orderRepository * @param ProductDataMapper $productDataMapper @@ -28,18 +22,8 @@ class OrderItemDataMapper * @param PriceFormatter $priceFormatter * @param ScopeConfigInterface $scopeConfig */ - public function __construct( - OrderRepositoryInterface $orderRepository, - ProductDataMapper $productDataMapper, - ProductRepositoryInterface $productRepository, - PriceFormatter $priceFormatter, - ScopeConfigInterface $scopeConfig - ) { - $this->orderRepository = $orderRepository; - $this->productDataMapper = $productDataMapper; - $this->productRepository = $productRepository; - $this->priceFormatter = $priceFormatter; - $this->scopeConfig = $scopeConfig; + public function __construct(private readonly OrderRepositoryInterface $orderRepository, private readonly ProductDataMapper $productDataMapper, private readonly ProductRepositoryInterface $productRepository, private readonly PriceFormatter $priceFormatter, private readonly ScopeConfigInterface $scopeConfig) + { } /** @@ -67,7 +51,7 @@ public function mapByOrderItem(OrderItemInterface $orderItem, ?OrderInterface $o try { $product = $this->productRepository->get($orderItem->getSku()); - } catch (NoSuchEntityException $e) { + } catch (NoSuchEntityException) { return $orderItemData; } @@ -89,16 +73,10 @@ private function getPrice(OrderItemInterface $orderItem): float $orderItem->getStoreId() ); - switch ($displayType) { - case Config::DISPLAY_TYPE_EXCLUDING_TAX: - case Config::DISPLAY_TYPE_BOTH: - $price = $orderItem->getPrice(); - break; - case Config::DISPLAY_TYPE_INCLUDING_TAX: - default: - $price = $orderItem->getPriceInclTax(); - break; - } + $price = match ($displayType) { + Config::DISPLAY_TYPE_EXCLUDING_TAX, Config::DISPLAY_TYPE_BOTH => $orderItem->getPrice(), + default => $orderItem->getPriceInclTax(), + }; return $this->priceFormatter->format((float)$price); } diff --git a/DataLayer/Mapper/ProductDataMapper.php b/DataLayer/Mapper/ProductDataMapper.php index 65eed96d..d484b872 100644 --- a/DataLayer/Mapper/ProductDataMapper.php +++ b/DataLayer/Mapper/ProductDataMapper.php @@ -18,15 +18,6 @@ class ProductDataMapper { - private Config $config; - private GetAttributeValue $getAttributeValue; - private CategoryProvider $categoryProvider; - private PriceFormatter $priceFormatter; - private Configurable $configurableType; - private ProductRepositoryInterface $productRepository; - - private array $dataLayerMapping; - private int $counter = 0; /** @@ -36,22 +27,8 @@ class ProductDataMapper * @param PriceFormatter $priceFormatter * @param array $dataLayerMapping */ - public function __construct( - Config $config, - GetAttributeValue $getAttributeValue, - CategoryProvider $categoryProvider, - PriceFormatter $priceFormatter, - Configurable $configurableType, - ProductRepositoryInterface $productRepository, - array $dataLayerMapping = [] - ) { - $this->config = $config; - $this->getAttributeValue = $getAttributeValue; - $this->categoryProvider = $categoryProvider; - $this->priceFormatter = $priceFormatter; - $this->configurableType = $configurableType; - $this->productRepository = $productRepository; - $this->dataLayerMapping = $dataLayerMapping; + public function __construct(private readonly Config $config, private readonly GetAttributeValue $getAttributeValue, private readonly CategoryProvider $categoryProvider, private readonly PriceFormatter $priceFormatter, private readonly Configurable $configurableType, private readonly ProductRepositoryInterface $productRepository, private readonly array $dataLayerMapping = []) + { } /** @@ -95,7 +72,7 @@ public function mapByProduct(ProductInterface $product): array $category = $this->categoryProvider->getFirstByProduct($product); $productData[$prefix . 'list_id'] = $category->getId(); $productData[$prefix . 'list_name'] = $category->getName(); - } catch (NoSuchEntityException $noSuchEntityException) { + } catch (NoSuchEntityException) { } $productData['price'] = $this->priceFormatter->format((float)$product->getFinalPrice()); @@ -126,7 +103,7 @@ private function attachCategoriesData(ProductInterface $product, array $data): a { try { $categories = $this->categoryProvider->getAllByProduct($product); - } catch (NoSuchEntityException $e) { + } catch (NoSuchEntityException) { return $data; } diff --git a/DataLayer/Processor/Base.php b/DataLayer/Processor/Base.php index cc9dcf45..e6ea29e1 100644 --- a/DataLayer/Processor/Base.php +++ b/DataLayer/Processor/Base.php @@ -7,14 +7,11 @@ class Base implements ProcessorInterface { - private XmlConfig $xmlConfig; - - public function __construct( - XmlConfig $xmlConfig - ) { - $this->xmlConfig = $xmlConfig; + public function __construct(private readonly XmlConfig $xmlConfig) + { } + #[\Override] public function process(array $data): array { $default = $this->xmlConfig->getDefault(); diff --git a/DataLayer/Processor/Cart.php b/DataLayer/Processor/Cart.php index 9bf66d70..7ef767d0 100644 --- a/DataLayer/Processor/Cart.php +++ b/DataLayer/Processor/Cart.php @@ -9,6 +9,7 @@ class Cart implements ProcessorInterface /** * @inheritDoc */ + #[\Override] public function process(array $data): array { return $data; diff --git a/DataLayer/Processor/Category.php b/DataLayer/Processor/Category.php index 15e71eef..4be1928e 100644 --- a/DataLayer/Processor/Category.php +++ b/DataLayer/Processor/Category.php @@ -9,6 +9,7 @@ class Category implements ProcessorInterface /** * @inheritDoc */ + #[\Override] public function process(array $data): array { return $data; diff --git a/DataLayer/Processor/Checkout.php b/DataLayer/Processor/Checkout.php index fc335487..35a45396 100644 --- a/DataLayer/Processor/Checkout.php +++ b/DataLayer/Processor/Checkout.php @@ -9,6 +9,7 @@ class Checkout implements ProcessorInterface /** * @inheritDoc */ + #[\Override] public function process(array $data): array { return $data; diff --git a/DataLayer/Processor/Product.php b/DataLayer/Processor/Product.php index 3eed9928..1b88b417 100644 --- a/DataLayer/Processor/Product.php +++ b/DataLayer/Processor/Product.php @@ -9,6 +9,7 @@ class Product implements ProcessorInterface /** * @inheritDoc */ + #[\Override] public function process(array $data): array { return $data; diff --git a/DataLayer/Processor/SuccessPage.php b/DataLayer/Processor/SuccessPage.php index ad9f8b59..720e0295 100644 --- a/DataLayer/Processor/SuccessPage.php +++ b/DataLayer/Processor/SuccessPage.php @@ -9,6 +9,7 @@ class SuccessPage implements ProcessorInterface /** * @inheritDoc */ + #[\Override] public function process(array $data): array { return $data; diff --git a/DataLayer/Tag/AccountId.php b/DataLayer/Tag/AccountId.php index d8bf1521..45a15a5f 100644 --- a/DataLayer/Tag/AccountId.php +++ b/DataLayer/Tag/AccountId.php @@ -10,14 +10,11 @@ */ class AccountId implements TagInterface { - private Config $config; - - public function __construct( - Config $config - ) { - $this->config = $config; + public function __construct(private readonly Config $config) + { } + #[\Override] public function get(): string { return $this->config->getId(); diff --git a/DataLayer/Tag/Cart/CartItems.php b/DataLayer/Tag/Cart/CartItems.php index 1e24542a..c51ddec7 100644 --- a/DataLayer/Tag/Cart/CartItems.php +++ b/DataLayer/Tag/Cart/CartItems.php @@ -12,30 +12,21 @@ class CartItems implements TagInterface { - private CartModel $cartModel; - private CartItemDataMapper $cartItemDataMapper; - private ProductProvider $productProvider; - /** * @param CartModel $cartModel * @param CartItemDataMapper $cartItemDataMapper * @throws NoSuchEntityException * @throws LocalizedException */ - public function __construct( - CartModel $cartModel, - CartItemDataMapper $cartItemDataMapper, - ProductProvider $productProvider - ) { - $this->cartModel = $cartModel; - $this->cartItemDataMapper = $cartItemDataMapper; - $this->productProvider = $productProvider; + public function __construct(private readonly CartModel $cartModel, private readonly CartItemDataMapper $cartItemDataMapper, private readonly ProductProvider $productProvider) + { } /** * @return array * @throws NoSuchEntityException */ + #[\Override] public function get(): array { $cartItems = $this->cartModel->getQuote()->getAllVisibleItems(); diff --git a/DataLayer/Tag/Cart/CartValue.php b/DataLayer/Tag/Cart/CartValue.php index 0f5b7050..a88c9fe5 100644 --- a/DataLayer/Tag/Cart/CartValue.php +++ b/DataLayer/Tag/Cart/CartValue.php @@ -10,24 +10,18 @@ class CartValue implements TagInterface { - private CartModel $cartModel; - private PriceFormatter $priceFormatter; - /** * @param CartModel $cartModel * @param PriceFormatter $priceFormatter */ - public function __construct( - CartModel $cartModel, - PriceFormatter $priceFormatter - ) { - $this->cartModel = $cartModel; - $this->priceFormatter = $priceFormatter; + public function __construct(private readonly CartModel $cartModel, private readonly PriceFormatter $priceFormatter) + { } /** * @return float */ + #[\Override] public function get(): float { return $this->priceFormatter->format((float)$this->cartModel->getQuote()->getBaseGrandTotal()); diff --git a/DataLayer/Tag/Category/CategorySize.php b/DataLayer/Tag/Category/CategorySize.php index 69bc8aff..87f3c800 100644 --- a/DataLayer/Tag/Category/CategorySize.php +++ b/DataLayer/Tag/Category/CategorySize.php @@ -20,6 +20,7 @@ public function setSize(int $size = 0) /** * @return int */ + #[\Override] public function get(): int { return $this->size; diff --git a/DataLayer/Tag/Category/CurrentCategory.php b/DataLayer/Tag/Category/CurrentCategory.php index b3d416ee..e56dd8b4 100644 --- a/DataLayer/Tag/Category/CurrentCategory.php +++ b/DataLayer/Tag/Category/CurrentCategory.php @@ -9,25 +9,19 @@ class CurrentCategory implements MergeTagInterface { - private GetCurrentCategory $getCurrentCategory; - private CategoryDataMapper $categoryDataMapper; - /** * @param GetCurrentCategory $getCurrentCategory * @param CategoryDataMapper $categoryDataMapper */ - public function __construct( - GetCurrentCategory $getCurrentCategory, - CategoryDataMapper $categoryDataMapper - ) { - $this->getCurrentCategory = $getCurrentCategory; - $this->categoryDataMapper = $categoryDataMapper; + public function __construct(private readonly GetCurrentCategory $getCurrentCategory, private readonly CategoryDataMapper $categoryDataMapper) + { } /** * @return string[] * @throws NoSuchEntityException */ + #[\Override] public function merge(): array { $currentCategory = $this->getCurrentCategory->get(); diff --git a/DataLayer/Tag/Category/Products.php b/DataLayer/Tag/Category/Products.php index a8abb820..4bf33f0d 100644 --- a/DataLayer/Tag/Category/Products.php +++ b/DataLayer/Tag/Category/Products.php @@ -10,29 +10,20 @@ class Products implements TagInterface { - private GetCurrentCategoryProducts $getCurrentCategoryProducts; - private GetCurrentCategory $getCurrentCategory; - private ProductDataMapper $productDataMapper; - /** * @param GetCurrentCategoryProducts $getCurrentCategoryProducts * @param GetCurrentCategory $getCurrentCategory * @param ProductDataMapper $productDataMapper */ - public function __construct( - GetCurrentCategoryProducts $getCurrentCategoryProducts, - GetCurrentCategory $getCurrentCategory, - ProductDataMapper $productDataMapper - ) { - $this->getCurrentCategoryProducts = $getCurrentCategoryProducts; - $this->getCurrentCategory = $getCurrentCategory; - $this->productDataMapper = $productDataMapper; + public function __construct(private readonly GetCurrentCategoryProducts $getCurrentCategoryProducts, private readonly GetCurrentCategory $getCurrentCategory, private readonly ProductDataMapper $productDataMapper) + { } /** * @return array * @throws NoSuchEntityException */ + #[\Override] public function get(): array { $productsData = []; diff --git a/DataLayer/Tag/CurrencyCode.php b/DataLayer/Tag/CurrencyCode.php index 0173fd20..56851fc3 100644 --- a/DataLayer/Tag/CurrencyCode.php +++ b/DataLayer/Tag/CurrencyCode.php @@ -9,20 +9,11 @@ use Tagging\GTM\Logger\Debugger; class CurrencyCode implements TagInterface { - private StoreManagerInterface $storeManager; - private LoggerInterface $logger; - private Debugger $debugger; - - public function __construct( - StoreManagerInterface $storeManager, - LoggerInterface $logger, - Debugger $debugger - ) { - $this->storeManager = $storeManager; - $this->logger = $logger; - $this->debugger = $debugger; + public function __construct(private readonly StoreManagerInterface $storeManager, private readonly LoggerInterface $logger, private readonly Debugger $debugger) + { } + #[\Override] public function get(): string { try { diff --git a/DataLayer/Tag/EnhancedConversions.php b/DataLayer/Tag/EnhancedConversions.php index 72034b07..62b283a7 100644 --- a/DataLayer/Tag/EnhancedConversions.php +++ b/DataLayer/Tag/EnhancedConversions.php @@ -10,21 +10,15 @@ class EnhancedConversions implements MergeTagInterface { - private CheckoutSession $checkoutSession; - private OrderRepositoryInterface $orderRepository; - /** * @param CheckoutSession $checkoutSession * @param OrderRepositoryInterface $orderRepository */ - public function __construct( - CheckoutSession $checkoutSession, - OrderRepositoryInterface $orderRepository - ) { - $this->checkoutSession = $checkoutSession; - $this->orderRepository = $orderRepository; + public function __construct(private readonly CheckoutSession $checkoutSession, private readonly OrderRepositoryInterface $orderRepository) + { } + #[\Override] public function merge(): array { return [ diff --git a/DataLayer/Tag/EnhancedConversions/Sha256EmailAddress.php b/DataLayer/Tag/EnhancedConversions/Sha256EmailAddress.php index 2ae489fd..63e5840a 100644 --- a/DataLayer/Tag/EnhancedConversions/Sha256EmailAddress.php +++ b/DataLayer/Tag/EnhancedConversions/Sha256EmailAddress.php @@ -9,21 +9,15 @@ class Sha256EmailAddress implements TagInterface { - private CheckoutSession $checkoutSession; - private OrderRepositoryInterface $orderRepository; - /** * @param CheckoutSession $checkoutSession * @param OrderRepositoryInterface $orderRepository */ - public function __construct( - CheckoutSession $checkoutSession, - OrderRepositoryInterface $orderRepository - ) { - $this->checkoutSession = $checkoutSession; - $this->orderRepository = $orderRepository; + public function __construct(private readonly CheckoutSession $checkoutSession, private readonly OrderRepositoryInterface $orderRepository) + { } + #[\Override] public function get(): string { $order = $this->getOrder(); diff --git a/DataLayer/Tag/Event.php b/DataLayer/Tag/Event.php index c12a93f4..da89f29e 100644 --- a/DataLayer/Tag/Event.php +++ b/DataLayer/Tag/Event.php @@ -6,6 +6,7 @@ class Event implements TagInterface { + #[\Override] public function get() { return null; diff --git a/DataLayer/Tag/LiveOnly.php b/DataLayer/Tag/LiveOnly.php index cb3778ac..235cb2b9 100644 --- a/DataLayer/Tag/LiveOnly.php +++ b/DataLayer/Tag/LiveOnly.php @@ -7,16 +7,14 @@ class LiveOnly implements TagInterface { - private State $state; - /** * @param State $state */ - public function __construct(State $state) + public function __construct(private readonly State $state) { - $this->state = $state; } + #[\Override] public function get(): bool { return $this->state->getMode() === State::MODE_PRODUCTION; diff --git a/DataLayer/Tag/Order/Order.php b/DataLayer/Tag/Order/Order.php index fe357d44..4921159a 100644 --- a/DataLayer/Tag/Order/Order.php +++ b/DataLayer/Tag/Order/Order.php @@ -11,31 +11,19 @@ class Order implements MergeTagInterface { - private CheckoutSession $checkoutSession; - private OrderRepositoryInterface $orderRepository; - private Config $config; - private PriceFormatter $priceFormatter; - /** * @param CheckoutSession $checkoutSession * @param OrderRepositoryInterface $orderRepository * @param Config $config */ - public function __construct( - CheckoutSession $checkoutSession, - OrderRepositoryInterface $orderRepository, - Config $config, - PriceFormatter $priceFormatter - ) { - $this->checkoutSession = $checkoutSession; - $this->orderRepository = $orderRepository; - $this->config = $config; - $this->priceFormatter = $priceFormatter; + public function __construct(private readonly CheckoutSession $checkoutSession, private readonly OrderRepositoryInterface $orderRepository, private readonly Config $config, private readonly PriceFormatter $priceFormatter) + { } /** * @return array */ + #[\Override] public function merge(): array { $order = $this->getOrder(); diff --git a/DataLayer/Tag/Order/OrderItems.php b/DataLayer/Tag/Order/OrderItems.php index e0cd0cfd..29a6d6ac 100644 --- a/DataLayer/Tag/Order/OrderItems.php +++ b/DataLayer/Tag/Order/OrderItems.php @@ -9,25 +9,20 @@ class OrderItems implements TagInterface { - private CheckoutSession $checkoutSession; - private OrderItemDataMapper $orderItemDataMapper; private ?OrderInterface $order = null; /** * @param CheckoutSession $checkoutSession * @param OrderItemDataMapper $orderItemDataMapper */ - public function __construct( - CheckoutSession $checkoutSession, - OrderItemDataMapper $orderItemDataMapper - ) { - $this->checkoutSession = $checkoutSession; - $this->orderItemDataMapper = $orderItemDataMapper; + public function __construct(private readonly CheckoutSession $checkoutSession, private readonly OrderItemDataMapper $orderItemDataMapper) + { } /** * @return array */ + #[\Override] public function get(): array { $order = $this->order; diff --git a/DataLayer/Tag/Order/UserData.php b/DataLayer/Tag/Order/UserData.php index 9f624336..9419a2b5 100644 --- a/DataLayer/Tag/Order/UserData.php +++ b/DataLayer/Tag/Order/UserData.php @@ -11,20 +11,14 @@ class UserData implements TagInterface { - private CheckoutSession $checkoutSession; - private OrderRepositoryInterface $orderRepository; - - public function __construct( - CheckoutSession $checkoutSession, - OrderRepositoryInterface $orderRepository - ) { - $this->checkoutSession = $checkoutSession; - $this->orderRepository = $orderRepository; + public function __construct(private readonly CheckoutSession $checkoutSession, private readonly OrderRepositoryInterface $orderRepository) + { } /** * @return array */ + #[\Override] public function get(): array { $order = $this->getOrder(); diff --git a/DataLayer/Tag/Page/Breadcrumbs.php b/DataLayer/Tag/Page/Breadcrumbs.php index ba6f72ba..e2d42acc 100644 --- a/DataLayer/Tag/Page/Breadcrumbs.php +++ b/DataLayer/Tag/Page/Breadcrumbs.php @@ -7,14 +7,11 @@ class Breadcrumbs implements TagInterface { - private CatalogHelper $catalogHelper; - - public function __construct( - CatalogHelper $catalogHelper - ) { - $this->catalogHelper = $catalogHelper; + public function __construct(private readonly CatalogHelper $catalogHelper) + { } + #[\Override] public function get(): array { $data = []; diff --git a/DataLayer/Tag/Page/VirtualPage.php b/DataLayer/Tag/Page/VirtualPage.php index 2a916a9c..d06520eb 100644 --- a/DataLayer/Tag/Page/VirtualPage.php +++ b/DataLayer/Tag/Page/VirtualPage.php @@ -8,14 +8,11 @@ class VirtualPage implements TagInterface { - private StoreManagerInterface $storeManager; - - public function __construct( - StoreManagerInterface $storeManager - ) { - $this->storeManager = $storeManager; + public function __construct(private readonly StoreManagerInterface $storeManager) + { } + #[\Override] public function get(): string { /** @var Store $store */ diff --git a/DataLayer/Tag/PagePath.php b/DataLayer/Tag/PagePath.php index 6b2329e2..6c9185fe 100644 --- a/DataLayer/Tag/PagePath.php +++ b/DataLayer/Tag/PagePath.php @@ -7,14 +7,11 @@ class PagePath implements TagInterface { - private UrlInterface $url; - - public function __construct( - UrlInterface $url - ) { - $this->url = $url; + public function __construct(private readonly UrlInterface $url) + { } + #[\Override] public function get(): string { return $this->url->getCurrentUrl(); diff --git a/DataLayer/Tag/PageTitle.php b/DataLayer/Tag/PageTitle.php index d3cb95b1..41dbf29c 100644 --- a/DataLayer/Tag/PageTitle.php +++ b/DataLayer/Tag/PageTitle.php @@ -7,14 +7,11 @@ class PageTitle implements TagInterface { - private Title $pageTitle; - - public function __construct( - Title $pageTitle - ) { - $this->pageTitle = $pageTitle; + public function __construct(private readonly Title $pageTitle) + { } + #[\Override] public function get(): string { return $this->pageTitle->get(); diff --git a/DataLayer/Tag/PageType.php b/DataLayer/Tag/PageType.php index 28bbf7b2..ae7c5cff 100644 --- a/DataLayer/Tag/PageType.php +++ b/DataLayer/Tag/PageType.php @@ -7,14 +7,11 @@ class PageType implements TagInterface { - private RequestInterface $request; - - public function __construct( - RequestInterface $request - ) { - $this->request = $request; + public function __construct(private readonly RequestInterface $request) + { } + #[\Override] public function get(): string { $controllerName = $this->request->getControllerName(); // @phpstan-ignore-line diff --git a/DataLayer/Tag/Product/CurrentCategoryName.php b/DataLayer/Tag/Product/CurrentCategoryName.php index a1480749..ac9f9184 100644 --- a/DataLayer/Tag/Product/CurrentCategoryName.php +++ b/DataLayer/Tag/Product/CurrentCategoryName.php @@ -8,25 +8,19 @@ class CurrentCategoryName implements TagInterface { - private GetCurrentProduct $getCurrentProduct; - private ProductCategory $productCategory; - /** * @param GetCurrentProduct $getCurrentProduct * @param ProductCategory $productCategory */ - public function __construct( - GetCurrentProduct $getCurrentProduct, - ProductCategory $productCategory - ) { - $this->getCurrentProduct = $getCurrentProduct; - $this->productCategory = $productCategory; + public function __construct(private readonly GetCurrentProduct $getCurrentProduct, private readonly ProductCategory $productCategory) + { } /** * @return string * @throws NoSuchEntityException */ + #[\Override] public function get(): string { $currentProduct = $this->getCurrentProduct->get(); diff --git a/DataLayer/Tag/Product/CurrentPrice.php b/DataLayer/Tag/Product/CurrentPrice.php index 69f0cde7..9423294c 100644 --- a/DataLayer/Tag/Product/CurrentPrice.php +++ b/DataLayer/Tag/Product/CurrentPrice.php @@ -10,25 +10,19 @@ class CurrentPrice implements TagInterface { - private GetCurrentProduct $getCurrentProduct; - private PriceFormatter $priceFormatter; - /** * @param GetCurrentProduct $getCurrentProduct * @param PriceFormatter $priceFormatter */ - public function __construct( - GetCurrentProduct $getCurrentProduct, - PriceFormatter $priceFormatter - ) { - $this->getCurrentProduct = $getCurrentProduct; - $this->priceFormatter = $priceFormatter; + public function __construct(private readonly GetCurrentProduct $getCurrentProduct, private readonly PriceFormatter $priceFormatter) + { } /** * @return float * @throws NoSuchEntityException */ + #[\Override] public function get(): float { $product = $this->getCurrentProduct->get(); diff --git a/DataLayer/Tag/Product/CurrentProduct.php b/DataLayer/Tag/Product/CurrentProduct.php index 917b24ad..b79d5720 100644 --- a/DataLayer/Tag/Product/CurrentProduct.php +++ b/DataLayer/Tag/Product/CurrentProduct.php @@ -11,25 +11,20 @@ class CurrentProduct implements MergeTagInterface { private ?ProductInterface $product = null; - private GetCurrentProduct $getCurrentProduct; - private ProductDataMapper $productDataMapper; /** * @param GetCurrentProduct $getCurrentProduct * @param ProductDataMapper $productDataMapper */ - public function __construct( - GetCurrentProduct $getCurrentProduct, - ProductDataMapper $productDataMapper - ) { - $this->getCurrentProduct = $getCurrentProduct; - $this->productDataMapper = $productDataMapper; + public function __construct(private readonly GetCurrentProduct $getCurrentProduct, private readonly ProductDataMapper $productDataMapper) + { } /** * @return string[] * @throws NoSuchEntityException */ + #[\Override] public function merge(): array { return $this->productDataMapper->mapByProduct($this->getProduct()); diff --git a/DataLayer/Tag/Product/ProductCategory.php b/DataLayer/Tag/Product/ProductCategory.php index bbde875a..a5c2d3f2 100644 --- a/DataLayer/Tag/Product/ProductCategory.php +++ b/DataLayer/Tag/Product/ProductCategory.php @@ -11,21 +11,19 @@ class ProductCategory implements ProductTagInterface { private Product $product; - private CategoryProvider $categoryProvider; /** * @param CategoryProvider $categoryProvider */ - public function __construct( - CategoryProvider $categoryProvider - ) { - $this->categoryProvider = $categoryProvider; + public function __construct(private readonly CategoryProvider $categoryProvider) + { } /** * @param Product $product * @return $this */ + #[\Override] public function setProduct(Product $product): ProductCategory { $this->product = $product; @@ -35,6 +33,7 @@ public function setProduct(Product $product): ProductCategory /** * @return string */ + #[\Override] public function get(): string { /** @var Category|null $category */ @@ -45,7 +44,7 @@ public function get(): string try { return $this->categoryProvider->getFirstByProduct($this->product)->getName(); - } catch (NoSuchEntityException $e) { + } catch (NoSuchEntityException) { return ''; } } diff --git a/DataLayer/Tag/Store/CurrentStore.php b/DataLayer/Tag/Store/CurrentStore.php index 237e9e07..1bb845c0 100644 --- a/DataLayer/Tag/Store/CurrentStore.php +++ b/DataLayer/Tag/Store/CurrentStore.php @@ -9,14 +9,11 @@ class CurrentStore implements TagInterface { - private $storeManager; - - public function __construct( - StoreManagerInterface $storeManager - ) { - $this->storeManager = $storeManager; + public function __construct(private readonly StoreManagerInterface $storeManager) + { } + #[\Override] public function get(): array { try { @@ -26,7 +23,7 @@ public function get(): array 'website_id' => $this->storeManager->getStore()->getWebsiteId(), 'url' => $this->storeManager->getStore()->getCurrentUrl(), ]; - } catch (\Exception $e) { + } catch (\Exception) { return [ 'code' => null, 'name' => null, diff --git a/DataLayer/Tag/Version.php b/DataLayer/Tag/Version.php index c9c1be5e..03133356 100644 --- a/DataLayer/Tag/Version.php +++ b/DataLayer/Tag/Version.php @@ -7,17 +7,14 @@ class Version implements TagInterface { - private ComponentRegistrar $composerRegistrar; - /** * @param ComponentRegistrar $composerRegistrar */ - public function __construct( - ComponentRegistrar $composerRegistrar - ) { - $this->composerRegistrar = $composerRegistrar; + public function __construct(private readonly ComponentRegistrar $composerRegistrar) + { } + #[\Override] public function get(): string { $path = $this->composerRegistrar->getPath('module', 'Tagging_GTM'); diff --git a/DataLayer/TagParser.php b/DataLayer/TagParser.php index 13dea5d1..5b456a79 100644 --- a/DataLayer/TagParser.php +++ b/DataLayer/TagParser.php @@ -31,11 +31,10 @@ public function parse(array $data, array $processors = []): array /** * @param string $tagName - * @param mixed $tagValue * @param array $data * @return array */ - private function convertTag($tagName, $tagValue, array $data): array + private function convertTag($tagName, mixed $tagValue, array $data): array { if ($tagValue instanceof MergeTagInterface) { unset($data[$tagName]); @@ -74,6 +73,6 @@ private function getValueFromFromTagValueObject(ArgumentInterface $tagValueObjec return $tagValueObject->get(); } - throw new RuntimeException('Unknown object in data layer: ' . get_class($tagValueObject)); + throw new RuntimeException('Unknown object in data layer: ' . $tagValueObject::class); } } diff --git a/Logger/Debugger.php b/Logger/Debugger.php index 0424297f..5e87fe04 100644 --- a/Logger/Debugger.php +++ b/Logger/Debugger.php @@ -10,37 +10,22 @@ class Debugger { - /** - * @var Config - */ - private $config; - - /** - * @var LoggerInterface - */ - private $logger; - /** * Debugger constructor. * * @param Config $config * @param LoggerInterface $logger */ - public function __construct( - Config $config, - LoggerInterface $logger - ) { - $this->config = $config; - $this->logger = $logger; + public function __construct(private readonly Config $config, private readonly LoggerInterface $logger) + { } /** * @param string $msg - * @param mixed $data * * @return bool */ - public function debug(string $msg, $data = null): bool + public function debug(string $msg, mixed $data = null): bool { if ($this->config->isDebug() === false) { return false; diff --git a/MageWire/Checkout.php b/MageWire/Checkout.php index b5a84d7c..5d0c4577 100644 --- a/MageWire/Checkout.php +++ b/MageWire/Checkout.php @@ -10,21 +10,8 @@ class Checkout extends Component { - private CheckoutSession $checkoutSession; - private BeginCheckout $beginCheckout; - private AddShippingInfo $addShippingInfo; - private AddPaymentInfo $addPaymentInfo; - - public function __construct( - CheckoutSession $checkoutSession, - BeginCheckout $beginCheckout, - AddShippingInfo $addShippingInfo, - AddPaymentInfo $addPaymentInfo - ) { - $this->checkoutSession = $checkoutSession; - $this->beginCheckout = $beginCheckout; - $this->addShippingInfo = $addShippingInfo; - $this->addPaymentInfo = $addPaymentInfo; + public function __construct(private readonly CheckoutSession $checkoutSession, private readonly BeginCheckout $beginCheckout, private readonly AddShippingInfo $addShippingInfo, private readonly AddPaymentInfo $addPaymentInfo) + { } public function boot(): void diff --git a/Model/Collector/DynamicTaggingCollector.php b/Model/Collector/DynamicTaggingCollector.php index f51bfb3a..6121be11 100644 --- a/Model/Collector/DynamicTaggingCollector.php +++ b/Model/Collector/DynamicTaggingCollector.php @@ -10,13 +10,11 @@ class DynamicTaggingCollector implements PolicyCollectorInterface { - private Config $config; - - public function __construct(Config $config) + public function __construct(private readonly Config $config) { - $this->config = $config; } + #[\Override] public function collect(array $defaultPolicies = []): array { try { @@ -66,7 +64,7 @@ public function collect(array $defaultPolicies = []): array return array_merge($defaultPolicies, $policies); - } catch (\Exception $e) { + } catch (\Exception) { return $defaultPolicies; } } diff --git a/Model/Config/Backend/ContainerConfig.php b/Model/Config/Backend/ContainerConfig.php index 2e6d638b..24038567 100644 --- a/Model/Config/Backend/ContainerConfig.php +++ b/Model/Config/Backend/ContainerConfig.php @@ -7,6 +7,7 @@ class ContainerConfig extends Value { + #[\Override] public function beforeSave() { if (false === $this->validate()) { diff --git a/Model/Config/Source/CategoryAttributes.php b/Model/Config/Source/CategoryAttributes.php index 6de7f571..0afae223 100644 --- a/Model/Config/Source/CategoryAttributes.php +++ b/Model/Config/Source/CategoryAttributes.php @@ -9,23 +9,20 @@ class CategoryAttributes implements OptionSourceInterface { - private CategoryAttributeRepositoryInterface $categoryAttributeRepository; - private SearchCriteriaBuilder $searchCriteriaBuilder; - private SortOrderFactory $sortOrderFactory; + private readonly SortOrderFactory $sortOrderFactory; public function __construct( - CategoryAttributeRepositoryInterface $categoryAttributeRepository, - SearchCriteriaBuilder $searchCriteriaBuilder, + private readonly CategoryAttributeRepositoryInterface $categoryAttributeRepository, + private readonly SearchCriteriaBuilder $searchCriteriaBuilder, SortOrderFactory $sortOrderFactory ) { - $this->categoryAttributeRepository = $categoryAttributeRepository; - $this->searchCriteriaBuilder = $searchCriteriaBuilder; $this->sortOrderFactory = $sortOrderFactory; } /** * {@inheritdoc} */ + #[\Override] public function toOptionArray(): array { $options = [['value' => '', 'label' => '']]; diff --git a/Model/Config/Source/CustomerAttributes.php b/Model/Config/Source/CustomerAttributes.php index 27fd27e1..f405eb94 100644 --- a/Model/Config/Source/CustomerAttributes.php +++ b/Model/Config/Source/CustomerAttributes.php @@ -10,23 +10,20 @@ class CustomerAttributes implements OptionSourceInterface { - private AttributeRepositoryInterface $attributeRepository; - private SearchCriteriaBuilder $searchCriteriaBuilder; - private SortOrderFactory $sortOrderFactory; + private readonly SortOrderFactory $sortOrderFactory; public function __construct( - AttributeRepositoryInterface $attributeRepository, - SearchCriteriaBuilder $searchCriteriaBuilder, + private readonly AttributeRepositoryInterface $attributeRepository, + private readonly SearchCriteriaBuilder $searchCriteriaBuilder, SortOrderFactory $sortOrderFactory ) { - $this->attributeRepository = $attributeRepository; - $this->searchCriteriaBuilder = $searchCriteriaBuilder; $this->sortOrderFactory = $sortOrderFactory; } /** * {@inheritdoc} */ + #[\Override] public function toOptionArray(): array { $options = [['value' => '', 'label' => '']]; diff --git a/Model/Config/Source/ProductAttributes.php b/Model/Config/Source/ProductAttributes.php index 3e530d66..b104e6be 100644 --- a/Model/Config/Source/ProductAttributes.php +++ b/Model/Config/Source/ProductAttributes.php @@ -10,24 +10,20 @@ class ProductAttributes implements OptionSourceInterface { const REQUIRED_ATTRIBUTES = ['id', 'sku', 'name']; - - private ProductAttributeRepositoryInterface $productAttributeRepository; - private SearchCriteriaBuilder $searchCriteriaBuilder; - private SortOrderFactory $sortOrderFactory; + private readonly SortOrderFactory $sortOrderFactory; public function __construct( - ProductAttributeRepositoryInterface $productAttributeRepository, - SearchCriteriaBuilder $searchCriteriaBuilder, + private readonly ProductAttributeRepositoryInterface $productAttributeRepository, + private readonly SearchCriteriaBuilder $searchCriteriaBuilder, SortOrderFactory $sortOrderFactory ) { - $this->productAttributeRepository = $productAttributeRepository; - $this->searchCriteriaBuilder = $searchCriteriaBuilder; $this->sortOrderFactory = $sortOrderFactory; } /** * {@inheritdoc} */ + #[\Override] public function toOptionArray(): array { $options = [['value' => '', 'label' => '']]; diff --git a/Model/Config/Source/ViewCartOccurancesOptions.php b/Model/Config/Source/ViewCartOccurancesOptions.php index e827f4bd..6aa32b4f 100644 --- a/Model/Config/Source/ViewCartOccurancesOptions.php +++ b/Model/Config/Source/ViewCartOccurancesOptions.php @@ -12,6 +12,7 @@ class ViewCartOccurancesOptions implements OptionSourceInterface /** * {@inheritdoc} */ + #[\Override] public function toOptionArray(): array { $options = [ diff --git a/Model/Config/Source/WebhookTriggerOptions.php b/Model/Config/Source/WebhookTriggerOptions.php index 0c04065f..93ba178d 100644 --- a/Model/Config/Source/WebhookTriggerOptions.php +++ b/Model/Config/Source/WebhookTriggerOptions.php @@ -12,6 +12,7 @@ class WebhookTriggerOptions implements OptionSourceInterface /** * {@inheritdoc} */ + #[\Override] public function toOptionArray(): array { $options = [ diff --git a/Observer/AddAdditionalLayoutHandles.php b/Observer/AddAdditionalLayoutHandles.php index e0d74092..04c28776 100644 --- a/Observer/AddAdditionalLayoutHandles.php +++ b/Observer/AddAdditionalLayoutHandles.php @@ -9,17 +9,11 @@ class AddAdditionalLayoutHandles implements ObserverInterface { - private RequestInterface $request; - private LayoutInterface $layout; - - public function __construct( - Request $request, - LayoutInterface $layout - ) { - $this->request = $request; - $this->layout = $layout; + public function __construct(private readonly RequestInterface $request, private readonly LayoutInterface $layout) + { } + #[\Override] public function execute(Observer $observer) { $handles = []; diff --git a/Observer/TriggerAddToCartDataLayerEvent.php b/Observer/TriggerAddToCartDataLayerEvent.php index 4991b2ba..3c83d2e9 100644 --- a/Observer/TriggerAddToCartDataLayerEvent.php +++ b/Observer/TriggerAddToCartDataLayerEvent.php @@ -10,17 +10,11 @@ class TriggerAddToCartDataLayerEvent implements ObserverInterface { - private CheckoutSessionDataProviderInterface $checkoutSessionDataProvider; - private AddToCartEvent $addToCartEvent; - - public function __construct( - CheckoutSessionDataProviderInterface $checkoutSessionDataProvider, - AddToCartEvent $addToCartEvent - ) { - $this->checkoutSessionDataProvider = $checkoutSessionDataProvider; - $this->addToCartEvent = $addToCartEvent; + public function __construct(private readonly CheckoutSessionDataProviderInterface $checkoutSessionDataProvider, private readonly AddToCartEvent $addToCartEvent) + { } + #[\Override] public function execute(Observer $observer) { /** @var ProductInterface $product */ diff --git a/Observer/TriggerAddToWishlistDataLayerEvent.php b/Observer/TriggerAddToWishlistDataLayerEvent.php index 106c5460..75bafeeb 100644 --- a/Observer/TriggerAddToWishlistDataLayerEvent.php +++ b/Observer/TriggerAddToWishlistDataLayerEvent.php @@ -10,17 +10,11 @@ class TriggerAddToWishlistDataLayerEvent implements ObserverInterface { - private CustomerSessionDataProviderInterface $customerSessionDataProvider; - private AddToWishlistEvent $addToWishlistEvent; - - public function __construct( - CustomerSessionDataProviderInterface $customerSessionDataProvider, - AddToWishlistEvent $addToWishlistEvent - ) { - $this->customerSessionDataProvider = $customerSessionDataProvider; - $this->addToWishlistEvent = $addToWishlistEvent; + public function __construct(private readonly CustomerSessionDataProviderInterface $customerSessionDataProvider, private readonly AddToWishlistEvent $addToWishlistEvent) + { } + #[\Override] public function execute(Observer $observer) { /** @var ProductInterface $product */ diff --git a/Observer/TriggerCheckoutSessionSaveEvent.php b/Observer/TriggerCheckoutSessionSaveEvent.php index 14d94f79..9a527e7b 100644 --- a/Observer/TriggerCheckoutSessionSaveEvent.php +++ b/Observer/TriggerCheckoutSessionSaveEvent.php @@ -10,20 +10,11 @@ use Tagging\GTM\Logger\Debugger; class TriggerCheckoutSessionSaveEvent implements ObserverInterface { - private CookieManagerInterface $cookieManager; - private OrderRepositoryInterface $orderRepository; - private Debugger $debugger; - - public function __construct( - CookieManagerInterface $cookieManager, - OrderRepositoryInterface $orderRepository, - Debugger $debugger - ) { - $this->cookieManager = $cookieManager; - $this->orderRepository = $orderRepository; - $this->debugger = $debugger; + public function __construct(private readonly CookieManagerInterface $cookieManager, private readonly OrderRepositoryInterface $orderRepository, private readonly Debugger $debugger) + { } + #[\Override] public function execute(Observer $observer) { try { @@ -34,7 +25,7 @@ public function execute(Observer $observer) $marketingCookie = $this->cookieManager->getCookie('trytagging_user_data', 'e30='); $this->debugger->debug("TriggerCheckoutSessionSaveEvent: Cookie value: " . $marketingCookie, $marketingCookie); - $marketingCookie = json_decode(base64_decode($marketingCookie), true); + $marketingCookie = json_decode(base64_decode((string) $marketingCookie), true); $marketingCookie['ip'] = $_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['HTTP_CLIENT_IP'] ?? $_SERVER['HTTP_X_REAL_IP'] ?? diff --git a/Observer/TriggerLoginDataLayerEvent.php b/Observer/TriggerLoginDataLayerEvent.php index ca09d7a4..ca4c8912 100644 --- a/Observer/TriggerLoginDataLayerEvent.php +++ b/Observer/TriggerLoginDataLayerEvent.php @@ -9,17 +9,11 @@ class TriggerLoginDataLayerEvent implements ObserverInterface { - private CustomerSessionDataProviderInterface $customerSessionDataProvider; - private LoginEvent $loginEvent; - - public function __construct( - CustomerSessionDataProviderInterface $customerSessionDataProvider, - LoginEvent $loginEvent - ) { - $this->customerSessionDataProvider = $customerSessionDataProvider; - $this->loginEvent = $loginEvent; + public function __construct(private readonly CustomerSessionDataProviderInterface $customerSessionDataProvider, private readonly LoginEvent $loginEvent) + { } + #[\Override] public function execute(Observer $observer) { $customer = $observer->getEvent()->getCustomer(); diff --git a/Observer/TriggerLogoutDataLayerEvent.php b/Observer/TriggerLogoutDataLayerEvent.php index 3f413fc3..8bfdd11b 100644 --- a/Observer/TriggerLogoutDataLayerEvent.php +++ b/Observer/TriggerLogoutDataLayerEvent.php @@ -9,17 +9,11 @@ class TriggerLogoutDataLayerEvent implements ObserverInterface { - private CustomerSessionDataProviderInterface $customerSessionDataProvider; - private LogoutEvent $logoutEvent; - - public function __construct( - CustomerSessionDataProviderInterface $customerSessionDataProvider, - LogoutEvent $logoutEvent - ) { - $this->customerSessionDataProvider = $customerSessionDataProvider; - $this->logoutEvent = $logoutEvent; + public function __construct(private readonly CustomerSessionDataProviderInterface $customerSessionDataProvider, private readonly LogoutEvent $logoutEvent) + { } + #[\Override] public function execute(Observer $observer) { $this->customerSessionDataProvider->add('logout_event', $this->logoutEvent->get()); diff --git a/Observer/TriggerPurchaseDataLayerEvent.php b/Observer/TriggerPurchaseDataLayerEvent.php index 0d579da1..f489e91e 100644 --- a/Observer/TriggerPurchaseDataLayerEvent.php +++ b/Observer/TriggerPurchaseDataLayerEvent.php @@ -12,20 +12,11 @@ class TriggerPurchaseDataLayerEvent implements ObserverInterface { - private CheckoutSessionDataProviderInterface $checkoutSessionDataProvider; - private PurchaseEvent $purchaseEvent; - private Debugger $debugger; - - public function __construct( - CheckoutSessionDataProviderInterface $checkoutSessionDataProvider, - PurchaseEvent $purchaseEvent, - Debugger $debugger - ) { - $this->checkoutSessionDataProvider = $checkoutSessionDataProvider; - $this->purchaseEvent = $purchaseEvent; - $this->debugger = $debugger; + public function __construct(private readonly CheckoutSessionDataProviderInterface $checkoutSessionDataProvider, private readonly PurchaseEvent $purchaseEvent, private readonly Debugger $debugger) + { } + #[\Override] public function execute(Observer $observer) { /** @var OrderInterface $order */ diff --git a/Observer/TriggerPurchaseWebhookEvent.php b/Observer/TriggerPurchaseWebhookEvent.php index 5e4901ef..08429bc4 100644 --- a/Observer/TriggerPurchaseWebhookEvent.php +++ b/Observer/TriggerPurchaseWebhookEvent.php @@ -16,23 +16,11 @@ class TriggerPurchaseWebhookEvent implements ObserverInterface { - private PurchaseWebhookEvent $webhookEvent; - private Debugger $debugger; - private OrderPaymentRepositoryInterface $orderPaymentRepository; - private Config $config; - - public function __construct( - PurchaseWebhookEvent $webhookEvent, - Debugger $debugger, - OrderPaymentRepositoryInterface $orderPaymentRepository, - Config $config - ) { - $this->webhookEvent = $webhookEvent; - $this->debugger = $debugger; - $this->orderPaymentRepository = $orderPaymentRepository; - $this->config = $config; + public function __construct(private readonly PurchaseWebhookEvent $webhookEvent, private readonly Debugger $debugger, private readonly OrderPaymentRepositoryInterface $orderPaymentRepository, private readonly Config $config) + { } + #[\Override] public function execute(Observer $observer) { /** @var OrderInterface $order */ diff --git a/Observer/TriggerRemoveFromCartDataLayerEvent.php b/Observer/TriggerRemoveFromCartDataLayerEvent.php index 1ead6eae..2cbd89b9 100644 --- a/Observer/TriggerRemoveFromCartDataLayerEvent.php +++ b/Observer/TriggerRemoveFromCartDataLayerEvent.php @@ -10,17 +10,11 @@ class TriggerRemoveFromCartDataLayerEvent implements ObserverInterface { - private CheckoutSessionDataProviderInterface $checkoutSessionDataProvider; - private RemoveFromCartEvent $removeFromCartEvent; - - public function __construct( - CheckoutSessionDataProviderInterface $checkoutSessionDataProvider, - RemoveFromCartEvent $removeFromCartEvent - ) { - $this->checkoutSessionDataProvider = $checkoutSessionDataProvider; - $this->removeFromCartEvent = $removeFromCartEvent; + public function __construct(private readonly CheckoutSessionDataProviderInterface $checkoutSessionDataProvider, private readonly RemoveFromCartEvent $removeFromCartEvent) + { } + #[\Override] public function execute(Observer $observer) { /** @var CartItemInterface $quoteItem */ diff --git a/Observer/TriggerSignUpDataLayerEvent.php b/Observer/TriggerSignUpDataLayerEvent.php index dfa30fa3..6865830d 100644 --- a/Observer/TriggerSignUpDataLayerEvent.php +++ b/Observer/TriggerSignUpDataLayerEvent.php @@ -9,17 +9,11 @@ class TriggerSignUpDataLayerEvent implements ObserverInterface { - private CustomerSessionDataProviderInterface $customerSessionDataProvider; - private SignUpEvent $signUpEvent; - - public function __construct( - CustomerSessionDataProviderInterface $customerSessionDataProvider, - SignUpEvent $signUpEvent - ) { - $this->customerSessionDataProvider = $customerSessionDataProvider; - $this->signUpEvent = $signUpEvent; + public function __construct(private readonly CustomerSessionDataProviderInterface $customerSessionDataProvider, private readonly SignUpEvent $signUpEvent) + { } + #[\Override] public function execute(Observer $observer) { $eventData = $this->signUpEvent->get(); diff --git a/Plugin/AddDataToCartSection.php b/Plugin/AddDataToCartSection.php index fa8c5fb1..5a0ef2c1 100644 --- a/Plugin/AddDataToCartSection.php +++ b/Plugin/AddDataToCartSection.php @@ -17,23 +17,13 @@ class AddDataToCartSection { - private CheckoutCart $checkoutCart; - private CheckoutSessionDataProvider $checkoutSessionDataProvider; - private ViewCartEvent $viewCartEvent; - /** * @param CheckoutCart $checkoutCart * @param CheckoutSessionDataProvider $checkoutSessionDataProvider * @param ViewCartEvent $viewCartEvent */ - public function __construct( - CheckoutCart $checkoutCart, - CheckoutSessionDataProvider $checkoutSessionDataProvider, - ViewCartEvent $viewCartEvent - ) { - $this->checkoutCart = $checkoutCart; - $this->checkoutSessionDataProvider = $checkoutSessionDataProvider; - $this->viewCartEvent = $viewCartEvent; + public function __construct(private readonly CheckoutCart $checkoutCart, private readonly CheckoutSessionDataProvider $checkoutSessionDataProvider, private readonly ViewCartEvent $viewCartEvent) + { } /** diff --git a/Plugin/AddDataToCustomerSection.php b/Plugin/AddDataToCustomerSection.php index 5fefb0bb..72554388 100644 --- a/Plugin/AddDataToCustomerSection.php +++ b/Plugin/AddDataToCustomerSection.php @@ -25,16 +25,6 @@ class AddDataToCustomerSection { - private CustomerSession $customerSession; - private GroupRepositoryInterface $groupRepository; - private CustomerSessionDataProviderInterface $customerSessionDataProvider; - private CustomerDataMapper $customerDataMapper; - private CustomerRepositoryInterface $customerRepository; - private CollectionFactory $orderCollectionFactory; - private LoggerInterface $logger; - private Debugger $debugger; - private Config $config; - /** * Customer constructor. * @param CustomerSession $customerSession @@ -43,36 +33,17 @@ class AddDataToCustomerSection * @param CustomerDataMapper $customerDataMapper * @param CustomerRepositoryInterface $customerRepository */ - public function __construct( - CustomerSession $customerSession, - GroupRepositoryInterface $groupRepository, - CustomerSessionDataProviderInterface $customerSessionDataProvider, - CustomerDataMapper $customerDataMapper, - CustomerRepositoryInterface $customerRepository, - CollectionFactory $orderCollectionFactory, - LoggerInterface $logger, - Debugger $debugger, - Config $config - ) { - $this->customerSession = $customerSession; - $this->groupRepository = $groupRepository; - $this->customerSessionDataProvider = $customerSessionDataProvider; - $this->customerDataMapper = $customerDataMapper; - $this->customerRepository = $customerRepository; - $this->orderCollectionFactory = $orderCollectionFactory; - $this->logger = $logger; - $this->debugger = $debugger; - $this->config = $config; + public function __construct(private readonly CustomerSession $customerSession, private readonly GroupRepositoryInterface $groupRepository, private readonly CustomerSessionDataProviderInterface $customerSessionDataProvider, private readonly CustomerDataMapper $customerDataMapper, private readonly CustomerRepositoryInterface $customerRepository, private readonly CollectionFactory $orderCollectionFactory, private readonly LoggerInterface $logger, private readonly Debugger $debugger, private readonly Config $config) + { } /** * @param CustomerData $subject - * @param mixed $result * @return mixed * @throws LocalizedException * @throws NoSuchEntityException */ - public function afterGetSectionData(CustomerData $subject, $result) + public function afterGetSectionData(CustomerData $subject, mixed $result) { if (!is_array($result)) { return $result; diff --git a/Plugin/AddProductDetails.php b/Plugin/AddProductDetails.php index 8f599cc2..e035d87b 100644 --- a/Plugin/AddProductDetails.php +++ b/Plugin/AddProductDetails.php @@ -11,25 +11,20 @@ class AddProductDetails { - private LayoutInterface $layout; - - public function __construct( - LayoutInterface $layout - ) { - $this->layout = $layout; + public function __construct(private readonly LayoutInterface $layout) + { } /** * @param AbstractProduct $abstractProduct - * @param mixed $html * @param ProductInterface $product * @return string */ - public function afterGetProductDetailsHtml(AbstractProduct $abstractProduct, $html, ProductInterface $product) + public function afterGetProductDetailsHtml(AbstractProduct $abstractProduct, mixed $html, ProductInterface $product) { try { $block = $this->getProductDetailsBlock(); - } catch (BlockNotFound $blockNotFound) { + } catch (BlockNotFound) { return $html; } diff --git a/Plugin/GetProductsFromCategoryBlockPlugin.php b/Plugin/GetProductsFromCategoryBlockPlugin.php index 4bc4c1b7..913c7190 100644 --- a/Plugin/GetProductsFromCategoryBlockPlugin.php +++ b/Plugin/GetProductsFromCategoryBlockPlugin.php @@ -10,22 +10,12 @@ class GetProductsFromCategoryBlockPlugin { - private CategorySize $categorySize; - private GetCurrentCategoryProducts $getCurrentCategoryProducts; - private Config $config; - /** * GetProductsFromCategoryBlockPlugin constructor. * @param CategorySize $categorySize */ - public function __construct( - CategorySize $categorySize, - GetCurrentCategoryProducts $getCurrentCategoryProducts, - Config $config - ) { - $this->categorySize = $categorySize; - $this->getCurrentCategoryProducts = $getCurrentCategoryProducts; - $this->config = $config; + public function __construct(private readonly CategorySize $categorySize, private readonly GetCurrentCategoryProducts $getCurrentCategoryProducts, private readonly Config $config) + { } /** diff --git a/Plugin/TriggerAddGuestPaymentInfoDataLayerEvent.php b/Plugin/TriggerAddGuestPaymentInfoDataLayerEvent.php index 3403722c..57577a73 100644 --- a/Plugin/TriggerAddGuestPaymentInfoDataLayerEvent.php +++ b/Plugin/TriggerAddGuestPaymentInfoDataLayerEvent.php @@ -11,18 +11,8 @@ class TriggerAddGuestPaymentInfoDataLayerEvent { - private CheckoutSessionDataProviderInterface $checkoutSessionDataProvider; - private AddPaymentInfo $addPaymentInfo; - private MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId; - - public function __construct( - CheckoutSessionDataProviderInterface $checkoutSessionDataProvider, - AddPaymentInfo $addPaymentInfo, - MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId - ) { - $this->checkoutSessionDataProvider = $checkoutSessionDataProvider; - $this->addPaymentInfo = $addPaymentInfo; - $this->maskedQuoteIdToQuoteId = $maskedQuoteIdToQuoteId; + public function __construct(private readonly CheckoutSessionDataProviderInterface $checkoutSessionDataProvider, private readonly AddPaymentInfo $addPaymentInfo, private readonly MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId) + { } public function afterSavePaymentInformationAndPlaceOrder( @@ -31,7 +21,7 @@ public function afterSavePaymentInformationAndPlaceOrder( $cartId, $email, PaymentInterface $paymentMethod, - AddressInterface $billingAddress = null + ?AddressInterface $billingAddress = null ) { $cartId = $this->maskedQuoteIdToQuoteId->execute($cartId); $addPaymentInfoEventData = $this->addPaymentInfo @@ -49,7 +39,7 @@ public function afterSavePaymentInformation( $cartId, $email, PaymentInterface $paymentMethod, - AddressInterface $billingAddress = null + ?AddressInterface $billingAddress = null ) { $cartId = $this->maskedQuoteIdToQuoteId->execute($cartId); $addPaymentInfoEventData = $this->addPaymentInfo diff --git a/Plugin/TriggerAddPaymentInfoDataLayerEvent.php b/Plugin/TriggerAddPaymentInfoDataLayerEvent.php index 7dc35005..538c8495 100644 --- a/Plugin/TriggerAddPaymentInfoDataLayerEvent.php +++ b/Plugin/TriggerAddPaymentInfoDataLayerEvent.php @@ -10,31 +10,22 @@ class TriggerAddPaymentInfoDataLayerEvent { - private CheckoutSessionDataProviderInterface $checkoutSessionDataProvider; - private AddPaymentInfo $addPaymentInfo; - - public function __construct( - CheckoutSessionDataProviderInterface $checkoutSessionDataProvider, - AddPaymentInfo $addPaymentInfo - ) { - $this->checkoutSessionDataProvider = $checkoutSessionDataProvider; - $this->addPaymentInfo = $addPaymentInfo; + public function __construct(private readonly CheckoutSessionDataProviderInterface $checkoutSessionDataProvider, private readonly AddPaymentInfo $addPaymentInfo) + { } /** * @param PaymentInformationManagementInterface $subject - * @param mixed $orderId - * @param mixed $cartId * @param PaymentInterface $paymentMethod * @param AddressInterface|null $billingAddress * @return mixed */ public function afterSavePaymentInformationAndPlaceOrder( PaymentInformationManagementInterface $subject, - $orderId, - $cartId, + mixed $orderId, + mixed $cartId, PaymentInterface $paymentMethod, - AddressInterface $billingAddress = null + ?AddressInterface $billingAddress = null ) { $addPaymentInfoEventData = $this->addPaymentInfo ->setPaymentMethod($paymentMethod->getMethod()) @@ -58,7 +49,7 @@ public function afterSavePaymentInformation( $orderId, $cartId, PaymentInterface $paymentMethod, - AddressInterface $billingAddress = null + ?AddressInterface $billingAddress = null ) { $addPaymentInfoEventData = $this->addPaymentInfo ->setPaymentMethod($paymentMethod->getMethod()) diff --git a/Plugin/TriggerAddShippingInfoDataLayerEvent.php b/Plugin/TriggerAddShippingInfoDataLayerEvent.php index c6cdafe6..9cc1a293 100644 --- a/Plugin/TriggerAddShippingInfoDataLayerEvent.php +++ b/Plugin/TriggerAddShippingInfoDataLayerEvent.php @@ -10,28 +10,20 @@ class TriggerAddShippingInfoDataLayerEvent { - private CheckoutSessionDataProviderInterface $checkoutSessionDataProvider; - private AddShippingInfo $addShippingInfo; - - public function __construct( - CheckoutSessionDataProviderInterface $checkoutSessionDataProvider, - AddShippingInfo $addShippingInfo - ) { - $this->checkoutSessionDataProvider = $checkoutSessionDataProvider; - $this->addShippingInfo = $addShippingInfo; + public function __construct(private readonly CheckoutSessionDataProviderInterface $checkoutSessionDataProvider, private readonly AddShippingInfo $addShippingInfo) + { } /** * @param ShippingInformationManagementInterface $subject * @param PaymentDetailsInterface $paymentDetails - * @param mixed $cartId * @param ShippingInformationInterface $addressInformation * @return PaymentDetailsInterface */ public function afterSaveAddressInformation( ShippingInformationManagementInterface $subject, PaymentDetailsInterface $paymentDetails, - $cartId, + mixed $cartId, ShippingInformationInterface $addressInformation ) { diff --git a/Plugin/TriggerViewSearchResultDataLayerEvent.php b/Plugin/TriggerViewSearchResultDataLayerEvent.php index 3628e59c..2f04779b 100644 --- a/Plugin/TriggerViewSearchResultDataLayerEvent.php +++ b/Plugin/TriggerViewSearchResultDataLayerEvent.php @@ -8,15 +8,8 @@ class TriggerViewSearchResultDataLayerEvent { - private ViewSearchResultEvent $viewSearchResultEvent; - private CustomerSessionDataProviderInterface $customerSessionDataProvider; - - public function __construct( - ViewSearchResultEvent $viewSearchResultEvent, - CustomerSessionDataProviderInterface $customerSessionDataProvider - ) { - $this->viewSearchResultEvent = $viewSearchResultEvent; - $this->customerSessionDataProvider = $customerSessionDataProvider; + public function __construct(private readonly ViewSearchResultEvent $viewSearchResultEvent, private readonly CustomerSessionDataProviderInterface $customerSessionDataProvider) + { } public function afterExecute(Index $subject, $return) diff --git a/SessionDataProvider/CheckoutSessionDataProvider.php b/SessionDataProvider/CheckoutSessionDataProvider.php index 0b4f82c4..df1f8596 100644 --- a/SessionDataProvider/CheckoutSessionDataProvider.php +++ b/SessionDataProvider/CheckoutSessionDataProvider.php @@ -8,14 +8,11 @@ class CheckoutSessionDataProvider implements CheckoutSessionDataProviderInterface { - private CheckoutSession $checkoutSession; - - public function __construct( - CheckoutSession $checkoutSession - ) { - $this->checkoutSession = $checkoutSession; + public function __construct(private readonly CheckoutSession $checkoutSession) + { } + #[\Override] public function add(string $identifier, array $data) { $gtmData = $this->get(); @@ -23,6 +20,7 @@ public function add(string $identifier, array $data) $this->checkoutSession->setYireoGtmData($gtmData); } + #[\Override] public function get(): array { $gtmData = $this->checkoutSession->getYireoGtmData(); @@ -33,6 +31,7 @@ public function get(): array return []; } + #[\Override] public function clear() { $this->checkoutSession->setYireoGtmData([]); diff --git a/SessionDataProvider/CustomerSessionDataProvider.php b/SessionDataProvider/CustomerSessionDataProvider.php index eb64ec86..2894d491 100644 --- a/SessionDataProvider/CustomerSessionDataProvider.php +++ b/SessionDataProvider/CustomerSessionDataProvider.php @@ -8,17 +8,11 @@ class CustomerSessionDataProvider implements CustomerSessionDataProviderInterface { - private CustomerSession $customerSession; - private Debugger $debugger; - - public function __construct( - CustomerSession $customerSession, - Debugger $debugger - ) { - $this->customerSession = $customerSession; - $this->debugger = $debugger; + public function __construct(private readonly CustomerSession $customerSession, private readonly Debugger $debugger) + { } + #[\Override] public function add(string $identifier, array $data) { $gtmData = $this->get(); @@ -27,6 +21,7 @@ public function add(string $identifier, array $data) $this->customerSession->setYireoGtmData($gtmData); } + #[\Override] public function get(): array { $gtmData = $this->customerSession->getYireoGtmData(); @@ -37,6 +32,7 @@ public function get(): array return []; } + #[\Override] public function clear() { $this->customerSession->setYireoGtmData([]); diff --git a/Setup/UpgradeSchema.php b/Setup/UpgradeSchema.php index 7404bf4e..e61dc9d6 100644 --- a/Setup/UpgradeSchema.php +++ b/Setup/UpgradeSchema.php @@ -12,6 +12,7 @@ class UpgradeSchema implements UpgradeSchemaInterface { + #[\Override] public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context) { $installer = $setup; diff --git a/Test/Integration/Block/DataLayerTest.php b/Test/Integration/Block/DataLayerTest.php index a16351aa..cee04c24 100644 --- a/Test/Integration/Block/DataLayerTest.php +++ b/Test/Integration/Block/DataLayerTest.php @@ -35,7 +35,7 @@ public function testValidBlockContent() $block->setData('config', ObjectManager::getInstance()->get(Config::class)); $html = $block->toHtml(); - $this->assertTrue((bool)strpos($html, 'googleTagManagerPush'), 'Data layer not found in block output'); + $this->assertTrue((bool)strpos((string) $html, 'googleTagManagerPush'), 'Data layer not found in block output'); } /** @@ -59,6 +59,6 @@ public function testValidBodyContent() $this->assertNotFalse($block, 'Block "Tagging_GTM.data-layer" is empty'); $array = $this->layout->getUpdate()->asArray(); - $this->assertTrue((bool)strpos($body, 'googleTagManagerPush'), 'Data layer not found in HTML body: '. var_export($array, true)); + $this->assertTrue((bool)strpos((string) $body, 'googleTagManagerPush'), 'Data layer not found in HTML body: '. var_export($array, true)); } } diff --git a/Test/Integration/Block/ScriptTest.php b/Test/Integration/Block/ScriptTest.php index d5ca7799..bc8a09b1 100644 --- a/Test/Integration/Block/ScriptTest.php +++ b/Test/Integration/Block/ScriptTest.php @@ -30,9 +30,9 @@ public function testValidBlockContent() $this->assertStringContainsString('Tagging_GTM', $this->layout->getUpdate()->asString()); $body = $this->getResponse()->getBody(); // @phpstan-ignore-line - $this->assertTrue((bool)strpos($body, 'https://gtm.tryforwarder.com'), 'Script not found in HTML body: ' . $body); - $this->assertTrue(substr_count($body, 'var ADPAGE_TEST_CONFIG = true') === 2, 'Config script found in HTML head: ' . $body); - $this->assertTrue((bool)strpos($body, 'window.Tagging_PLACED_BY_PLUGIN = true'), 'Did not found window settings: ' . $body); + $this->assertTrue((bool)strpos((string) $body, 'https://gtm.tryforwarder.com'), 'Script not found in HTML body: ' . $body); + $this->assertTrue(substr_count((string) $body, 'var ADPAGE_TEST_CONFIG = true') === 2, 'Config script found in HTML head: ' . $body); + $this->assertTrue((bool)strpos((string) $body, 'window.Tagging_PLACED_BY_PLUGIN = true'), 'Did not found window settings: ' . $body); } /** @@ -54,8 +54,8 @@ public function testDisableScriptPlacement() $this->assertStringContainsString('Tagging_GTM', $this->layout->getUpdate()->asString()); $body = $this->getResponse()->getBody(); // @phpstan-ignore-line - $this->assertTrue(!(bool)strpos($body, 'https://gtm.tryforwarder.com'), 'Script found in HTML body: ' . $body); - $this->assertTrue(substr_count($body, 'var ADPAGE_TEST_CONFIG = true') === 1, 'Config script found in HTML head: ' . $body); // Script is also once loaded in the config so if only once the script is not placed - $this->assertTrue((bool)strpos($body, 'window.Tagging_PLACED_BY_PLUGIN = false'), 'Did not found window settings: ' . $body); + $this->assertTrue(!(bool)strpos((string) $body, 'https://gtm.tryforwarder.com'), 'Script found in HTML body: ' . $body); + $this->assertTrue(substr_count((string) $body, 'var ADPAGE_TEST_CONFIG = true') === 1, 'Config script found in HTML head: ' . $body); // Script is also once loaded in the config so if only once the script is not placed + $this->assertTrue((bool)strpos((string) $body, 'window.Tagging_PLACED_BY_PLUGIN = false'), 'Did not found window settings: ' . $body); } } diff --git a/Test/Integration/DataLayer/Event/ViewCartTest.php b/Test/Integration/DataLayer/Event/ViewCartTest.php index c335dfd4..85fbbc24 100644 --- a/Test/Integration/DataLayer/Event/ViewCartTest.php +++ b/Test/Integration/DataLayer/Event/ViewCartTest.php @@ -22,7 +22,7 @@ class ViewCartTest extends TestCase * @magentoAppArea frontend * @magentoAppIsolation enabled */ - public function testValidViewCartEvent() + public function testValidViewCartEvent(): never { $this->markTestSkipped('Broken test'); $om = ObjectManager::getInstance(); diff --git a/Test/Integration/DataLayer/Tag/VersionTest.php b/Test/Integration/DataLayer/Tag/VersionTest.php index 6ef3bfdf..dd615aba 100644 --- a/Test/Integration/DataLayer/Tag/VersionTest.php +++ b/Test/Integration/DataLayer/Tag/VersionTest.php @@ -14,6 +14,6 @@ public function testIfVersionIsSemantic() // SemVer 2.0.0 compliant regex pattern that supports pre-release identifiers // Matches: X.Y.Z, X.Y.Z-alpha1, X.Y.Z-beta1, X.Y.Z-rc1, etc. $semverPattern = '/^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/'; - $this->assertTrue((bool)preg_match($semverPattern, $version->get())); + $this->assertTrue((bool)preg_match($semverPattern, (string) $version->get())); } } diff --git a/Test/Integration/FixtureTrait/CreateCategory.php b/Test/Integration/FixtureTrait/CreateCategory.php index 474340b0..e73818ee 100644 --- a/Test/Integration/FixtureTrait/CreateCategory.php +++ b/Test/Integration/FixtureTrait/CreateCategory.php @@ -26,7 +26,7 @@ public function createCategory( /** @var $category Category */ $category = $categoryFactory->create(); $category->setId($id) - ->setName(isset($data['name']) ? $data['name'] : 'Category ' . $id) + ->setName($data['name'] ?? 'Category ' . $id) ->setParentId($parentId) ->setPath('1/' . $parentId . '/' . $id) ->setUrlKey('category' . $id) diff --git a/Test/Integration/FixtureTrait/CreateProduct.php b/Test/Integration/FixtureTrait/CreateProduct.php index 63843eb5..19ab83af 100644 --- a/Test/Integration/FixtureTrait/CreateProduct.php +++ b/Test/Integration/FixtureTrait/CreateProduct.php @@ -109,7 +109,7 @@ private function deleteProduct(int $id) 'catalog_url_rewrite_product_category' ).'` WHERE product_id='.$id ); - } catch (NoSuchEntityException $e) { + } catch (NoSuchEntityException) { } } diff --git a/Test/Integration/Page/CheckoutOnepageSuccessTest.php b/Test/Integration/Page/CheckoutOnepageSuccessTest.php index 1e6ccbd9..1e5ef99d 100644 --- a/Test/Integration/Page/CheckoutOnepageSuccessTest.php +++ b/Test/Integration/Page/CheckoutOnepageSuccessTest.php @@ -16,6 +16,7 @@ class CheckoutOnepageSuccessTest extends PageTestCase /** * @inheritdoc */ + #[\Override] protected function setUp(): void { parent::setUp(); @@ -29,7 +30,6 @@ protected function setUp(): void protected function tearDown(): void { $this->_objectManager->removeSharedInstance(CheckoutSession::class); - parent::tearDown(); } /** diff --git a/Util/Attribute/GetAttributeValue.php b/Util/Attribute/GetAttributeValue.php index b7f13d91..88086109 100644 --- a/Util/Attribute/GetAttributeValue.php +++ b/Util/Attribute/GetAttributeValue.php @@ -24,19 +24,12 @@ class GetAttributeValue { - private EavConfig $eavConfig; - private CamelCase $camelCase; - /** * @param EavConfig $eavConfig * @param CamelCase $camelCase */ - public function __construct( - EavConfig $eavConfig, - CamelCase $camelCase - ) { - $this->eavConfig = $eavConfig; - $this->camelCase = $camelCase; + public function __construct(private readonly EavConfig $eavConfig, private readonly CamelCase $camelCase) + { } /** @@ -108,10 +101,9 @@ public function getAttributeValue(CustomAttributesDataInterface $entity, string /** * @param Attribute $attribute - * @param mixed $attributeValue * @return mixed|string */ - private function filterAttributeValue(AbstractAttribute $attribute, $attributeValue) + private function filterAttributeValue(AbstractAttribute $attribute, mixed $attributeValue) { if (in_array($attribute->getFrontendInput(), ['textarea', 'text']) && !is_array($attributeValue)) { return strip_tags((string)$attributeValue); @@ -130,11 +122,10 @@ private function filterAttributeValue(AbstractAttribute $attribute, $attributeVa /** * @param AbstractAttribute $attribute - * @param mixed $attributeValue * @return string * @throws LocalizedException */ - private function getAttributeValueFromSelect(AbstractAttribute $attribute, $attributeValue): string + private function getAttributeValueFromSelect(AbstractAttribute $attribute, mixed $attributeValue): string { if (empty($attributeValue)) { return ''; @@ -152,11 +143,10 @@ private function getAttributeValueFromSelect(AbstractAttribute $attribute, $attr /** * @param AbstractAttribute $attribute - * @param mixed $attributeValue * @return array * @throws LocalizedException */ - private function getAttributeValueFromMultiSelect(AbstractAttribute $attribute, $attributeValue): array + private function getAttributeValueFromMultiSelect(AbstractAttribute $attribute, mixed $attributeValue): array { if (empty($attributeValue)) { return []; @@ -164,7 +154,7 @@ private function getAttributeValueFromMultiSelect(AbstractAttribute $attribute, $attributeValues = is_array($attributeValue) ? $attributeValue - : explode(',', $attributeValue); + : explode(',', (string) $attributeValue); $options = $attribute->getSource()->getAllOptions(); $attributeLabels = []; diff --git a/Util/CamelCase.php b/Util/CamelCase.php index 08ceb2d6..749c8768 100644 --- a/Util/CamelCase.php +++ b/Util/CamelCase.php @@ -18,7 +18,7 @@ class CamelCase */ public function from(string $string): string { - return strtolower(trim(preg_replace('/([A-Z]|[0-9]+)/', "_$1", $string), '_')); + return strtolower(trim((string) preg_replace('/([A-Z]|[0-9]+)/', "_$1", $string), '_')); } /** diff --git a/Util/CategoryProvider.php b/Util/CategoryProvider.php index 31a84850..d94a801e 100644 --- a/Util/CategoryProvider.php +++ b/Util/CategoryProvider.php @@ -28,24 +28,8 @@ class CategoryProvider */ private array $loadedCategories = []; - private CategoryListInterface $categoryListRepository; - private FilterBuilder $filterBuilder; - private SearchCriteriaBuilder $searchCriteriaBuilder; - private FilterGroupBuilder $filterGroupBuilder; - private StoreManagerInterface $storeManager; - - public function __construct( - CategoryListInterface $categoryListRepository, - FilterBuilder $filterBuilder, - SearchCriteriaBuilder $searchCriteriaBuilder, - FilterGroupBuilder $filterGroupBuilder, - StoreManagerInterface $storeManager - ) { - $this->categoryListRepository = $categoryListRepository; - $this->filterBuilder = $filterBuilder; - $this->searchCriteriaBuilder = $searchCriteriaBuilder; - $this->filterGroupBuilder = $filterGroupBuilder; - $this->storeManager = $storeManager; + public function __construct(private readonly CategoryListInterface $categoryListRepository, private readonly FilterBuilder $filterBuilder, private readonly SearchCriteriaBuilder $searchCriteriaBuilder, private readonly FilterGroupBuilder $filterGroupBuilder, private readonly StoreManagerInterface $storeManager) + { } /** @@ -96,9 +80,7 @@ public function getLoadedCategories(): array } } - return array_filter($this->loadedCategories, static function (CategoryInterface $category) { - return $category->getIsActive(); - }); + return array_filter($this->loadedCategories, static fn(CategoryInterface $category) => $category->getIsActive()); } /** @@ -194,9 +176,7 @@ private function loadCategoriesByIds(array $categoryIds): array private function filterRootCategoryIdFromCategoryIds(array $categoryIds): array { $rootCategoryId = $this->getRootCategoryId(); - return array_filter($categoryIds, static function ($categoryId) use ($rootCategoryId) { - return (int)$categoryId !== $rootCategoryId; - }); + return array_filter($categoryIds, static fn($categoryId) => (int)$categoryId !== $rootCategoryId); } /** diff --git a/Util/Debug.php b/Util/Debug.php index d0db5bb6..63a671e9 100644 --- a/Util/Debug.php +++ b/Util/Debug.php @@ -15,28 +15,14 @@ class Debug { - /** - * @var Config - */ - private $config; - - /** - * @var LoggerInterface - */ - private $logger; - /** * Data constructor. * * @param Config $config * @param LoggerInterface $logger */ - public function __construct( - Config $config, - LoggerInterface $logger - ) { - $this->config = $config; - $this->logger = $logger; + public function __construct(private readonly Config $config, private readonly LoggerInterface $logger) + { } /** diff --git a/Util/GetCategoryPath.php b/Util/GetCategoryPath.php index 4f8f9d5e..de6496bc 100644 --- a/Util/GetCategoryPath.php +++ b/Util/GetCategoryPath.php @@ -39,14 +39,14 @@ public function getCategoryPath(?CategoryModel $category = null): string } $categoryPath = $category->getPath(); - $categoryIdArray = explode('/', $categoryPath); + $categoryIdArray = explode('/', (string) $categoryPath); $categoryNames = []; foreach ($categoryIdArray as $categoryId) { if (!in_array($categoryId, self::ROOT_CATEGORY_IDS)) { try { $category = $this->categoryRepository->get($categoryId); - } catch (NoSuchEntityException $e) { + } catch (NoSuchEntityException) { continue; } $categoryNames[] = $category->getName(); diff --git a/Util/GetCurrentCategory.php b/Util/GetCurrentCategory.php index fcb48667..eaf0cf01 100644 --- a/Util/GetCurrentCategory.php +++ b/Util/GetCurrentCategory.php @@ -11,18 +11,8 @@ class GetCurrentCategory { - private RequestInterface $request; - private CategoryRepositoryInterface $categoryRepository; - private StoreManagerInterface $storeManager; - - public function __construct( - RequestInterface $request, - CategoryRepositoryInterface $categoryRepository, - StoreManagerInterface $storeManager - ) { - $this->request = $request; - $this->categoryRepository = $categoryRepository; - $this->storeManager = $storeManager; + public function __construct(private readonly RequestInterface $request, private readonly CategoryRepositoryInterface $categoryRepository, private readonly StoreManagerInterface $storeManager) + { } /** @@ -34,7 +24,7 @@ public function get(): CategoryInterface $categoryId = (int)$this->request->getParam('id'); try { $category = $this->categoryRepository->get($categoryId); - } catch (NoSuchEntityException $e) { + } catch (NoSuchEntityException) { /** @var Store $store */ $store = $this->storeManager->getStore(); $category = $this->categoryRepository->get($store->getRootCategoryId()); diff --git a/Util/GetCurrentProduct.php b/Util/GetCurrentProduct.php index 56761277..37736923 100644 --- a/Util/GetCurrentProduct.php +++ b/Util/GetCurrentProduct.php @@ -11,18 +11,8 @@ class GetCurrentProduct { - private RequestInterface $request; - private ProductRepositoryInterface $productRepository; - private StoreManagerInterface $storeManager; - - public function __construct( - RequestInterface $request, - ProductRepositoryInterface $productRepository, - StoreManagerInterface $storeManager - ) { - $this->request = $request; - $this->productRepository = $productRepository; - $this->storeManager = $storeManager; + public function __construct(private readonly RequestInterface $request, private readonly ProductRepositoryInterface $productRepository, private readonly StoreManagerInterface $storeManager) + { } /** diff --git a/Util/ProductProvider.php b/Util/ProductProvider.php index 0732bc2b..a0485500 100644 --- a/Util/ProductProvider.php +++ b/Util/ProductProvider.php @@ -10,9 +10,6 @@ class ProductProvider { - private ProductRepositoryInterface $productRepository; - private SearchCriteriaBuilder $searchCriteriaBuilder; - /** * @var string[] */ @@ -23,12 +20,8 @@ class ProductProvider */ private array $loadedProducts = []; - public function __construct( - ProductRepositoryInterface $productRepository, - SearchCriteriaBuilder $searchCriteriaBuilder - ) { - $this->productRepository = $productRepository; - $this->searchCriteriaBuilder = $searchCriteriaBuilder; + public function __construct(private readonly ProductRepositoryInterface $productRepository, private readonly SearchCriteriaBuilder $searchCriteriaBuilder) + { } /** diff --git a/ViewModel/Commons.php b/ViewModel/Commons.php index 076059c8..f60e0535 100644 --- a/ViewModel/Commons.php +++ b/ViewModel/Commons.php @@ -21,10 +21,6 @@ */ class Commons implements ArgumentInterface { - private DataLayer $dataLayer; - private Config $config; - private SerializerInterface $serializer; - /** * Commons constructor. * @@ -32,14 +28,8 @@ class Commons implements ArgumentInterface * @param Config $config * @param SerializerInterface $serializer */ - public function __construct( - DataLayer $dataLayer, - Config $config, - SerializerInterface $serializer - ) { - $this->dataLayer = $dataLayer; - $this->config = $config; - $this->serializer = $serializer; + public function __construct(private readonly DataLayer $dataLayer, private readonly Config $config, private readonly SerializerInterface $serializer) + { } /** diff --git a/ViewModel/DataLayer.php b/ViewModel/DataLayer.php index fc8f5d0e..f9f72381 100644 --- a/ViewModel/DataLayer.php +++ b/ViewModel/DataLayer.php @@ -13,16 +13,6 @@ class DataLayer implements ArgumentInterface { - private TagParser $variableParser; - private LayoutInterface $layout; - private SerializerInterface $serializer; - - /** - * @var ProcessorInterface[] - */ - protected array $processors; - private XmlConfig $xmlConfig; - /** * @param TagParser $variableParser * @param LayoutInterface $layout @@ -30,18 +20,8 @@ class DataLayer implements ArgumentInterface * @param XmlConfig $xmlConfig * @param array $processors */ - public function __construct( - TagParser $variableParser, - LayoutInterface $layout, - SerializerInterface $serializer, - XmlConfig $xmlConfig, - array $processors = [] - ) { - $this->variableParser = $variableParser; - $this->layout = $layout; - $this->serializer = $serializer; - $this->processors = $processors; - $this->xmlConfig = $xmlConfig; + public function __construct(private readonly TagParser $variableParser, private readonly LayoutInterface $layout, private readonly SerializerInterface $serializer, private readonly XmlConfig $xmlConfig, protected array $processors = []) + { } /** @@ -51,7 +31,7 @@ public function getDataLayer(): array { try { $block = $this->getDataLayerBlock(); - } catch(BlockNotFound $blockNotFound) { + } catch(BlockNotFound) { return []; } @@ -75,7 +55,7 @@ public function getDataLayerEvents(): array { try { $block = $this->getDataLayerBlock(); - } catch(BlockNotFound $blockNotFound) { + } catch(BlockNotFound) { return []; } @@ -119,7 +99,7 @@ private function getProcessors(): array { try { $block = $this->getDataLayerBlock(); - } catch(BlockNotFound $blockNotFound) { + } catch(BlockNotFound) { return []; } diff --git a/composer.json b/composer.json index fa57c5cf..c5b0c3b5 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "magento/module-sales": "^100.0 || ^101.0 || ^102.0 || ^103.0", "magento/module-store": "^100.0 || ^101.0", "psr/log": "^1 || ^2 || ^3", - "php": "^7.4|^8.1", + "php": "^8.4", "ext-json": "*", "ext-dom": "*", "ext-pcre": "*"