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 PHP foreach loop warnings for unset Makaira response properties #50

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions src/Makaira/Connect/Core/Autosuggester.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
6 changes: 4 additions & 2 deletions src/Makaira/Connect/SearchHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down