Skip to content

Commit

Permalink
Improve performance when optional peoperty exists
Browse files Browse the repository at this point in the history
  • Loading branch information
rust17 committed Dec 4, 2023
1 parent 41bba12 commit 1b34d17
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Transformers/DataTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,16 @@ protected function resolvePayload(TransformableData $data): array

$payload = [];

$objVars = get_object_vars($data);

foreach ($dataClass->properties as $property) {
if ($property->hidden) {
continue;
}

$name = $property->name;

if ($property->type->isOptional && ! array_key_exists($name, get_object_vars($data))) {
if ($property->type->isOptional && ! array_key_exists($name, $objVars)) {
continue;
}

Expand Down

0 comments on commit 1b34d17

Please sign in to comment.