Skip to content

Commit a9e92cd

Browse files
staabmclxmstaab
andauthored
cover more unresolvable-query cases (#167)
Co-authored-by: Markus Staab <[email protected]>
1 parent 601c328 commit a9e92cd

File tree

5 files changed

+33
-1
lines changed

5 files changed

+33
-1
lines changed

src/QueryReflection/QuerySimulation.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,13 @@ public static function simulateParamValueType(Type $paramType): ?string
7474
return null;
7575
}
7676

77+
// plain string types can contain anything.. we cannot reason about it
78+
if ($paramType instanceof StringType) {
79+
return null;
80+
}
81+
7782
// all types which we can't simulate and render a query unresolvable at analysis time
78-
if ($paramType instanceof MixedType || $paramType instanceof StringType || $paramType instanceof IntersectionType) {
83+
if ($paramType instanceof MixedType || $paramType instanceof IntersectionType) {
7984
if (QueryReflection::getRuntimeConfiguration()->isDebugEnabled()) {
8085
throw new UnresolvableQueryException('Cannot simulate parameter value for type: '.$paramType->describe(VerbosityLevel::precise()));
8186
}

tests/data/unresolvable-pdo-statement.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,16 @@ public function noErrorOnMixedQuery(PDO $pdo, $mixed)
2020
$stmt = $pdo->prepare($mixed);
2121
$stmt->execute([]);
2222
}
23+
24+
public function noErrorOnStringQuery(PDO $pdo, string $query)
25+
{
26+
$stmt = $pdo->prepare($query);
27+
$stmt->execute([]);
28+
}
29+
30+
public function noErrorOnStringAndParamsQuery(PDO $pdo, string $query, array $params)
31+
{
32+
$stmt = $pdo->prepare($query);
33+
$stmt->execute($params);
34+
}
2335
}

tests/data/unresolvable-query-in-function.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,9 @@ public function noErrorOnMixedQuery(DbCredentials $dbCredentials, $mixed)
2323
// which don't know anything about the actual query
2424
\Deployer\runMysqlQuery($mixed, $dbCredentials);
2525
}
26+
27+
public function noErrorOnStringQuery(DbCredentials $dbCredentials, string $query)
28+
{
29+
\Deployer\runMysqlQuery($query, $dbCredentials);
30+
}
2631
}

tests/data/unresolvable-query-in-method.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,9 @@ public function noErrorOnMixedQuery(PDO $pdo, $mixed)
2323
// which don't know anything about the actual query
2424
$pdo->query($mixed);
2525
}
26+
27+
public function noErrorOnStringQuery(PDO $pdo, string $query)
28+
{
29+
$pdo->query($query);
30+
}
2631
}

tests/data/unresolvable-statement.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,9 @@ public function noErrorOnMixedQuery(Connection $connection, $mixed)
1919
// which don't know anything about the actual query
2020
$connection->preparedQuery($mixed, []);
2121
}
22+
23+
public function noErrorOnStringQuery(Connection $connection, string $string)
24+
{
25+
$connection->preparedQuery($string, []);
26+
}
2227
}

0 commit comments

Comments
 (0)