Completed
Push — master ( 6a0101...61ff1f )
by Karel
10:05 queued 08:15
created

RawPartialResults::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of the FOSElasticaBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\ElasticaBundle\Paginator;
13
14
use Elastica\Result;
15
use Elastica\ResultSet;
16
17
/**
18
 * Raw partial results transforms to a simple array.
19
 */
20
class RawPartialResults implements PartialResultsInterface
21
{
22
    protected $resultSet;
23
24
    /**
25
     * @param ResultSet $resultSet
26
     */
27 2
    public function __construct(ResultSet $resultSet)
28
    {
29 2
        $this->resultSet = $resultSet;
30 2
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function toArray()
36
    {
37
        return array_map(function (Result $result) {
38
            return $result->getSource();
39
        }, $this->resultSet->getResults());
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function getTotalHits()
46
    {
47
        return $this->resultSet->getTotalHits();
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function getAggregations()
54
    {
55
        if ($this->resultSet->hasAggregations()) {
56
            return $this->resultSet->getAggregations();
57
        }
58
59
        return;
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function getSuggests()
66
    {
67
        if ($this->resultSet->hasSuggests()) {
68
            return $this->resultSet->getSuggests();
69
        }
70
71
        return;
72
    }
73
}
74