Skip to content

Commit 9c50b0f

Browse files
staabmclxmstaab
andauthored
Support simulation of date/dateime placeholders (#244)
Co-authored-by: Markus Staab <[email protected]>
1 parent 3ae14e9 commit 9c50b0f

File tree

8 files changed

+1004
-154
lines changed

8 files changed

+1004
-154
lines changed

.phpstan-dba.cache

Lines changed: 16 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/QueryReflection/MysqliQueryReflector.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ final class MysqliQueryReflector implements QueryReflector
3131

3232
public const MYSQL_HOST_NOT_FOUND = 2002;
3333

34+
public const DATE_FORMAT = 'Y-m-d';
35+
3436
private const MAX_CACHE_SIZE = 50;
3537

3638
/**

src/QueryReflection/QuerySimulation.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ public static function simulateParamValueType(Type $paramType, bool $preparedPar
7575
if ($stringType->isSuperTypeOf($paramType)->yes() || $paramType instanceof ObjectType && $paramType->isInstanceOf(Stringable::class)->yes()) {
7676
// in a prepared context, regular strings are fine
7777
if (true === $preparedParam) {
78-
return '1';
78+
// returns a string in date-format, so in case the simulated value is used against a date/datetime column
79+
// we won't run into a sql error.
80+
// XX in case we would have a proper sql parser, we could feed schema-type-dependent default values in case of strings.
81+
return date(MysqliQueryReflector::DATE_FORMAT);
7982
}
8083

8184
// plain string types can contain anything.. we cannot reason about it

0 commit comments

Comments
 (0)