Skip to content

Commit 64cb8ee

Browse files
committed
fix
1 parent 984ad6c commit 64cb8ee

File tree

3 files changed

+28
-17
lines changed

3 files changed

+28
-17
lines changed

src/QueryReflection/QueryReflection.php

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,18 @@ public function resolveParameterTypes(Expr $parameter, Scope $scope): Type
437437
}
438438
}
439439

440-
return $scope->getType($parameter);
440+
$parameterType = $scope->getType($parameter);
441+
if (
442+
$parameter instanceof Expr\Variable
443+
&& $parameterType->isArray()->yes()
444+
&& $parameterType->isIterableAtLeastOnce()->maybe()
445+
) {
446+
$builder = ConstantArrayTypeBuilder::createEmpty();
447+
$builder->setOffsetValueType(new ConstantIntegerType(0), $parameterType->getIterableValueType());
448+
return $builder->getArray();
449+
}
450+
451+
return $parameterType;
441452
}
442453

443454
/**
@@ -473,20 +484,6 @@ public function resolveParameters(Type $parameterTypes): ?array
473484
return $this->resolveConstantArray($arrays[0]);
474485
}
475486

476-
if ($parameterTypes->isArray()->yes()) {
477-
$valueType = $parameterTypes->getIterableValueType();
478-
479-
if ($valueType->isScalar()->yes()) {
480-
return [new Parameter(
481-
null,
482-
$valueType,
483-
QuerySimulation::simulateParamValueType($valueType, true),
484-
false
485-
)];
486-
}
487-
}
488-
489-
490487
return null;
491488
}
492489

src/Rules/SyntaxErrorInPreparedStatementMethodRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ private function checkErrors(CallLike $callLike, Scope $scope): array
110110
if (\count($args) > 1) {
111111
$parameterTypes = $queryReflection->resolveParameterTypes($args[1]->value, $scope);
112112
try {
113-
$parameters = $queryReflection->resolveParameters($parameterTypes) ?? [];
113+
$parameters = $queryReflection->resolveParameters($parameterTypes);
114114
} catch (UnresolvableQueryException $exception) {
115115
return [
116116
RuleErrorBuilder::message($exception->asRuleMessage())->tip($exception::getTip())->identifier('dba.unresolvableQuery')->line($callLike->getStartLine())->build(),

tests/rules/data/bug-749.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function getMoreIds(string $s, array $ids): array
4242
/**
4343
* @param array<int> $ids
4444
*/
45-
public function getArrayIds(string $s, array $ids): array
45+
public function getArrayIds(array $ids): array
4646
{
4747
return $this
4848
->connection
@@ -53,6 +53,20 @@ public function getArrayIds(string $s, array $ids): array
5353
->fetchFirstColumn();
5454
}
5555

56+
/**
57+
* @param array<int> $ids
58+
*/
59+
public function getArrayIdMix(int $i, array $ids): array
60+
{
61+
return $this
62+
->connection
63+
->executeQuery(
64+
'SELECT akid FROM ak WHERE eladaid = ? AND akid IN ('. self::inPlaceholders($ids) .')',
65+
array_merge([$i], $ids),
66+
)
67+
->fetchFirstColumn();
68+
}
69+
5670
/**
5771
* Returns a string containing all required "?"-placeholders to pass $ids into a IN()-expression.
5872
*

0 commit comments

Comments
 (0)