Fixed exception when undo/revert to a change which contained a change to a enum property

This commit is contained in:
Jan Böhmer 2023-07-18 23:34:45 +02:00
parent 6fb1845ff7
commit 8116217019

View file

@ -244,6 +244,15 @@ class TimeTravel
$reflection = new ReflectionClass($element::class);
$property = $reflection->getProperty($field);
//Check if the property is an BackedEnum, then convert the int or float value to an enum instance
if ((is_string($new_value) || is_int($new_value))
&& $property->getType() !== null
&& is_a($property->getType()->getName(), \BackedEnum::class, true)) {
/** @phpstan-var class-string<\BackedEnum> $enum_class */
$enum_class = $property->getType()->getName();
$new_value = $enum_class::from($new_value);
}
$property->setValue($element, $new_value);
}
}