Skip to content

Commit 371d67b

Browse files
authored
ENGCOM-4086: Optimize snail_case replacement to PascalCase #20596
2 parents b15af15 + d5dca69 commit 371d67b

File tree

13 files changed

+32
-27
lines changed

13 files changed

+32
-27
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/GridOnly.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
<?php
22
/**
3-
*
43
* Copyright © Magento, Inc. All rights reserved.
54
* See COPYING.txt for license details.
65
*/
76
namespace Magento\Catalog\Controller\Adminhtml\Product;
87

9-
class GridOnly extends \Magento\Catalog\Controller\Adminhtml\Product
8+
use Magento\Framework\App\Action\HttpGetActionInterface;
9+
10+
/**
11+
* Get specified tab grid controller.
12+
*/
13+
class GridOnly extends \Magento\Catalog\Controller\Adminhtml\Product implements HttpGetActionInterface
1014
{
1115
/**
1216
* @var \Magento\Framework\Controller\Result\RawFactory
@@ -47,7 +51,7 @@ public function execute()
4751
$this->productBuilder->build($this->getRequest());
4852

4953
$block = $this->getRequest()->getParam('gridOnlyBlock');
50-
$blockClassSuffix = str_replace(' ', '_', ucwords(str_replace('_', ' ', $block)));
54+
$blockClassSuffix = ucwords($block, '_');
5155

5256
/** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
5357
$resultRaw = $this->resultRawFactory->create();

app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Category/CurrentUrlRewritesRegeneratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ protected function getCurrentRewritesMocks($currentRewrites)
252252
->disableOriginalConstructor()->getMock();
253253
foreach ($urlRewrite as $key => $value) {
254254
$url->expects($this->any())
255-
->method('get' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key))))
255+
->method('get' . str_replace('_', '', ucwords($key, '_')))
256256
->will($this->returnValue($value));
257257
}
258258
$rewrites[] = $url;

app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Product/CurrentUrlRewritesRegeneratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ protected function getCurrentRewritesMocks($currentRewrites)
294294
->disableOriginalConstructor()->getMock();
295295
foreach ($urlRewrite as $key => $value) {
296296
$url->expects($this->any())
297-
->method('get' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key))))
297+
->method('get' . str_replace('_', '', ucwords($key, '_')))
298298
->will($this->returnValue($value));
299299
}
300300
$rewrites[] = $url;

app/code/Magento/CatalogUrlRewrite/Test/Unit/Observer/AfterImportDataObserverTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ protected function currentUrlRewritesRegeneratorGetCurrentRewritesMocks($current
694694
->disableOriginalConstructor()->getMock();
695695
foreach ($urlRewrite as $key => $value) {
696696
$url->expects($this->any())
697-
->method('get' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key))))
697+
->method('get' . str_replace('_', '', ucwords($key, '_')))
698698
->will($this->returnValue($value));
699699
}
700700
$rewrites[] = $url;

app/code/Magento/Tax/Test/Unit/Model/Calculation/RateRepositoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ private function getTaxRateMock(array $taxRateData)
252252
foreach ($taxRateData as $key => $value) {
253253
// convert key from snake case to upper case
254254
$taxRateMock->expects($this->any())
255-
->method('get' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key))))
255+
->method('get' . str_replace('_', '', ucwords($key, '_')))
256256
->will($this->returnValue($value));
257257
}
258258

app/code/Magento/Tax/Test/Unit/Model/Sales/Total/Quote/ShippingTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private function getMockObject($className, array $objectState)
133133
$getterValueMap = [];
134134
$methods = ['__wakeup'];
135135
foreach ($objectState as $key => $value) {
136-
$getterName = 'get' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key)));
136+
$getterName = 'get' . str_replace('_', '', ucwords($key, '_'));
137137
$getterValueMap[$getterName] = $value;
138138
$methods[] = $getterName;
139139
}

dev/tests/functional/tests/app/Magento/CatalogSearch/Test/Fixture/CatalogSearchQuery/QueryText.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private function createProducts(FixtureFactory $fixtureFactory, $productsData)
6161
$searchValue = isset($productData[2]) ? $productData[2] : $productData[1];
6262
if ($this->data === null) {
6363
if ($product->hasData($searchValue)) {
64-
$getProperty = 'get' . str_replace(' ', '', ucwords(str_replace('_', ' ', $searchValue)));
64+
$getProperty = 'get' . str_replace('_', '', ucwords($searchValue, '_'));
6565
$this->data = $product->$getProperty();
6666
} else {
6767
$this->data = $searchValue;

dev/tests/functional/tests/app/Magento/Widget/Test/Handler/Widget/Curl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ protected function prepareWidgetInstance(array $data)
172172
$widgetInstances = [];
173173
foreach ($data['widget_instance'] as $key => $widgetInstance) {
174174
$pageGroup = $widgetInstance['page_group'];
175-
$method = 'prepare' . str_replace(' ', '', ucwords(str_replace('_', ' ', $pageGroup))) . 'Group';
175+
$method = 'prepare' . str_replace('_', '', ucwords($pageGroup, '_')) . 'Group';
176176
if (!method_exists(__CLASS__, $method)) {
177177
throw new \Exception('Method for prepare page group "' . $method . '" is not exist.');
178178
}

lib/internal/Magento/Framework/Api/SimpleDataObjectConverter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function convertKeysToCamelCase(array $dataArray)
5858
if (is_array($fieldValue) && !$this->_isSimpleSequentialArray($fieldValue)) {
5959
$fieldValue = $this->convertKeysToCamelCase($fieldValue);
6060
}
61-
$fieldName = lcfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', $fieldName))));
61+
$fieldName = lcfirst(str_replace('_', '', ucwords($fieldName, '_')));
6262
$response[$fieldName] = $fieldValue;
6363
}
6464
return $response;
@@ -148,7 +148,7 @@ protected function _unpackAssociativeArray($data)
148148
*/
149149
public static function snakeCaseToUpperCamelCase($input)
150150
{
151-
return str_replace(' ', '', ucwords(str_replace('_', ' ', $input)));
151+
return str_replace('_', '', ucwords($input, '_'));
152152
}
153153

154154
/**

lib/internal/Magento/Framework/Code/NameBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function buildClassName($parts)
2626
$separator = '\\';
2727
$string = join($separator, $parts);
2828
$string = str_replace('_', $separator, $string);
29-
$className = str_replace(' ', $separator, ucwords(str_replace($separator, ' ', $string)));
29+
$className = ucwords($string, $separator);
3030
return $className;
3131
}
3232
}

0 commit comments

Comments
 (0)