Skip to content

Commit 463bd96

Browse files
committed
Replaced ReflectionClass usages with procedural function calls
1 parent b8818b6 commit 463bd96

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

src/AbstractTrackingListener.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,19 @@ protected function updateField($object, $eventAdapter, $meta, $field, array $con
227227
}
228228

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

233-
if (!$reflectionClass->hasMethod($setterName)) {
234-
throw new InvalidMappingException("Setter method - [{$setterName}] does not exist in class - {$meta->getName()}");
232+
if (!method_exists($object, $setterName)) {
233+
throw new InvalidMappingException(
234+
sprintf(
235+
"Setter method [%s] does not exist in class %s",
236+
$setterName,
237+
$meta->getName(),
238+
),
239+
);
235240
}
236241

237-
$reflectionClass->getMethod($setterName)->invoke($object, $newValue);
242+
$object->{$setterName}($newValue);
238243
} else {
239244
$property->setValue($object, $newValue);
240245
}

src/SoftDeleteable/SoftDeleteableListener.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,19 @@ public function onFlush(EventArgs $args)
9898
}
9999

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

104-
if (!$reflectionClass->hasMethod($setterName)) {
105-
throw new InvalidMappingException("Setter method - [{$setterName}] does not exist in class - {$meta->getName()}");
103+
if (!method_exists($object, $setterName)) {
104+
throw new InvalidMappingException(
105+
sprintf(
106+
"Setter method [%s] does not exist in class %s",
107+
$setterName,
108+
$meta->getName(),
109+
),
110+
);
106111
}
107112

108-
$reflectionClass->getMethod($setterName)->invoke($object, $date);
113+
$object->{$setterName}($date);
109114
} else {
110115
$reflProp->setValue($object, $date);
111116
}

0 commit comments

Comments
 (0)