You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- No attributes in DTO to let them simple
- Explicit target/source in tests
- All properties with same name for simple tests
- Lot less DTOs needed
- Bad enum mapping now throws MappingTransformException
if ($targetTypeinstanceof \ReflectionNamedType && \in_array($targetType->getName(), ['string', 'int'], true)) {
404
+
thrownewMappingTransformException(\sprintf('Cannot map pure enum "%s" to scalar type "%s" on property "%s". Only BackedEnum can be converted to scalar values.', $value::class, $targetType->getName(), $propertyName));
thrownewMappingTransformException(\sprintf('Cannot map "%s" to "%s" on property "%s". Pure enums cannot be mapped from scalar values.', get_debug_type($sourceValue), $targetEnumTypeName, $targetProperty->getName()));
thrownewMappingException(\sprintf('Cannot convert value of type "%s" to "%s"-backed enum "%s".', $actualType, $expectedType, $enumClass));
477
+
thrownewMappingTransformException(\sprintf('Cannot convert value of type "%s" to "%s"-backed enum "%s".', $actualType, $expectedType, $targetEnumClass));
470
478
}
471
479
472
480
try {
473
-
return$enumClass::from($value);
481
+
return$targetEnumClass::from($value);
474
482
} catch (\ValueError$e) {
475
-
thrownewMappingException(\sprintf('Invalid value "%s" for enum "%s": "%s"', $value, $enumClass, $e->getMessage()), 0, $e);
483
+
thrownewMappingTransformException(\sprintf('Invalid value "%s" for enum "%s": "%s"', $value, $targetEnumClass, $e->getMessage()), 0, $e);
if (!$backingTypeinstanceof \ReflectionNamedType) {
485
-
thrownewMappingException(\sprintf('Cannot determine backing type for enum "%s".', $enum::class));
486
-
}
487
-
488
-
$backingTypeName = $backingType->getName();
492
+
$backingType = get_debug_type($enum->value);
489
493
490
-
if ($backingTypeName !== $targetType) {
491
-
thrownewMappingException(\sprintf('Cannot convert enum "%s" with backing type "%s" to incompatible type "%s".', $enum::class, $backingTypeName, $targetType));
0 commit comments