Completed
Push — master ( 357c73...c8ba24 )
by Karel
37:25 queued 27:22
created

RawPartialResults::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace FOS\ElasticaBundle\Paginator;
4
5
use Elastica\ResultSet;
6
use Elastica\Result;
7
8
/**
9
 * Raw partial results transforms to a simple array.
10
 */
11
class RawPartialResults implements PartialResultsInterface
12
{
13
    protected $resultSet;
14
15
    /**
16
     * @param ResultSet $resultSet
17
     */
18
    public function __construct(ResultSet $resultSet)
19
    {
20
        $this->resultSet = $resultSet;
21
    }
22
23
    /**
24
     * {@inheritDoc}
25
     */
26
    public function toArray()
27
    {
28
        return array_map(function (Result $result) {
29
            return $result->getSource();
30
        }, $this->resultSet->getResults());
31
    }
32
33
    /**
34
     * {@inheritDoc}
35
     */
36
    public function getTotalHits()
37
    {
38
        return $this->resultSet->getTotalHits();
39
    }
40
41
    /**
42
     * {@inheritDoc}
43
     */
44
    public function getAggregations()
45
    {
46
        if ($this->resultSet->hasAggregations()) {
47
            return $this->resultSet->getAggregations();
48
        }
49
50
        return;
51
    }
52
}
53