Skip to content

Commit

Permalink
method name issue fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehmet Korkmaz committed May 5, 2017
1 parent 9df9817 commit 3d0f10c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/SDK/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,9 @@ private function actionFactory(string $name, array $arguments, string $namespace
{
$actionClass = $namespace . '\\'. convertSnakeCase($name);
$actionName = $arguments[0];
$actionMethod = convertSnakeCase($actionName, 'f');
$actionObject = new $actionClass($this->environment->getMerchantData());
if (!method_exists($actionObject, $actionName)) {
if (!method_exists($actionObject, $actionMethod)) {
$message = sprintf(
'%s/%s is not valid MerchantSafeUnipay API action.',
ucfirst($name),
Expand All @@ -188,7 +189,7 @@ private function actionFactory(string $name, array $arguments, string $namespace
throw new BadMethodCallException($message);
}
try {
$actionObject->$actionName($arguments[1]);
$actionObject->$actionMethod($arguments[1]);
return $actionObject;
} catch (TypeError $e) {
$message = 'This action needs arguments, no argument provided.';
Expand Down
9 changes: 6 additions & 3 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function filter(array $filterKeys, array $arrayData)
return $filteredData;
}

function convertCamelCase(string $str, string $separator = '_')
function convertCamelCase(string $str, string $separator = '_') : string
{
return trim(preg_replace_callback(
'/[A-Z]/',
Expand All @@ -25,7 +25,10 @@ function ($match) use ($separator) {
), $separator);
}

function convertSnakeCase(string $str)
function convertSnakeCase(string $str, $type = 'ucwords') :string
{
return str_replace(' ','', ucwords(str_replace('_', ' ', $str)));
if ($type === 'ucwords') {
return str_replace(' ', '', ucwords(str_replace('_', ' ', $str)));
}
return lcfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', $str))));
}

0 comments on commit 3d0f10c

Please sign in to comment.