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()
{
if ($this->options === null) {
if (is_array($this->options)) {
return;
}
$this->options = [];
foreach ($this->buckets as $bucket) {
$this->options[$bucket['key']] = new FacetOption($bucket);
}
}
}
}

View file

@ -115,20 +115,25 @@ class SearchResult implements SearchResultInterface
*/
protected function initResults()
{
if ($this->results === null) {
if (is_array($this->results)) {
return;
}
$this->results = [];
foreach ($this->result->getResults() as $result) {
$this->results[] = new ResultItem($result->getData(), $result->getParam('_type'));
}
}
}
/**
* @return void
*/
protected function initFacets()
{
if ($this->facets === null) {
if (is_array($this->facets)) {
return;
}
$this->facets = [];
if ($this->result->hasAggregations()) {
foreach ($this->result->getAggregations() as $aggregationName => $aggregation) {
@ -140,7 +145,6 @@ class SearchResult implements SearchResultInterface
}
}
}
}
/**
* Countable - Interface

View file

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