Skip to content

Commit 45bcbb8

Browse files
Merge remote-tracking branch '38554/patch-phrase-remove-sprintf' into comprs_jul4
2 parents 3fbce83 + 4ba5491 commit 45bcbb8

File tree

10 files changed

+64
-92
lines changed

10 files changed

+64
-92
lines changed

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

Lines changed: 10 additions & 15 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,18 +18,12 @@
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 = [])
25+
public function __construct(private array $storageConfigurations = [])
3026
{
31-
$this->storageConfigurations = $storageConfigurations;
3227
}
3328

3429
/**
@@ -40,16 +35,16 @@ public function __construct(array $storageConfigurations = [])
4035
*/
4136
public function get($namespace)
4237
{
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 {
38+
$storageConfiguration = $this->storageConfigurations[$namespace] ?? null;
39+
if ($storageConfiguration === null) {
5040
return false;
5141
}
42+
if (!$storageConfiguration instanceof FrontendStorageConfigurationInterface) {
43+
throw new LocalizedException(
44+
__("Invalid pool type with namespace: %1", $namespace)
45+
);
46+
}
5247

53-
return $this->storageConfigurations[$namespace];
48+
return $storageConfiguration;
5449
}
5550
}

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: 16 additions & 39 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

@@ -49,18 +50,21 @@ class WebsiteRepository implements \Magento\Store\Api\WebsiteRepositoryInterface
4950
/**
5051
* @var Config
5152
*/
52-
private $appConfig;
53+
private Config $appConfig;
5354

5455
/**
5556
* @param WebsiteFactory $factory
5657
* @param CollectionFactory $websiteCollectionFactory
58+
* @param Config|null $appConfig
5759
*/
5860
public function __construct(
5961
WebsiteFactory $factory,
60-
CollectionFactory $websiteCollectionFactory
62+
CollectionFactory $websiteCollectionFactory,
63+
?Config $appConfig = null
6164
) {
6265
$this->factory = $factory;
6366
$this->websiteCollectionFactory = $websiteCollectionFactory;
67+
$this->appConfig = $appConfig ?? ObjectManager::getInstance()->get(Config::class);
6468
}
6569

6670
/**
@@ -72,19 +76,14 @@ public function get($code)
7276
return $this->entities[$code];
7377
}
7478

75-
$websiteData = $this->getAppConfig()->get('scopes', "websites/$code", []);
79+
$websiteData = $this->appConfig->get('scopes', "websites/$code", []);
7680
$website = $this->factory->create([
7781
'data' => $websiteData
7882
]);
7983

8084
if ($website->getId() === null) {
8185
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-
)
86+
__("The website with code %1 that was requested wasn't found. Verify the website and try again.", $code)
8887
);
8988
}
9089
$this->entities[$code] = $website;
@@ -101,19 +100,14 @@ public function getById($id)
101100
return $this->entitiesById[$id];
102101
}
103102

104-
$websiteData = $this->getAppConfig()->get('scopes', "websites/$id", []);
103+
$websiteData = $this->appConfig->get('scopes', "websites/$id", []);
105104
$website = $this->factory->create([
106105
'data' => $websiteData
107106
]);
108107

109108
if ($website->getId() === null) {
110109
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-
)
110+
__("The website with id %1 that was requested wasn't found. Verify the website and try again.", $id)
117111
);
118112
}
119113
$this->entities[$website->getCode()] = $website;
@@ -127,7 +121,7 @@ public function getById($id)
127121
public function getList()
128122
{
129123
if (!$this->allLoaded) {
130-
$websites = $this->getAppConfig()->get('scopes', 'websites', []);
124+
$websites = $this->appConfig->get('scopes', 'websites', []);
131125
foreach ($websites as $data) {
132126
$website = $this->factory->create([
133127
'data' => $data
@@ -156,7 +150,7 @@ public function getDefault()
156150
$this->initDefaultWebsite();
157151
}
158152
if (!$this->default) {
159-
throw new \DomainException(__("The default website isn't defined. Set the website and try again."));
153+
throw new \DomainException("The default website isn't defined. Set the website and try again.");
160154
}
161155
}
162156

@@ -174,36 +168,19 @@ public function clean()
174168
$this->allLoaded = false;
175169
}
176170

177-
/**
178-
* Retrieve application config.
179-
*
180-
* @deprecated 100.1.3
181-
* @return Config
182-
*/
183-
private function getAppConfig()
184-
{
185-
if (!$this->appConfig) {
186-
$this->appConfig = ObjectManager::getInstance()->get(Config::class);
187-
}
188-
return $this->appConfig;
189-
}
190-
191171
/**
192172
* Initialize default website.
193173
*
194174
* @return void
195175
*/
196176
private function initDefaultWebsite()
197177
{
198-
$websites = (array) $this->getAppConfig()->get('scopes', 'websites', []);
178+
$websites = (array)$this->appConfig->get('scopes', 'websites', []);
199179
foreach ($websites as $data) {
200180
if (isset($data['is_default']) && $data['is_default'] == 1) {
201181
if ($this->default) {
202182
throw new \DomainException(
203-
__(
204-
'The default website is invalid. '
205-
. 'Make sure no more than one default is defined and try again.'
206-
)
183+
'The default website is invalid. Make sure no more than one default is defined and try again.'
207184
);
208185
}
209186
$website = $this->factory->create([

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)