Skip to content

Commit 16fc4c8

Browse files
authored
Refactoring (#266)
* Refactoring * Update QuerySimulation.php * Update QuerySimulation.php * Update QuerySimulation.php * Update QuerySimulation.php
1 parent 88fd3b2 commit 16fc4c8

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/QueryReflection/MysqliQueryReflector.php

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

2525
public const MYSQL_HOST_NOT_FOUND = 2002;
2626

27-
public const DATE_FORMAT = 'Y-m-d';
28-
2927
private const MAX_CACHE_SIZE = 50;
3028

3129
private mysqli $db;

src/QueryReflection/QuerySimulation.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
*/
2828
final class QuerySimulation
2929
{
30+
public const DATE_FORMAT = 'Y-m-d';
31+
3032
/**
3133
* @throws UnresolvableQueryException
3234
*/
@@ -72,13 +74,18 @@ public static function simulateParamValueType(Type $paramType, bool $preparedPar
7274
}
7375

7476
$stringType = new StringType();
75-
if ($stringType->isSuperTypeOf($paramType)->yes() || $paramType instanceof ObjectType && $paramType->isInstanceOf(Stringable::class)->yes()) {
77+
$isStringableObjectType = $paramType instanceof ObjectType
78+
&& $paramType->isInstanceOf(Stringable::class)->yes();
79+
if (
80+
$stringType->isSuperTypeOf($paramType)->yes()
81+
|| $isStringableObjectType
82+
) {
7683
// in a prepared context, regular strings are fine
7784
if (true === $preparedParam) {
7885
// returns a string in date-format, so in case the simulated value is used against a date/datetime column
7986
// we won't run into a sql error.
8087
// 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, 0);
88+
return date(self::DATE_FORMAT, 0);
8289
}
8390

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

0 commit comments

Comments
 (0)