33namespace PHPStan \Platform ;
44
55use Cache \Adapter \PHPArray \ArrayCachePool ;
6+ use DateTimeImmutable ;
67use Doctrine \Common \Annotations \AnnotationReader ;
78use Doctrine \DBAL \Connection ;
89use Doctrine \DBAL \Driver ;
@@ -203,6 +204,24 @@ public static function provideCases(): iterable
203204 },
204205 ];
205206
207+ yield ' 0.1 ' => [
208+ 'data ' => self ::dataDefault (),
209+ 'select ' => 'SELECT 0.1 FROM %s t ' ,
210+ 'mysql ' => new ConstantStringType ('0.1 ' ),
211+ 'sqlite ' => new ConstantFloatType (0.1 ),
212+ 'pdo_pgsql ' => new ConstantStringType ('0.1 ' ),
213+ 'pgsql ' => new ConstantStringType ('0.1 ' ),
214+ 'mssql ' => new MixedType (),
215+ 'mysqlResult ' => '0.1 ' ,
216+ 'sqliteResult ' => 0.1 ,
217+ 'pdoPgsqlResult ' => '0.1 ' ,
218+ 'pgsqlResult ' => '0.1 ' ,
219+ 'mssqlResult ' => '.1 ' ,
220+ 'shouldStringify ' => static function (Driver $ driver , int $ php , string $ configName ): bool {
221+ return self ::defaultStringification ($ driver , $ php , $ configName );
222+ },
223+ ];
224+
206225 yield ' 1e0 ' => [
207226 'data ' => self ::dataDefault (),
208227 'select ' => 'SELECT 1e0 FROM %s t ' ,
@@ -3425,6 +3444,27 @@ public static function provideCases(): iterable
34253444 },
34263445 ];
34273446
3447+ yield 'COALESCE(t.col_datetime, t.col_datetime) ' => [
3448+ 'data ' => self ::dataDefault (),
3449+ 'select ' => 'SELECT COALESCE(t.col_datetime, t.col_datetime) FROM %s t ' ,
3450+ 'mysql ' => self ::string (),
3451+ 'sqlite ' => self ::string (),
3452+ 'pdo_pgsql ' => self ::string (),
3453+ 'pgsql ' => self ::string (),
3454+ 'mssql ' => self ::mixed (),
3455+ 'mysqlResult ' => '2024-01-31 12:59:59 ' ,
3456+ 'sqliteResult ' => '2024-01-31 12:59:59 ' ,
3457+ 'pdoPgsqlResult ' => '2024-01-31 12:59:59 ' ,
3458+ 'pgsqlResult ' => '2024-01-31 12:59:59 ' ,
3459+ 'mssqlResult ' => '2024-01-31 12:59:59.000000 ' , // doctrine/dbal changes default ReturnDatesAsStrings to true
3460+ 'shouldStringify ' => static function (): bool {
3461+ return false ;
3462+ },
3463+ ];
3464+
3465+ // TODO postgres ->setUseBooleanTrueFalseStrings()
3466+ // TODO string TypedExpression does not cast to string
3467+ // TODO sqlsrv uses native DateTime
34283468 // TODO would col_numeric_string differ from col_string results ?
34293469 // TODO dbal/orm versions
34303470 // TODO unknown driver to return mixed everywhere
@@ -3777,6 +3817,11 @@ private static function numericString(): Type
37773817 ]);
37783818 }
37793819
3820+ private static function string (): Type
3821+ {
3822+ return new StringType ();
3823+ }
3824+
37803825 private static function numericStringOrNull (): Type
37813826 {
37823827 return TypeCombinator::addNull (new IntersectionType ([
@@ -3854,6 +3899,7 @@ public static function dataDefault(): array
38543899 'col_string ' => 'foobar ' ,
38553900 'col_string_nullable ' => null ,
38563901 'col_mixed ' => 1 ,
3902+ 'col_datetime ' => new DateTimeImmutable ('2024-01-31 12:59:59 ' ),
38573903 ],
38583904 ];
38593905 }
@@ -3879,6 +3925,7 @@ public static function dataAllIntLike(): array
38793925 'col_string ' => '1 ' ,
38803926 'col_string_nullable ' => null ,
38813927 'col_mixed ' => 1 ,
3928+ 'col_datetime ' => new DateTimeImmutable ('2024-01-31 12:59:59 ' ),
38823929 ],
38833930 ];
38843931 }
@@ -3905,6 +3952,7 @@ public static function dataSqrt(): array
39053952 'col_string ' => 'foobar ' ,
39063953 'col_string_nullable ' => null ,
39073954 'col_mixed ' => 1 ,
3955+ 'col_datetime ' => new DateTimeImmutable ('2024-01-31 12:59:59 ' ),
39083956 ],
39093957 ];
39103958 }
0 commit comments