@@ -39,14 +39,15 @@ public static function transformPostgresTextArrayToPHPArray(string $postgresArra
3939
4040 $ jsonArray = '[ ' .\trim ($ trimmed , '{} ' ).'] ' ;
4141
42+ /** @var array<int, mixed>|null $decoded */
4243 $ decoded = \json_decode ($ jsonArray , true , 512 , JSON_BIGINT_AS_STRING );
4344 if ($ decoded === null && \json_last_error () !== JSON_ERROR_NONE ) {
4445 throw new \InvalidArgumentException ('Invalid array format: ' .\json_last_error_msg ());
4546 }
4647
4748 return \array_map (
48- static fn ($ value ): mixed => \is_string ($ value ) ? self ::unescapeString ($ value ) : $ value ,
49- $ decoded
49+ static fn (mixed $ value ): mixed => \is_string ($ value ) ? self ::unescapeString ($ value ) : $ value ,
50+ ( array ) $ decoded
5051 );
5152 }
5253
@@ -64,7 +65,11 @@ public static function transformPHPArrayToPostgresTextArray(array $phpArray): st
6465 throw new \InvalidArgumentException ('Only single-dimensioned arrays are supported ' );
6566 }
6667
67- $ processed = \array_map (static fn ($ value ): string => self ::formatValue ($ value ), $ phpArray );
68+ /** @var array<int|string, string> */
69+ $ processed = \array_map (
70+ static fn (mixed $ value ): string => self ::formatValue ($ value ),
71+ $ phpArray
72+ );
6873
6974 return '{ ' .\implode (', ' , $ processed ).'} ' ;
7075 }
@@ -84,8 +89,29 @@ private static function formatValue(mixed $value): string
8489 return (string ) $ value ;
8590 }
8691
87- // Convert to string if not already
88- $ stringValue = (string ) $ value ;
92+ // Handle booleans
93+ if (\is_bool ($ value )) {
94+ return $ value ? 'true ' : 'false ' ;
95+ }
96+
97+ // Handle objects that implement __toString()
98+ if (\is_object ($ value )) {
99+ if (\method_exists ($ value , '__toString ' )) {
100+ $ stringValue = $ value ->__toString ();
101+ } else {
102+ // For objects without __toString, use a default representation
103+ $ stringValue = $ value ::class;
104+ }
105+ } else {
106+ // For all other types, force string conversion
107+ // This covers strings, resources, and other types
108+ $ stringValue = match (true ) {
109+ \is_resource ($ value ) => '(resource) ' ,
110+ default => (string ) $ value // @phpstan-ignore-line
111+ };
112+ }
113+
114+ \assert (\is_string ($ stringValue ));
89115
90116 // Handle empty string
91117 if ($ stringValue === '' ) {
0 commit comments