From 1129c4fe21b5607d3347ceaadc2b7a07f508af78 Mon Sep 17 00:00:00 2001 From: Bas Date: Sun, 15 Dec 2024 19:50:01 +0100 Subject: [PATCH] chore: qa improvements --- src/Query/Concerns/BuildsGroups.php | 6 ++---- src/Query/Concerns/CompilesColumns.php | 4 ++++ src/Query/Concerns/CompilesUnions.php | 6 ++++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Query/Concerns/BuildsGroups.php b/src/Query/Concerns/BuildsGroups.php index 45922ab..7607ec3 100644 --- a/src/Query/Concerns/BuildsGroups.php +++ b/src/Query/Concerns/BuildsGroups.php @@ -160,9 +160,7 @@ public function forNestedWhere($aliases = []) */ public function havingNested(Closure $callback, $boolean = 'and') { - $callback($query = $this->forNestedWhere($this->groups)); - - + $callback($query = $this->forNestedWhere($this->groups ?? [])); return $this->addNestedHavingQuery($query, $boolean); } @@ -176,7 +174,7 @@ public function havingNested(Closure $callback, $boolean = 'and') */ public function addNestedHavingQuery($query, $boolean = 'and') { - if (count($query->havings)) { + if (count($query->havings ?? [])) { $type = 'Nested'; $this->havings[] = compact('type', 'query', 'boolean'); diff --git a/src/Query/Concerns/CompilesColumns.php b/src/Query/Concerns/CompilesColumns.php index 40cd8cd..ca93959 100644 --- a/src/Query/Concerns/CompilesColumns.php +++ b/src/Query/Concerns/CompilesColumns.php @@ -289,6 +289,10 @@ protected function mergeJoinResults(IlluminateQueryBuilder $query, $returnDocs = { assert($query instanceof Builder); + if (!is_array($query->joins)) { + return $returnDocs; + } + foreach ($query->joins as $join) { $tableAlias = $query->getTableAlias($join->table); diff --git a/src/Query/Concerns/CompilesUnions.php b/src/Query/Concerns/CompilesUnions.php index 8bd5286..b7ff4b7 100644 --- a/src/Query/Concerns/CompilesUnions.php +++ b/src/Query/Concerns/CompilesUnions.php @@ -18,13 +18,19 @@ trait CompilesUnions */ protected function compileUnions(IlluminateBuilder $query, $firstQuery = '') { + if (!is_array($query->unions)) { + return ''; + } + $unionResultsId = 'union' . $query->getQueryId() . 'Results'; $unionDocId = 'union' . $query->getQueryId() . 'Result'; $query->registerTableAlias($unionResultsId, $unionDocId); $firstQuery = $this->wrapSubquery($firstQuery); + $unions = ''; + foreach ($query->unions as $union) { $prefix = ($unions !== '') ? $unions : $firstQuery; $unions = $this->compileUnion($union, $prefix);