Skip to content

Commit d9208cf

Browse files
author
Stanislav Idolov
authored
ENGCOM-2982: Fixing Snake Case To Camel Case #18064
2 parents 232e655 + 9f0374d commit d9208cf

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

app/code/Magento/Signifyd/Model/CaseServices/UpdatingService.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
*/
66
namespace Magento\Signifyd\Model\CaseServices;
77

8+
use Magento\Framework\Api\SimpleDataObjectConverter;
89
use Magento\Framework\Exception\LocalizedException;
9-
use Magento\Framework\Exception\NotFoundException;
1010
use Magento\Signifyd\Api\CaseRepositoryInterface;
1111
use Magento\Signifyd\Api\Data\CaseInterface;
1212
use Magento\Signifyd\Model\CommentsHistoryUpdater;
@@ -73,7 +73,6 @@ public function __construct(
7373
* @param CaseInterface $case
7474
* @param array $data
7575
* @return void
76-
* @throws NotFoundException
7776
* @throws LocalizedException
7877
*/
7978
public function update(CaseInterface $case, array $data)
@@ -111,7 +110,7 @@ private function setCaseData(CaseInterface $case, array $data)
111110
'orderId'
112111
];
113112
foreach ($data as $key => $value) {
114-
$methodName = 'set' . ucfirst($key);
113+
$methodName = 'set' . SimpleDataObjectConverter::snakeCaseToUpperCamelCase($key);
115114
if (!in_array($key, $notResolvedKeys) && method_exists($case, $methodName)) {
116115
call_user_func([$case, $methodName], $value);
117116
}

app/code/Magento/Webapi/Controller/Rest/ParamsOverrider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ private function isPropertyDeclaredInDataObject(
197197
$index = array_search($serviceMethodParamName, array_column($methodParams, 'name'));
198198
if ($index !== false) {
199199
$paramObjectType = $methodParams[$index][MethodsMap::METHOD_META_TYPE];
200-
$setter = 'set' . ucfirst(SimpleDataObjectConverter::snakeCaseToCamelCase($objectProperty));
200+
$setter = 'set' . SimpleDataObjectConverter::snakeCaseToUpperCamelCase($objectProperty);
201201
if (array_key_exists(
202202
$setter,
203203
$this->getMethodsMap()->getMethodsMap($paramObjectType)

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
use Magento\Framework\Convert\ConvertArray;
99
use Magento\Framework\Reflection\DataObjectProcessor;
1010

11+
/**
12+
* Data object converter.
13+
*/
1114
class SimpleDataObjectConverter
1215
{
1316
/**
@@ -156,14 +159,13 @@ public static function snakeCaseToUpperCamelCase($input)
156159
*/
157160
public static function snakeCaseToCamelCase($input)
158161
{
159-
return lcfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', $input))));
162+
return lcfirst(self::snakeCaseToUpperCamelCase($input));
160163
}
161164

162165
/**
163166
* Convert a CamelCase string read from method into field key in snake_case
164167
*
165-
* e.g. DefaultShipping => default_shipping
166-
* Postcode => postcode
168+
* For example [DefaultShipping => default_shipping, Postcode => postcode]
167169
*
168170
* @param string $name
169171
* @return string

lib/internal/Magento/Framework/App/Request/DataPersistor.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
*/
66
namespace Magento\Framework\App\Request;
77

8+
use Magento\Framework\Api\SimpleDataObjectConverter;
89
use Magento\Framework\Session\SessionManagerInterface;
910

11+
/**
12+
* Persist data to session.
13+
*/
1014
class DataPersistor implements DataPersistorInterface
1115
{
1216
/**
@@ -32,7 +36,7 @@ public function __construct(
3236
*/
3337
public function set($key, $data)
3438
{
35-
$method = 'set' . ucfirst($key) . 'Data';
39+
$method = 'set' . SimpleDataObjectConverter::snakeCaseToUpperCamelCase($key) . 'Data';
3640
call_user_func_array([$this->session, $method], [$data]);
3741
}
3842

@@ -44,7 +48,7 @@ public function set($key, $data)
4448
*/
4549
public function get($key)
4650
{
47-
$method = 'get' . ucfirst($key) . 'Data';
51+
$method = 'get' . SimpleDataObjectConverter::snakeCaseToUpperCamelCase($key) . 'Data';
4852
return call_user_func_array([$this->session, $method], []);
4953
}
5054

@@ -56,7 +60,7 @@ public function get($key)
5660
*/
5761
public function clear($key)
5862
{
59-
$method = 'uns' . ucfirst($key) . 'Data';
63+
$method = 'uns' . SimpleDataObjectConverter::snakeCaseToUpperCamelCase($key) . 'Data';
6064
call_user_func_array([$this->session, $method], []);
6165
}
6266
}

0 commit comments

Comments
 (0)