44
55use Doctrine \DBAL \Platforms \AbstractPlatform ;
66use Doctrine \DBAL \Types \Type ;
7+ use Thunder \Platenum \Enum \AbstractConstantsEnum ;
78use Thunder \Platenum \Enum \EnumTrait ;
89
910/** @psalm-suppress PropertyNotSetInConstructor, MissingConstructor */
@@ -13,7 +14,7 @@ final class PlatenumDoctrineType extends Type
1314 private $ platenumClass ;
1415 /** @var string */
1516 private $ platenumAlias ;
16- /** @var callable */
17+ /** @var callable(mixed):mixed */
1718 private $ platenumCallback ;
1819 /** @psalm-var callable(array,AbstractPlatform):string */
1920 private $ platenumSql ;
@@ -46,7 +47,9 @@ public static function registerString(string $alias, string $class): void
4647 return (string )$ value ;
4748 };
4849 $ sql = function (array $ declaration , AbstractPlatform $ platform ): string {
49- return $ platform ->getVarcharTypeDeclarationSQL ([]);
50+ return method_exists ($ platform , 'getStringTypeDeclarationSQL ' )
51+ ? $ platform ->getStringTypeDeclarationSQL ([])
52+ : $ platform ->getVarcharTypeDeclarationSQL ([]);
5053 };
5154
5255 self ::registerCallback ($ alias , $ class , $ toString , $ sql );
@@ -55,7 +58,7 @@ public static function registerString(string $alias, string $class): void
5558 /**
5659 * @param string $alias
5760 * @psalm-param class-string $class
58- * @param callable $callback
61+ * @param callable(int|string):mixed $callback
5962 * @psalm-param callable(array<mixed>,AbstractPlatform):string $sql
6063 */
6164 private static function registerCallback (string $ alias , string $ class , callable $ callback , callable $ sql ): void
@@ -120,8 +123,8 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)
120123 throw new \LogicException (sprintf ($ message , self ::class, gettype ($ value )));
121124 }
122125
123- /** @psalm-suppress MixedMethodCall */
124- return ($ this ->platenumCallback )( $ value ->getValue ());
126+ /** @var AbstractConstantsEnum $value */
127+ return call_user_func ($ this ->platenumCallback , $ value ->getValue ());
125128 }
126129
127130 public function convertToPHPValue ($ value , AbstractPlatform $ platform )
0 commit comments