Skip to content

Commit

Permalink
Only filter properties when predicate is set
Browse files Browse the repository at this point in the history
  • Loading branch information
veewee committed Jun 14, 2024
1 parent 627d428 commit 16f0fb0
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Reflect/properties_set.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ function properties_set(object $object, array $values, Closure|null $predicate =
{
$class = ReflectedClass::fromObject($object);

$allProperties = $class->properties();
$filteredProperties = $predicate ? filter($allProperties, $predicate) : $allProperties;
$newValues = $class->isDynamic() ? diff_by_key($values, $allProperties) : [];
if ($predicate) {
$allProperties = $class->properties();
$filteredProperties = filter($allProperties, $predicate);
$unknownValues = $class->isDynamic() ? diff_by_key($values, $allProperties) : [];

$values = merge($unknownValues, intersect_by_key($values, $filteredProperties));
}

return reduce_with_keys(
merge($newValues, intersect_by_key($values, $filteredProperties)),
$values,
/**
* @param T $object
* @return T
Expand Down

0 comments on commit 16f0fb0

Please sign in to comment.