diff --git a/src/QueryReflection/ReflectionCache.php b/src/QueryReflection/ReflectionCache.php index 840fedd88..816013c26 100644 --- a/src/QueryReflection/ReflectionCache.php +++ b/src/QueryReflection/ReflectionCache.php @@ -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; diff --git a/src/SqlAst/ParserInference.php b/src/SqlAst/ParserInference.php index 273316574..3c5ef5995 100644 --- a/src/SqlAst/ParserInference.php +++ b/src/SqlAst/ParserInference.php @@ -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); @@ -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) {