diff --git a/app/code/Magento/Catalog/Model/FrontendStorageConfigurationPool.php b/app/code/Magento/Catalog/Model/FrontendStorageConfigurationPool.php index 7e8b249466b14..0b6d550e51d44 100644 --- a/app/code/Magento/Catalog/Model/FrontendStorageConfigurationPool.php +++ b/app/code/Magento/Catalog/Model/FrontendStorageConfigurationPool.php @@ -3,6 +3,7 @@ * Copyright 2017 Adobe * All Rights Reserved. */ +declare(strict_types=1); namespace Magento\Catalog\Model; @@ -17,19 +18,11 @@ */ class FrontendStorageConfigurationPool { - /** - * @var array - */ - private $storageConfigurations; - /** * StorageConfigurationPool constructor. * @param array $storageConfigurations */ - public function __construct(array $storageConfigurations = []) - { - $this->storageConfigurations = $storageConfigurations; - } + public function __construct(private array $storageConfigurations = []) {} /** * Retrieve storage collector (which hold dynamic configurations) by its namespace @@ -40,16 +33,16 @@ public function __construct(array $storageConfigurations = []) */ public function get($namespace) { - if (isset($this->storageConfigurations[$namespace])) { - if (!$this->storageConfigurations[$namespace] instanceof FrontendStorageConfigurationInterface) { - throw new LocalizedException( - __(sprintf("Invalid pool type with namespace: %s", $namespace)) - ); - } - } else { + $storageConfiguration = $this->storageConfigurations[$namespace] ?? null; + if ($storageConfiguration === null) { return false; } + if (!$storageConfiguration instanceof FrontendStorageConfigurationInterface) { + throw new LocalizedException( + __("Invalid pool type with namespace: %1", $namespace) + ); + } - return $this->storageConfigurations[$namespace]; + return $storageConfiguration; } } diff --git a/app/code/Magento/CatalogInventory/Model/StockStateProvider.php b/app/code/Magento/CatalogInventory/Model/StockStateProvider.php index 03cd651b1a060..0ed1a552ad08c 100644 --- a/app/code/Magento/CatalogInventory/Model/StockStateProvider.php +++ b/app/code/Magento/CatalogInventory/Model/StockStateProvider.php @@ -3,6 +3,7 @@ * Copyright 2014 Adobe * All Rights Reserved. */ +declare(strict_types=1); namespace Magento\CatalogInventory\Model; @@ -169,13 +170,13 @@ public function checkQuoteItemQty(StockItemInterface $stockItem, $qty, $summaryQ if (!$this->checkQty($stockItem, $summaryQty) || !$this->checkQty($stockItem, $qty)) { $message = __('The requested qty. is not available'); if ((int) $this->scopeConfig->getValue('cataloginventory/options/not_available_message') === 1) { - $itemMessage = (__(sprintf( - 'Only %s of %s available', + $itemMessage = __( + 'Only %1 of %2 available', $stockItem->getQty() - $stockItem->getMinQty(), $this->localeFormat->getNumber($qty) - ))); + ); } else { - $itemMessage = (__('Not enough items for sale')); + $itemMessage = __('Not enough items for sale'); } $result->setHasError(true) ->setErrorCode('qty_available') diff --git a/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php b/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php index 3d40de0f0e8e4..269f979951cbb 100644 --- a/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php +++ b/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php @@ -1,8 +1,9 @@ 'Column configurable_variations: Invalid option value for attribute "%s"', self::ERROR_INVALID_WEBSITE => 'Invalid website code for super attribute', self::ERROR_DUPLICATED_VARIATIONS => 'SKU %s contains duplicated variations', - self::ERROR_UNIDENTIFIABLE_VARIATION => 'Configurable variation "%s" is unidentifiable', + self::ERROR_UNIDENTIFIABLE_VARIATION => 'Configurable variation "%1" is unidentifiable', ]; /** @@ -580,10 +581,8 @@ protected function _parseVariations($rowData) if (empty($fieldAndValuePairs['sku'])) { throw new LocalizedException( __( - sprintf( - $this->_messageTemplates[self::ERROR_UNIDENTIFIABLE_VARIATION], - $variation - ) + $this->_messageTemplates[self::ERROR_UNIDENTIFIABLE_VARIATION], + $variation ) ); } diff --git a/app/code/Magento/EavGraphQl/Model/GetAttributeSelectedOptionComposite.php b/app/code/Magento/EavGraphQl/Model/GetAttributeSelectedOptionComposite.php index 5c918a2354800..6008981d14e15 100644 --- a/app/code/Magento/EavGraphQl/Model/GetAttributeSelectedOptionComposite.php +++ b/app/code/Magento/EavGraphQl/Model/GetAttributeSelectedOptionComposite.php @@ -1,7 +1,7 @@ providers[$entityType])) { - throw new RuntimeException( - __(sprintf('"%s" entity type not set in providers', $entityType)) - ); + throw new RuntimeException(__('"%1" entity type not set in providers', $entityType)); } if (!$this->providers[$entityType] instanceof GetAttributeSelectedOptionInterface) { throw new RuntimeException( diff --git a/app/code/Magento/EavGraphQl/Model/GetAttributeValueComposite.php b/app/code/Magento/EavGraphQl/Model/GetAttributeValueComposite.php index 288e0a5cce8eb..7f51983a2a637 100644 --- a/app/code/Magento/EavGraphQl/Model/GetAttributeValueComposite.php +++ b/app/code/Magento/EavGraphQl/Model/GetAttributeValueComposite.php @@ -1,7 +1,7 @@ providers[$entityType])) { - throw new RuntimeException( - __(sprintf('"%s" entity type not set in providers', $entityType)) - ); + throw new RuntimeException(__('"%1" entity type not set in providers', $entityType)); } if (!$this->providers[$entityType] instanceof GetAttributeValueInterface) { throw new RuntimeException( diff --git a/app/code/Magento/SalesRule/Model/Coupon/Usage/Processor.php b/app/code/Magento/SalesRule/Model/Coupon/Usage/Processor.php index 01078ed00393c..24b6cd3cc237f 100644 --- a/app/code/Magento/SalesRule/Model/Coupon/Usage/Processor.php +++ b/app/code/Magento/SalesRule/Model/Coupon/Usage/Processor.php @@ -127,7 +127,7 @@ private function lockLoadedCoupon(Coupon $coupon, UpdateInfo $updateInfo, array if (!empty($incrementedCouponIds)) { $this->revertCouponTimesUsed($incrementedCouponIds); } - throw new CouldNotSaveException(__(sprintf('%s %s', $coupon->getCode(), self::ERROR_MESSAGE))); + throw new CouldNotSaveException(__('%1 %2', $coupon->getCode(), self::ERROR_MESSAGE)); } if ($updateInfo->isIncrement() || $coupon->getTimesUsed() > 0) { diff --git a/app/code/Magento/Store/Model/WebsiteRepository.php b/app/code/Magento/Store/Model/WebsiteRepository.php index e01bc8191b355..4b7123fb00d7e 100644 --- a/app/code/Magento/Store/Model/WebsiteRepository.php +++ b/app/code/Magento/Store/Model/WebsiteRepository.php @@ -1,8 +1,9 @@ getId() === null) { throw new NoSuchEntityException( - __( - sprintf( - "The website with code %s that was requested wasn't found. Verify the website and try again.", - $code - ) - ) + __("The website with code %1 that was requested wasn't found. Verify the website and try again.", $code) ); } $this->entities[$code] = $website; @@ -108,12 +104,7 @@ public function getById($id) if ($website->getId() === null) { throw new NoSuchEntityException( - __( - sprintf( - "The website with id %s that was requested wasn't found. Verify the website and try again.", - $id - ) - ) + __("The website with id %1 that was requested wasn't found. Verify the website and try again.", $id) ); } $this->entities[$website->getCode()] = $website; diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Category/DeleteTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Category/DeleteTest.php index 8db16fa2c4546..75355374a11c9 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Category/DeleteTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Category/DeleteTest.php @@ -1,7 +1,7 @@ getRequest()->setPostValue(['id' => $incorrectId]); $this->dispatch('backend/catalog/category/delete'); $this->assertSessionMessages( - $this->equalTo([(string)__(sprintf('No such entity with id = %s', $incorrectId))]), + $this->equalTo([(string)__('No such entity with id = %1', $incorrectId)]), MessageInterface::TYPE_ERROR ); } diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Attribute/Save/AbstractAttributeTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Attribute/Save/AbstractAttributeTest.php index d74688e4a2ab7..b19a8311b610d 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Attribute/Save/AbstractAttributeTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Attribute/Save/AbstractAttributeTest.php @@ -1,7 +1,7 @@ expectException(Exception::class); - $messageFormat = 'The "%s" attribute value is empty. Set the attribute and try again.'; + $messageFormat = 'The "%1" attribute value is empty. Set the attribute and try again.'; $this->expectExceptionMessage( - (string)__(sprintf($messageFormat, $this->getAttribute()->getDefaultFrontendLabel())) + (string)__($messageFormat, $this->getAttribute()->getDefaultFrontendLabel()) ); $this->prepareAttribute(['is_required' => true]); $this->unsetAttributeValueAndValidate($productSku); @@ -95,9 +95,9 @@ public function testDefaultValue(string $productSku): void public function testUniqueAttribute(string $firstSku, string $secondSku): void { $this->expectException(Exception::class); - $messageFormat = 'The value of the "%s" attribute isn\'t unique. Set a unique value and try again.'; + $messageFormat = 'The value of the "%1" attribute isn\'t unique. Set a unique value and try again.'; $this->expectExceptionMessage( - (string)__(sprintf($messageFormat, $this->getAttribute()->getDefaultFrontendLabel())) + (string)__($messageFormat, $this->getAttribute()->getDefaultFrontendLabel()) ); $this->prepareAttribute(['is_unique' => 1]); $product = $this->setAttributeValueAndValidate($firstSku, $this->getDefaultAttributeValue()); diff --git a/dev/tests/integration/testsuite/Magento/UrlRewrite/Controller/Adminhtml/SaveRewriteTest.php b/dev/tests/integration/testsuite/Magento/UrlRewrite/Controller/Adminhtml/SaveRewriteTest.php index e483058e2771c..d02a068b1def0 100644 --- a/dev/tests/integration/testsuite/Magento/UrlRewrite/Controller/Adminhtml/SaveRewriteTest.php +++ b/dev/tests/integration/testsuite/Magento/UrlRewrite/Controller/Adminhtml/SaveRewriteTest.php @@ -1,16 +1,20 @@ dispatch('backend/admin/url_rewrite/save'); $this->assertSessionMessages( - $this->containsEqual(__(sprintf( - 'URL key "%s" matches a reserved endpoint name (%s). Use another URL key.', + $this->containsEqual(__( + 'URL key "%1" matches a reserved endpoint name (%2). Use another URL key.', $requestPath, $reservedWords - ))), - \Magento\Framework\Message\MessageInterface::TYPE_ERROR + )), + MessageInterface::TYPE_ERROR ); } }