Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix types #715

Merged
merged 4 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/QueryReflection/ReflectionCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ private function readCachedRecords(bool $useReadLock): ?array

// the schemaHash is only available in replay-and-record mode.
if (null === $this->schemaHash) {
if ($cache['schemaHash'] !== null && ! is_string($cache['schemaHash'])) {
throw new ShouldNotHappenException();
}
$this->schemaHash = $cache['schemaHash'];
} elseif ($this->schemaHash !== $cache['schemaHash']) {
return null;
Expand Down
20 changes: 13 additions & 7 deletions src/SqlAst/ParserInference.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public function narrowResultType(string $queryString, ConstantArrayType $resultT
$fromTable = $this->schemaReflection->getTable($fromName);
} elseif ($from instanceof Join) {
while (1) {
if (! $from instanceof Join || ! method_exists($from, 'getCondition')) {
return $resultType;
}

if ($from->getCondition() === null) {
if (QueryReflection::getRuntimeConfiguration()->isDebugEnabled()) {
throw new UnresolvableAstInQueryException('Cannot narrow down types null join conditions: ' . $queryString);
Expand Down Expand Up @@ -104,14 +108,16 @@ public function narrowResultType(string $queryString, ConstantArrayType $resultT
$joinType = SchemaJoin::TYPE_INNER;
}

$joinedTable = $this->schemaReflection->getTable($from->getRight()->getTable()->getName());
if ($from->getRight() instanceof TableReferenceTable) {
$joinedTable = $this->schemaReflection->getTable($from->getRight()->getTable()->getName());

if ($joinedTable !== null) {
$joins[] = new SchemaJoin(
$joinType,
$joinedTable,
$from->getCondition()
);
if ($joinedTable !== null) {
$joins[] = new SchemaJoin(
$joinType,
$joinedTable,
$from->getCondition()
);
}
}

if ($from->getLeft() instanceof TableReferenceTable) {
Expand Down