diff --git a/app/code/Magento/Catalog/Model/FrontendStorageConfigurationPool.php b/app/code/Magento/Catalog/Model/FrontendStorageConfigurationPool.php index 7e8b249466b14..ec4b0d7fc5421 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,18 +18,12 @@ */ class FrontendStorageConfigurationPool { - /** - * @var array - */ - private $storageConfigurations; - /** * StorageConfigurationPool constructor. * @param array $storageConfigurations */ - public function __construct(array $storageConfigurations = []) + public function __construct(private array $storageConfigurations = []) { - $this->storageConfigurations = $storageConfigurations; } /** @@ -40,16 +35,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..f18720db3a661 100644 --- a/app/code/Magento/Store/Model/WebsiteRepository.php +++ b/app/code/Magento/Store/Model/WebsiteRepository.php @@ -1,8 +1,9 @@ factory = $factory; $this->websiteCollectionFactory = $websiteCollectionFactory; + $this->appConfig = $appConfig ?? ObjectManager::getInstance()->get(Config::class); } /** @@ -72,19 +76,14 @@ public function get($code) return $this->entities[$code]; } - $websiteData = $this->getAppConfig()->get('scopes', "websites/$code", []); + $websiteData = $this->appConfig->get('scopes', "websites/$code", []); $website = $this->factory->create([ 'data' => $websiteData ]); if ($website->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; @@ -101,19 +100,14 @@ public function getById($id) return $this->entitiesById[$id]; } - $websiteData = $this->getAppConfig()->get('scopes', "websites/$id", []); + $websiteData = $this->appConfig->get('scopes', "websites/$id", []); $website = $this->factory->create([ 'data' => $websiteData ]); 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; @@ -127,7 +121,7 @@ public function getById($id) public function getList() { if (!$this->allLoaded) { - $websites = $this->getAppConfig()->get('scopes', 'websites', []); + $websites = $this->appConfig->get('scopes', 'websites', []); foreach ($websites as $data) { $website = $this->factory->create([ 'data' => $data @@ -156,7 +150,7 @@ public function getDefault() $this->initDefaultWebsite(); } if (!$this->default) { - throw new \DomainException(__("The default website isn't defined. Set the website and try again.")); + throw new \DomainException("The default website isn't defined. Set the website and try again."); } } @@ -174,20 +168,6 @@ public function clean() $this->allLoaded = false; } - /** - * Retrieve application config. - * - * @deprecated 100.1.3 - * @return Config - */ - private function getAppConfig() - { - if (!$this->appConfig) { - $this->appConfig = ObjectManager::getInstance()->get(Config::class); - } - return $this->appConfig; - } - /** * Initialize default website. * @@ -195,15 +175,12 @@ private function getAppConfig() */ private function initDefaultWebsite() { - $websites = (array) $this->getAppConfig()->get('scopes', 'websites', []); + $websites = (array)$this->appConfig->get('scopes', 'websites', []); foreach ($websites as $data) { if (isset($data['is_default']) && $data['is_default'] == 1) { if ($this->default) { throw new \DomainException( - __( - 'The default website is invalid. ' - . 'Make sure no more than one default is defined and try again.' - ) + 'The default website is invalid. Make sure no more than one default is defined and try again.' ); } $website = $this->factory->create([ 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 ); } }