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

RawPartialResults   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 42
ccs 0
cts 21
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A toArray() 0 6 1
A getTotalHits() 0 4 1
A getAggregations() 0 8 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