From 140dea3cbbd695141651daa1750658d2fb0d5d2d Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Sat, 27 Oct 2018 13:15:02 +0200 Subject: [PATCH] TASK: Refactor code to use guards and decrease indentation --- Classes/Connection/Elasticsearch/Facet.php | 12 ++++--- .../Connection/Elasticsearch/SearchResult.php | 34 +++++++++++-------- Classes/Domain/Model/SearchResult.php | 11 +++--- 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/Classes/Connection/Elasticsearch/Facet.php b/Classes/Connection/Elasticsearch/Facet.php index 45aa865..c1fb1e5 100644 --- a/Classes/Connection/Elasticsearch/Facet.php +++ b/Classes/Connection/Elasticsearch/Facet.php @@ -99,11 +99,13 @@ class Facet implements FacetInterface */ protected function initOptions() { - if ($this->options === null) { - $this->options = []; - foreach ($this->buckets as $bucket) { - $this->options[$bucket['key']] = new FacetOption($bucket); - } + if (is_array($this->options)) { + return; + } + + $this->options = []; + foreach ($this->buckets as $bucket) { + $this->options[$bucket['key']] = new FacetOption($bucket); } } } diff --git a/Classes/Connection/Elasticsearch/SearchResult.php b/Classes/Connection/Elasticsearch/SearchResult.php index 5773a50..faa8e37 100644 --- a/Classes/Connection/Elasticsearch/SearchResult.php +++ b/Classes/Connection/Elasticsearch/SearchResult.php @@ -115,11 +115,13 @@ class SearchResult implements SearchResultInterface */ protected function initResults() { - if ($this->results === null) { - $this->results = []; - foreach ($this->result->getResults() as $result) { - $this->results[] = new ResultItem($result->getData(), $result->getParam('_type')); - } + if (is_array($this->results)) { + return; + } + + $this->results = []; + foreach ($this->result->getResults() as $result) { + $this->results[] = new ResultItem($result->getData(), $result->getParam('_type')); } } @@ -128,16 +130,18 @@ class SearchResult implements SearchResultInterface */ protected function initFacets() { - if ($this->facets === null) { - $this->facets = []; - if ($this->result->hasAggregations()) { - foreach ($this->result->getAggregations() as $aggregationName => $aggregation) { - $this->facets[$aggregationName] = $this->objectManager->get( - Facet::class, - $aggregationName, - $aggregation - ); - } + if (is_array($this->facets)) { + return; + } + + $this->facets = []; + if ($this->result->hasAggregations()) { + foreach ($this->result->getAggregations() as $aggregationName => $aggregation) { + $this->facets[$aggregationName] = $this->objectManager->get( + Facet::class, + $aggregationName, + $aggregation + ); } } } diff --git a/Classes/Domain/Model/SearchResult.php b/Classes/Domain/Model/SearchResult.php index 97a12fb..80b88e7 100644 --- a/Classes/Domain/Model/SearchResult.php +++ b/Classes/Domain/Model/SearchResult.php @@ -79,10 +79,13 @@ class SearchResult implements SearchResultInterface */ protected function initResults() { - if ($this->results === null) { - foreach ($this->resultItems as $item) { - $this->results[] = new ResultItem($item['data'], $item['type']); - } + if (is_array($this->results)) { + return; + } + + $this->results = []; + foreach ($this->resultItems as $item) { + $this->results[] = new ResultItem($item['data'], $item['type']); } }