14
14
use Doctrine \DBAL \Types \ConversionException ;
15
15
use Doctrine \DBAL \Types \Type ;
16
16
17
+ use function get_debug_type ;
17
18
use function is_a ;
19
+ use function sprintf ;
18
20
19
21
abstract class AbstractUsDateTimeType extends Type
20
22
{
@@ -23,7 +25,7 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform): st
23
25
return match (true ) {
24
26
$ platform instanceof AbstractMySQLPlatform => 'DATETIME(6) ' ,
25
27
$ platform instanceof PostgreSQLPlatform => 'timestamp ' ,
26
- default => throw Exception:: notSupported ( __METHOD__ ),
28
+ default => throw new Exception ( ' Platform not supported ' ),
27
29
};
28
30
}
29
31
@@ -40,15 +42,15 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform): mixe
40
42
return $ value ->format ($ this ->getFormat ($ platform ));
41
43
}
42
44
43
- throw ConversionException:: conversionFailedInvalidType ( $ value , static ::class, [ ' null ' , DateTimeInterface::class] );
45
+ throw new ConversionException ( sprintf ( ' Expected %s, got %s ' , DateTimeInterface::class, get_debug_type ( $ value )) );
44
46
}
45
47
46
48
private function getFormat (AbstractPlatform $ platform ): string
47
49
{
48
50
return match (true ) {
49
51
$ platform instanceof AbstractMySQLPlatform => 'Y-m-d H:i:s.u ' ,
50
52
$ platform instanceof PostgreSQLPlatform => 'Y-m-d H:i:s.u ' ,
51
- default => throw Exception:: notSupported ( __METHOD__ ),
53
+ default => throw new Exception ( ' Platform not supported ' ),
52
54
};
53
55
}
54
56
@@ -73,7 +75,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform): mixed
73
75
}
74
76
75
77
if ($ val === false ) {
76
- throw ConversionException:: conversionFailedFormat ( $ value, static ::class, $ format );
78
+ throw new ConversionException ( ' Failed to convert value to ' . $ this -> getClassName () );
77
79
}
78
80
79
81
return $ val ;
0 commit comments