Skip to content

Remove sprintf usage in phrase calls #40033

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 2.4-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions app/code/Magento/Catalog/Model/FrontendStorageConfigurationPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright 2017 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

namespace Magento\Catalog\Model;

Expand All @@ -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
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright 2014 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

namespace Magento\CatalogInventory\Model;

Expand Down Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2011 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

namespace Magento\ConfigurableImportExport\Model\Import\Product\Type;

Expand Down Expand Up @@ -59,7 +60,7 @@ class Configurable extends \Magento\CatalogImportExport\Model\Import\Product\Typ
self::ERROR_INVALID_OPTION_VALUE => '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',
];

/**
Expand Down Expand Up @@ -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
)
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2023 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

Expand Down Expand Up @@ -39,9 +39,7 @@ public function __construct(array $providers = [])
public function execute(string $entityType, array $customAttribute): ?array
{
if (!isset($this->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(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2023 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

Expand Down Expand Up @@ -39,9 +39,7 @@ public function __construct(array $providers = [])
public function execute(string $entityType, array $customAttribute): ?array
{
if (!isset($this->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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
19 changes: 5 additions & 14 deletions app/code/Magento/Store/Model/WebsiteRepository.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2015 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

namespace Magento\Store\Model;

Expand Down Expand Up @@ -79,12 +80,7 @@ public function get($code)

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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2019 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

Expand All @@ -28,7 +28,7 @@ public function testDeleteMissingCategory(): void
$this->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
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2019 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

Expand Down Expand Up @@ -65,9 +65,9 @@ public function testSaveAttribute(string $productSku): void
public function testRequiredAttribute(string $productSku): void
{
$this->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);
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2021 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

namespace Magento\UrlRewrite\Controller\Adminhtml;

use Magento\Framework\App\Request\Http as HttpRequest;
use Magento\Framework\Message\MessageInterface;
use Magento\TestFramework\TestCase\AbstractBackendController;

/**
* @magentoAppArea adminhtml
*/
class SaveRewriteTest extends \Magento\TestFramework\TestCase\AbstractBackendController
class SaveRewriteTest extends AbstractBackendController
{
/**
* Test create url rewrite with invalid target path
Expand All @@ -34,12 +38,12 @@ public function testSaveRewriteWithInvalidRequestPath() : void
$this->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
);
}
}