Skip to content

Commit

Permalink
Merge pull request #15 from veewee/only-filter-properties-when-predic…
Browse files Browse the repository at this point in the history
…ate-is-set

Only filter properties when predicate is set
  • Loading branch information
veewee committed Jun 14, 2024
2 parents 627d428 + 16f0fb0 commit 8b0b2f6
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 8b0b2f6

Please sign in to comment.