Skip to content

Commit

Permalink
Fixed hasClassIdentifierKey method
Browse files Browse the repository at this point in the history
  • Loading branch information
nilportugues committed Jun 28, 2016
1 parent 64e1a41 commit 58bad68
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/Helpers/DataAttributesHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public static function setResponseDataAttributes(array &$mappings, array &$array
}

if (\is_array($value) && !array_key_exists(Serializer::CLASS_IDENTIFIER_KEY, $value)) {
if (self::notContainsClassIdentifierKey($value)) {
if (false === self::hasClassIdentifierKey($value)) {
$attributes[$keyName] = $value;
}
}
Expand Down Expand Up @@ -158,25 +158,27 @@ protected static function isScalarValue($value)

/**
* @param array $input
* @param bool $foundIdentifierKey
*
* @return bool
*/
protected static function notContainsClassIdentifierKey(array $input, $foundIdentifierKey = false)
protected static function hasClassIdentifierKey(array $input)
{
if (!empty($input[Serializer::SCALAR_VALUE])) {
$input = $input[Serializer::SCALAR_VALUE];
if (!empty($input[Serializer::CLASS_IDENTIFIER_KEY])) {
return true;
}

$foundIdentifierKey = false;
if (!empty($input[Serializer::SCALAR_VALUE]) && !empty($input[Serializer::MAP_TYPE])) {
$input = $input[Serializer::SCALAR_VALUE];
if (\is_array($input)) {
foreach ($input as $value) {
if (\is_array($value)) {
$foundIdentifierKey = $foundIdentifierKey
|| self::notContainsClassIdentifierKey($value, $foundIdentifierKey);
$foundIdentifierKey = $foundIdentifierKey || self::hasClassIdentifierKey($value);
}
}
}
}

return false === $foundIdentifierKey;
return $foundIdentifierKey;
}
}

0 comments on commit 58bad68

Please sign in to comment.