Skip to content
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

Optimize snail_case replacement to PascalCase #20596

Merged
merged 2 commits into from
Feb 24, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function execute()
$this->productBuilder->build($this->getRequest());

$block = $this->getRequest()->getParam('gridOnlyBlock');
$blockClassSuffix = str_replace(' ', '_', ucwords(str_replace('_', ' ', $block)));
$blockClassSuffix = ucwords($block, '_');

/** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
$resultRaw = $this->resultRawFactory->create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ protected function getCurrentRewritesMocks($currentRewrites)
->disableOriginalConstructor()->getMock();
foreach ($urlRewrite as $key => $value) {
$url->expects($this->any())
->method('get' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key))))
->method('get' . str_replace('_', '', ucwords($key, '_')))
->will($this->returnValue($value));
}
$rewrites[] = $url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ protected function getCurrentRewritesMocks($currentRewrites)
->disableOriginalConstructor()->getMock();
foreach ($urlRewrite as $key => $value) {
$url->expects($this->any())
->method('get' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key))))
->method('get' . str_replace('_', '', ucwords($key, '_')))
->will($this->returnValue($value));
}
$rewrites[] = $url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ protected function currentUrlRewritesRegeneratorGetCurrentRewritesMocks($current
->disableOriginalConstructor()->getMock();
foreach ($urlRewrite as $key => $value) {
$url->expects($this->any())
->method('get' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key))))
->method('get' . str_replace('_', '', ucwords($key, '_')))
->will($this->returnValue($value));
}
$rewrites[] = $url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ private function getTaxRateMock(array $taxRateData)
foreach ($taxRateData as $key => $value) {
// convert key from snake case to upper case
$taxRateMock->expects($this->any())
->method('get' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key))))
->method('get' . str_replace('_', '', ucwords($key, '_')))
->will($this->returnValue($value));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private function getMockObject($className, array $objectState)
$getterValueMap = [];
$methods = ['__wakeup'];
foreach ($objectState as $key => $value) {
$getterName = 'get' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key)));
$getterName = 'get' . str_replace('_', '', ucwords($key, '_'));
$getterValueMap[$getterName] = $value;
$methods[] = $getterName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private function createProducts(FixtureFactory $fixtureFactory, $productsData)
$searchValue = isset($productData[2]) ? $productData[2] : $productData[1];
if ($this->data === null) {
if ($product->hasData($searchValue)) {
$getProperty = 'get' . str_replace(' ', '', ucwords(str_replace('_', ' ', $searchValue)));
$getProperty = 'get' . str_replace('_', '', ucwords($searchValue, '_'));
$this->data = $product->$getProperty();
} else {
$this->data = $searchValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ protected function prepareWidgetInstance(array $data)
$widgetInstances = [];
foreach ($data['widget_instance'] as $key => $widgetInstance) {
$pageGroup = $widgetInstance['page_group'];
$method = 'prepare' . str_replace(' ', '', ucwords(str_replace('_', ' ', $pageGroup))) . 'Group';
$method = 'prepare' . str_replace('_', '', ucwords($pageGroup, '_')) . 'Group';
if (!method_exists(__CLASS__, $method)) {
throw new \Exception('Method for prepare page group "' . $method . '" is not exist.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function convertKeysToCamelCase(array $dataArray)
if (is_array($fieldValue) && !$this->_isSimpleSequentialArray($fieldValue)) {
$fieldValue = $this->convertKeysToCamelCase($fieldValue);
}
$fieldName = lcfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', $fieldName))));
$fieldName = lcfirst(str_replace('_', '', ucwords($fieldName, '_')));
$response[$fieldName] = $fieldValue;
}
return $response;
Expand Down Expand Up @@ -148,7 +148,7 @@ protected function _unpackAssociativeArray($data)
*/
public static function snakeCaseToUpperCamelCase($input)
{
return str_replace(' ', '', ucwords(str_replace('_', ' ', $input)));
return str_replace('_', '', ucwords($input, '_'));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/Magento/Framework/Code/NameBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function buildClassName($parts)
$separator = '\\';
$string = join($separator, $parts);
$string = str_replace('_', $separator, $string);
$className = str_replace(' ', $separator, ucwords(str_replace($separator, ' ', $string)));
$className = ucwords($string, $separator);
return $className;
}
}
4 changes: 2 additions & 2 deletions lib/internal/Magento/Framework/DataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ protected function _getData($key)
*/
public function setDataUsingMethod($key, $args = [])
{
$method = 'set' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key)));
$method = 'set' . str_replace('_', '', ucwords($key, '_'));
$this->{$method}($args);
return $this;
}
Expand All @@ -216,7 +216,7 @@ public function setDataUsingMethod($key, $args = [])
*/
public function getDataUsingMethod($key, $args = null)
{
$method = 'get' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key)));
$method = 'get' . str_replace('_', '', ucwords($key, '_'));
return $this->{$method}($args);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/internal/Magento/Framework/DataObject/Copy.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ protected function _setFieldsetFieldValue($target, $targetCode, $value)
*/
protected function getAttributeValueFromExtensibleDataObject($source, $code)
{
$method = 'get' . str_replace(' ', '', ucwords(str_replace('_', ' ', $code)));
$method = 'get' . str_replace('_', '', ucwords($code, '_'));

$methodExists = method_exists($source, $method);
if ($methodExists == true) {
Expand Down Expand Up @@ -273,7 +273,7 @@ protected function getAttributeValueFromExtensibleDataObject($source, $code)
*/
protected function setAttributeValueFromExtensibleDataObject($target, $code, $value)
{
$method = 'set' . str_replace(' ', '', ucwords(str_replace('_', ' ', $code)));
$method = 'set' . str_replace('_', '', ucwords($code, '_'));

$methodExists = method_exists($target, $method);
if ($methodExists == true) {
Expand Down
3 changes: 1 addition & 2 deletions lib/internal/Magento/Framework/Module/PackageInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ public function getNonExistingDependencies()
protected function convertPackageNameToModuleName($packageName)
{
$moduleName = str_replace('magento/module-', '', $packageName);
$moduleName = str_replace('-', ' ', $moduleName);
$moduleName = str_replace(' ', '', ucwords($moduleName));
$moduleName = str_replace('-', '', ucwords($moduleName, '-'));

return 'Magento_' . $moduleName;
}
Expand Down