Skip to content

Commit 1cb1435

Browse files
authored
Fix types (#715)
1 parent 1a8c8fb commit 1cb1435

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/QueryReflection/ReflectionCache.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ private function readCachedRecords(bool $useReadLock): ?array
157157

158158
// the schemaHash is only available in replay-and-record mode.
159159
if (null === $this->schemaHash) {
160+
if ($cache['schemaHash'] !== null && ! is_string($cache['schemaHash'])) {
161+
throw new ShouldNotHappenException();
162+
}
160163
$this->schemaHash = $cache['schemaHash'];
161164
} elseif ($this->schemaHash !== $cache['schemaHash']) {
162165
return null;

src/SqlAst/ParserInference.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ public function narrowResultType(string $queryString, ConstantArrayType $resultT
7474
$fromTable = $this->schemaReflection->getTable($fromName);
7575
} elseif ($from instanceof Join) {
7676
while (1) {
77+
if (! $from instanceof Join || ! method_exists($from, 'getCondition')) {
78+
return $resultType;
79+
}
80+
7781
if ($from->getCondition() === null) {
7882
if (QueryReflection::getRuntimeConfiguration()->isDebugEnabled()) {
7983
throw new UnresolvableAstInQueryException('Cannot narrow down types null join conditions: ' . $queryString);
@@ -104,14 +108,16 @@ public function narrowResultType(string $queryString, ConstantArrayType $resultT
104108
$joinType = SchemaJoin::TYPE_INNER;
105109
}
106110

107-
$joinedTable = $this->schemaReflection->getTable($from->getRight()->getTable()->getName());
111+
if ($from->getRight() instanceof TableReferenceTable) {
112+
$joinedTable = $this->schemaReflection->getTable($from->getRight()->getTable()->getName());
108113

109-
if ($joinedTable !== null) {
110-
$joins[] = new SchemaJoin(
111-
$joinType,
112-
$joinedTable,
113-
$from->getCondition()
114-
);
114+
if ($joinedTable !== null) {
115+
$joins[] = new SchemaJoin(
116+
$joinType,
117+
$joinedTable,
118+
$from->getCondition()
119+
);
120+
}
115121
}
116122

117123
if ($from->getLeft() instanceof TableReferenceTable) {

0 commit comments

Comments
 (0)