TASK: Refactor code to use guards and decrease indentation

This commit is contained in:
Daniel Siepmann 2018-10-27 13:15:02 +02:00
parent 5d5af73705
commit 140dea3cbb
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
3 changed files with 33 additions and 24 deletions

View file

@ -99,11 +99,13 @@ class Facet implements FacetInterface
*/ */
protected function initOptions() protected function initOptions()
{ {
if ($this->options === null) { if (is_array($this->options)) {
$this->options = []; return;
foreach ($this->buckets as $bucket) { }
$this->options[$bucket['key']] = new FacetOption($bucket);
} $this->options = [];
foreach ($this->buckets as $bucket) {
$this->options[$bucket['key']] = new FacetOption($bucket);
} }
} }
} }

View file

@ -115,11 +115,13 @@ class SearchResult implements SearchResultInterface
*/ */
protected function initResults() protected function initResults()
{ {
if ($this->results === null) { if (is_array($this->results)) {
$this->results = []; return;
foreach ($this->result->getResults() as $result) { }
$this->results[] = new ResultItem($result->getData(), $result->getParam('_type'));
} $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() protected function initFacets()
{ {
if ($this->facets === null) { if (is_array($this->facets)) {
$this->facets = []; return;
if ($this->result->hasAggregations()) { }
foreach ($this->result->getAggregations() as $aggregationName => $aggregation) {
$this->facets[$aggregationName] = $this->objectManager->get( $this->facets = [];
Facet::class, if ($this->result->hasAggregations()) {
$aggregationName, foreach ($this->result->getAggregations() as $aggregationName => $aggregation) {
$aggregation $this->facets[$aggregationName] = $this->objectManager->get(
); Facet::class,
} $aggregationName,
$aggregation
);
} }
} }
} }

View file

@ -79,10 +79,13 @@ class SearchResult implements SearchResultInterface
*/ */
protected function initResults() protected function initResults()
{ {
if ($this->results === null) { if (is_array($this->results)) {
foreach ($this->resultItems as $item) { return;
$this->results[] = new ResultItem($item['data'], $item['type']); }
}
$this->results = [];
foreach ($this->resultItems as $item) {
$this->results[] = new ResultItem($item['data'], $item['type']);
} }
} }