From 4f2c498ebfe84d3a477d612c8e076e36f82d8147 Mon Sep 17 00:00:00 2001 From: Florian Wolfsjaeger Date: Fri, 1 Mar 2024 16:26:46 +0100 Subject: [PATCH] Replaced ReflectionClass usages with procedural function calls --- src/AbstractTrackingListener.php | 13 +++++++++---- src/SoftDeleteable/SoftDeleteableListener.php | 13 +++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/AbstractTrackingListener.php b/src/AbstractTrackingListener.php index 131ee0229..cc402d0ac 100644 --- a/src/AbstractTrackingListener.php +++ b/src/AbstractTrackingListener.php @@ -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); } diff --git a/src/SoftDeleteable/SoftDeleteableListener.php b/src/SoftDeleteable/SoftDeleteableListener.php index 40d260288..6cf1fafa5 100644 --- a/src/SoftDeleteable/SoftDeleteableListener.php +++ b/src/SoftDeleteable/SoftDeleteableListener.php @@ -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); }