Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurkushman committed Mar 8, 2020
2 parents 4e5d08d + 3852356 commit f984b02
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions src/Helpers/Json.php
Expand Up @@ -201,6 +201,7 @@ private static function getSelectedData(string $json, array $data): string
*/
private static function unsetArray(array &$json, array $data): void
{
$attrsCase = ConfigHelper::getParam(ConfigInterface::ATTRIBUTES_CASE);
foreach ($json as $type => &$jsonObject) {

if ($type === ApiInterface::RAML_DATA) { // unset only data->attributes fields
Expand All @@ -211,6 +212,8 @@ private static function unsetArray(array &$json, array $data): void

if (\in_array($key, $data, true) === false) {
unset($v[JSONApiInterface::CONTENT_ATTRIBUTES][$key]);
} else if ($attrsCase !== ConfigInterface::DEFAULT_CASE) {
self::changeParamKey($json, $k, $v, $attrsCase);
}
}
}
Expand All @@ -236,22 +239,33 @@ private static function unsetObject(array &$json, array $data): void
if (\in_array($k, $data, true) === false) {
unset($json[JSONApiInterface::CONTENT_DATA][JSONApiInterface::CONTENT_ATTRIBUTES][$k]);
} else if ($attrsCase !== ConfigInterface::DEFAULT_CASE) {
$changedKey = $k;
if ($attrsCase === ConfigInterface::CAMEL_CASE) {
$changedKey = self::changeParamKeyToLowerCamelCase($k);
} else if ($attrsCase === ConfigInterface::LISP_CASE) {
$changedKey = self::changeParamKeyToLispCase($k);
}

$json[JSONApiInterface::CONTENT_DATA][JSONApiInterface::CONTENT_ATTRIBUTES][$changedKey] = $v;
if ($changedKey !== $k) {
unset($json[JSONApiInterface::CONTENT_DATA][JSONApiInterface::CONTENT_ATTRIBUTES][$k]);
}
self::changeParamKey($json, $k, $v, $attrsCase);
}
}
}
}

/**
* @param array $json
* @param string $k
* @param mixed $v
* @param string $attrsCase
*/
public static function changeParamKey(array &$json, string $k, $v, string $attrsCase): void
{
$changedKey = $k;
if ($attrsCase === ConfigInterface::CAMEL_CASE) {
$changedKey = self::changeParamKeyToLowerCamelCase($k);
} else if ($attrsCase === ConfigInterface::LISP_CASE) {
$changedKey = self::changeParamKeyToLispCase($k);
}

$json[JSONApiInterface::CONTENT_DATA][JSONApiInterface::CONTENT_ATTRIBUTES][$changedKey] = $v;
if ($changedKey !== $k) {
unset($json[JSONApiInterface::CONTENT_DATA][JSONApiInterface::CONTENT_ATTRIBUTES][$k]);
}
}

/**
* @param string $param
* @return string
Expand Down

0 comments on commit f984b02

Please sign in to comment.