From 6cdf7fa25c797c44836f8fe519c3d4349e33d3e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20R=C3=BCtter?= Date: Tue, 25 Apr 2023 15:16:10 +0200 Subject: [PATCH] Fix PHP foreach loop warnings for unset Makaira response properties --- src/Makaira/Connect/Core/Autosuggester.php | 8 ++++---- src/Makaira/Connect/SearchHandler.php | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Makaira/Connect/Core/Autosuggester.php b/src/Makaira/Connect/Core/Autosuggester.php index 66491fc8..00558c4c 100644 --- a/src/Makaira/Connect/Core/Autosuggester.php +++ b/src/Makaira/Connect/Core/Autosuggester.php @@ -167,7 +167,7 @@ public function search($searchPhrase = "") // get category results $aCategories = []; - if ($result['category']) { + if (is_object($result['category'])) { foreach ($result['category']->items as $document) { $aCategories[] = $this->prepareCategoryItem($document); } @@ -177,7 +177,7 @@ public function search($searchPhrase = "") // get manufacturer results $aManufacturers = []; - if ($result['manufacturer']) { + if (is_object($result['manufacturer'])) { foreach ($result['manufacturer']->items as $document) { $aManufacturers[] = $this->prepareManufacturerItem($document); } @@ -187,7 +187,7 @@ public function search($searchPhrase = "") // get searchable links results $aLinks = []; - if ($result['links']) { + if (is_object($result['links'])) { foreach ($result['links']->items as $document) { $aLinks[] = $this->prepareLinkItem($document); } @@ -197,7 +197,7 @@ public function search($searchPhrase = "") // get suggestion results $aSuggestions = []; - if ($result['suggestion']) { + if (is_object($result['suggestion'])) { foreach ($result['suggestion']->items as $document) { $aSuggestions[] = $this->prepareSuggestionItem($document); } diff --git a/src/Makaira/Connect/SearchHandler.php b/src/Makaira/Connect/SearchHandler.php index 34bbaafb..e305a645 100644 --- a/src/Makaira/Connect/SearchHandler.php +++ b/src/Makaira/Connect/SearchHandler.php @@ -143,8 +143,10 @@ private function parseResult($data, $max_items = -1) } $data['count'] = count($data['items']); - foreach ($data['aggregations'] as $key => $item) { - $data['aggregations'][ $key ] = new Aggregation($item); + if (isset($data['aggregations'])) { + foreach ($data['aggregations'] as $key => $item) { + $data['aggregations'][ $key ] = new Aggregation($item); + } } return new Result($data);