Skip to content

Commit

Permalink
Remove unknown keys warning from Deserializes trait (#714)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlevers committed Jun 10, 2024
1 parent 108349c commit 64c4b84
Showing 1 changed file with 0 additions and 8 deletions.
8 changes: 0 additions & 8 deletions src/Traits/Deserializes.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public static function deserialize(mixed $data): mixed
$attributeMap = $hasAttributeMap
? array_flip($reflectionClass->getProperty('attributeMap')->getValue())
: [];
$unknownKeys = [];

foreach ($data as $rawKey => $value) {
$key = $rawKey;
Expand All @@ -53,18 +52,11 @@ public static function deserialize(mixed $data): mixed
}

if (! array_key_exists($key, $attributeTypes)) {
$unknownKeys[] = $key;

continue;
}
$deserializedParams[$key] = static::deserializeValue($value, $attributeTypes[$key]);
}

if (count($unknownKeys) > 0) {
$cls = static::class;
echo "Warning: Unknown keys when deserializing into $cls: ".implode(', ', $unknownKeys)."\n";
}

return new static(...$deserializedParams);
}

Expand Down

0 comments on commit 64c4b84

Please sign in to comment.