Skip to content

Commit 9b623ad

Browse files
committed
Remove sprintf usage in phrase calls
1 parent 536edc2 commit 9b623ad

File tree

10 files changed

+53
-69
lines changed

10 files changed

+53
-69
lines changed

app/code/Magento/Catalog/Model/FrontendStorageConfigurationPool.php

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright 2017 Adobe
44
* All Rights Reserved.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Catalog\Model;
89

@@ -17,19 +18,11 @@
1718
*/
1819
class FrontendStorageConfigurationPool
1920
{
20-
/**
21-
* @var array
22-
*/
23-
private $storageConfigurations;
24-
2521
/**
2622
* StorageConfigurationPool constructor.
2723
* @param array $storageConfigurations
2824
*/
29-
public function __construct(array $storageConfigurations = [])
30-
{
31-
$this->storageConfigurations = $storageConfigurations;
32-
}
25+
public function __construct(private array $storageConfigurations = []) {}
3326

3427
/**
3528
* Retrieve storage collector (which hold dynamic configurations) by its namespace
@@ -40,16 +33,16 @@ public function __construct(array $storageConfigurations = [])
4033
*/
4134
public function get($namespace)
4235
{
43-
if (isset($this->storageConfigurations[$namespace])) {
44-
if (!$this->storageConfigurations[$namespace] instanceof FrontendStorageConfigurationInterface) {
45-
throw new LocalizedException(
46-
__(sprintf("Invalid pool type with namespace: %s", $namespace))
47-
);
48-
}
49-
} else {
36+
$storageConfiguration = $this->storageConfigurations[$namespace] ?? null;
37+
if ($storageConfiguration === null) {
5038
return false;
5139
}
40+
if (!$storageConfiguration instanceof FrontendStorageConfigurationInterface) {
41+
throw new LocalizedException(
42+
__("Invalid pool type with namespace: %1", $namespace)
43+
);
44+
}
5245

53-
return $this->storageConfigurations[$namespace];
46+
return $storageConfiguration;
5447
}
5548
}

app/code/Magento/CatalogInventory/Model/StockStateProvider.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright 2014 Adobe
44
* All Rights Reserved.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\CatalogInventory\Model;
89

@@ -169,13 +170,13 @@ public function checkQuoteItemQty(StockItemInterface $stockItem, $qty, $summaryQ
169170
if (!$this->checkQty($stockItem, $summaryQty) || !$this->checkQty($stockItem, $qty)) {
170171
$message = __('The requested qty. is not available');
171172
if ((int) $this->scopeConfig->getValue('cataloginventory/options/not_available_message') === 1) {
172-
$itemMessage = (__(sprintf(
173-
'Only %s of %s available',
173+
$itemMessage = __(
174+
'Only %1 of %2 available',
174175
$stockItem->getQty() - $stockItem->getMinQty(),
175176
$this->localeFormat->getNumber($qty)
176-
)));
177+
);
177178
} else {
178-
$itemMessage = (__('Not enough items for sale'));
179+
$itemMessage = __('Not enough items for sale');
179180
}
180181
$result->setHasError(true)
181182
->setErrorCode('qty_available')

app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2011 Adobe
4+
* All Rights Reserved.
55
*/
6+
declare(strict_types=1);
67

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

@@ -59,7 +60,7 @@ class Configurable extends \Magento\CatalogImportExport\Model\Import\Product\Typ
5960
self::ERROR_INVALID_OPTION_VALUE => 'Column configurable_variations: Invalid option value for attribute "%s"',
6061
self::ERROR_INVALID_WEBSITE => 'Invalid website code for super attribute',
6162
self::ERROR_DUPLICATED_VARIATIONS => 'SKU %s contains duplicated variations',
62-
self::ERROR_UNIDENTIFIABLE_VARIATION => 'Configurable variation "%s" is unidentifiable',
63+
self::ERROR_UNIDENTIFIABLE_VARIATION => 'Configurable variation "%1" is unidentifiable',
6364
];
6465

6566
/**
@@ -580,10 +581,8 @@ protected function _parseVariations($rowData)
580581
if (empty($fieldAndValuePairs['sku'])) {
581582
throw new LocalizedException(
582583
__(
583-
sprintf(
584-
$this->_messageTemplates[self::ERROR_UNIDENTIFIABLE_VARIATION],
585-
$variation
586-
)
584+
$this->_messageTemplates[self::ERROR_UNIDENTIFIABLE_VARIATION],
585+
$variation
587586
)
588587
);
589588
}

app/code/Magento/EavGraphQl/Model/GetAttributeSelectedOptionComposite.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2023 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -39,9 +39,7 @@ public function __construct(array $providers = [])
3939
public function execute(string $entityType, array $customAttribute): ?array
4040
{
4141
if (!isset($this->providers[$entityType])) {
42-
throw new RuntimeException(
43-
__(sprintf('"%s" entity type not set in providers', $entityType))
44-
);
42+
throw new RuntimeException(__('"%1" entity type not set in providers', $entityType));
4543
}
4644
if (!$this->providers[$entityType] instanceof GetAttributeSelectedOptionInterface) {
4745
throw new RuntimeException(

app/code/Magento/EavGraphQl/Model/GetAttributeValueComposite.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2023 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -39,9 +39,7 @@ public function __construct(array $providers = [])
3939
public function execute(string $entityType, array $customAttribute): ?array
4040
{
4141
if (!isset($this->providers[$entityType])) {
42-
throw new RuntimeException(
43-
__(sprintf('"%s" entity type not set in providers', $entityType))
44-
);
42+
throw new RuntimeException(__('"%1" entity type not set in providers', $entityType));
4543
}
4644
if (!$this->providers[$entityType] instanceof GetAttributeValueInterface) {
4745
throw new RuntimeException(

app/code/Magento/SalesRule/Model/Coupon/Usage/Processor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ private function lockLoadedCoupon(Coupon $coupon, UpdateInfo $updateInfo, array
127127
if (!empty($incrementedCouponIds)) {
128128
$this->revertCouponTimesUsed($incrementedCouponIds);
129129
}
130-
throw new CouldNotSaveException(__(sprintf('%s %s', $coupon->getCode(), self::ERROR_MESSAGE)));
130+
throw new CouldNotSaveException(__('%1 %2', $coupon->getCode(), self::ERROR_MESSAGE));
131131
}
132132

133133
if ($updateInfo->isIncrement() || $coupon->getTimesUsed() > 0) {

app/code/Magento/Store/Model/WebsiteRepository.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2015 Adobe
4+
* All Rights Reserved.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Store\Model;
89

@@ -79,12 +80,7 @@ public function get($code)
7980

8081
if ($website->getId() === null) {
8182
throw new NoSuchEntityException(
82-
__(
83-
sprintf(
84-
"The website with code %s that was requested wasn't found. Verify the website and try again.",
85-
$code
86-
)
87-
)
83+
__("The website with code %s that was requested wasn't found. Verify the website and try again.", $code)
8884
);
8985
}
9086
$this->entities[$code] = $website;
@@ -108,12 +104,7 @@ public function getById($id)
108104

109105
if ($website->getId() === null) {
110106
throw new NoSuchEntityException(
111-
__(
112-
sprintf(
113-
"The website with id %s that was requested wasn't found. Verify the website and try again.",
114-
$id
115-
)
116-
)
107+
__("The website with id %s that was requested wasn't found. Verify the website and try again.", $id)
117108
);
118109
}
119110
$this->entities[$website->getCode()] = $website;

dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Category/DeleteTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2019 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -28,7 +28,7 @@ public function testDeleteMissingCategory(): void
2828
$this->getRequest()->setPostValue(['id' => $incorrectId]);
2929
$this->dispatch('backend/catalog/category/delete');
3030
$this->assertSessionMessages(
31-
$this->equalTo([(string)__(sprintf('No such entity with id = %s', $incorrectId))]),
31+
$this->equalTo([(string)__('No such entity with id = %1', $incorrectId)]),
3232
MessageInterface::TYPE_ERROR
3333
);
3434
}

dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Attribute/Save/AbstractAttributeTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2019 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -65,9 +65,9 @@ public function testSaveAttribute(string $productSku): void
6565
public function testRequiredAttribute(string $productSku): void
6666
{
6767
$this->expectException(Exception::class);
68-
$messageFormat = 'The "%s" attribute value is empty. Set the attribute and try again.';
68+
$messageFormat = 'The "%1" attribute value is empty. Set the attribute and try again.';
6969
$this->expectExceptionMessage(
70-
(string)__(sprintf($messageFormat, $this->getAttribute()->getDefaultFrontendLabel()))
70+
(string)__($messageFormat, $this->getAttribute()->getDefaultFrontendLabel())
7171
);
7272
$this->prepareAttribute(['is_required' => true]);
7373
$this->unsetAttributeValueAndValidate($productSku);
@@ -95,9 +95,9 @@ public function testDefaultValue(string $productSku): void
9595
public function testUniqueAttribute(string $firstSku, string $secondSku): void
9696
{
9797
$this->expectException(Exception::class);
98-
$messageFormat = 'The value of the "%s" attribute isn\'t unique. Set a unique value and try again.';
98+
$messageFormat = 'The value of the "%1" attribute isn\'t unique. Set a unique value and try again.';
9999
$this->expectExceptionMessage(
100-
(string)__(sprintf($messageFormat, $this->getAttribute()->getDefaultFrontendLabel()))
100+
(string)__($messageFormat, $this->getAttribute()->getDefaultFrontendLabel())
101101
);
102102
$this->prepareAttribute(['is_unique' => 1]);
103103
$product = $this->setAttributeValueAndValidate($firstSku, $this->getDefaultAttributeValue());

dev/tests/integration/testsuite/Magento/UrlRewrite/Controller/Adminhtml/SaveRewriteTest.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2021 Adobe
4+
* All Rights Reserved.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\UrlRewrite\Controller\Adminhtml;
79

810
use Magento\Framework\App\Request\Http as HttpRequest;
11+
use Magento\Framework\Message\MessageInterface;
12+
use Magento\TestFramework\TestCase\AbstractBackendController;
913

1014
/**
1115
* @magentoAppArea adminhtml
1216
*/
13-
class SaveRewriteTest extends \Magento\TestFramework\TestCase\AbstractBackendController
17+
class SaveRewriteTest extends AbstractBackendController
1418
{
1519
/**
1620
* Test create url rewrite with invalid target path
@@ -34,12 +38,12 @@ public function testSaveRewriteWithInvalidRequestPath() : void
3438
$this->dispatch('backend/admin/url_rewrite/save');
3539

3640
$this->assertSessionMessages(
37-
$this->containsEqual(__(sprintf(
38-
'URL key "%s" matches a reserved endpoint name (%s). Use another URL key.',
41+
$this->containsEqual(__(
42+
'URL key "%1" matches a reserved endpoint name (%2). Use another URL key.',
3943
$requestPath,
4044
$reservedWords
41-
))),
42-
\Magento\Framework\Message\MessageInterface::TYPE_ERROR
45+
)),
46+
MessageInterface::TYPE_ERROR
4347
);
4448
}
4549
}

0 commit comments

Comments
 (0)