Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 16
SingleAggResultsType
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 6
56
0.00% covered (danger)
0.00%
0 / 16
 __construct
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getSourceFiltering
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getStoredFields
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getHighlightingConfiguration
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 transformElasticsearchResult
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 6
 createEmptyResult
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
<?php
namespace CirrusSearch\Search;
use Elastica\ResultSet as ElasticaResultSet;
/**
 * Result type for aggregations.
 */
class SingleAggResultsType implements ResultsType {
    /** @var string Name of aggregation */
    private $name;
    /** @param string $name Name of aggregation to return */
    public function __construct( $name ) {
        $this->name = $name;
    }
    /**
     * @return false|string|array corresponding to Elasticsearch source filtering syntax
     */
    public function getSourceFiltering() {
        return false;
    }
    public function getStoredFields() {
        return [];
    }
    public function getHighlightingConfiguration( array $extraHighlightFields ) {
        return null;
    }
    /**
     * @param ElasticaResultSet $resultSet
     * @return mixed|null Type depends on the aggregation performed. For
     *  a sum this will return an integer.
     */
    public function transformElasticsearchResult( ElasticaResultSet $resultSet ) {
        $aggs = $resultSet->getAggregations();
        if ( isset( $aggs[$this->name] ) ) {
            return $aggs[$this->name]['value'];
        }
        return $this->createEmptyResult();
    }
    /**
     * @return null
     */
    public function createEmptyResult() {
        return null;
    }
}