Skip to content

Commit

Permalink
Replaced ReflectionClass usages with procedural function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
fwolfsjaeger committed Mar 1, 2024
1 parent 023911f commit bd614cc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
13 changes: 9 additions & 4 deletions src/AbstractTrackingListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,19 @@ protected function updateField($object, $eventAdapter, $meta, $field, array $con
}

if (!empty($config['setterMethod'][$field])) {
$reflectionClass = $meta->getReflectionClass();
$setterName = $config['setterMethod'][$field];

if (!$reflectionClass->hasMethod($setterName)) {
throw new InvalidMappingException("Setter method - [{$setterName}] does not exist in class - {$meta->getName()}");
if (!method_exists($object, $setterName)) {
throw new InvalidMappingException(
sprintf(
"Setter method [%s] does not exist in class %s",
$setterName,
$meta->getName(),
),
);
}

$reflectionClass->getMethod($setterName)->invoke($object, $newValue);
$object->{$setterName}($newValue);
} else {
$property->setValue($object, $newValue);
}
Expand Down
13 changes: 9 additions & 4 deletions src/SoftDeleteable/SoftDeleteableListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,19 @@ public function onFlush(EventArgs $args)
}

if (!empty($config['setterMethod'][$config['fieldName']])) {
$reflectionClass = $meta->getReflectionClass();
$setterName = $config['setterMethod'][$config['fieldName']];

if (!$reflectionClass->hasMethod($setterName)) {
throw new InvalidMappingException("Setter method - [{$setterName}] does not exist in class - {$meta->getName()}");
if (!method_exists($object, $setterName)) {
throw new InvalidMappingException(
sprintf(
"Setter method [%s] does not exist in class %s",
$setterName,
$meta->getName(),
),
);
}

$reflectionClass->getMethod($setterName)->invoke($object, $date);
$object->{$setterName}($date);
} else {
$reflProp->setValue($object, $date);
}
Expand Down

0 comments on commit bd614cc

Please sign in to comment.