Completed
Push — master ( 80d3da...0d64d6 )
by Karel
14s
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 <https://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 2
    public function __construct(ResultSet $resultSet)
25
    {
26 2
        $this->resultSet = $resultSet;
27 2
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function toArray()
33
    {
34
        return \array_map(function (Result $result) {
35
            return $result->getSource();
36
        }, $this->resultSet->getResults());
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function getTotalHits()
43
    {
44
        return $this->resultSet->getTotalHits();
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function getAggregations()
51
    {
52
        if ($this->resultSet->hasAggregations()) {
53
            return $this->resultSet->getAggregations();
54
        }
55
56
        return;
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function getSuggests()
63
    {
64
        if ($this->resultSet->hasSuggests()) {
65
            return $this->resultSet->getSuggests();
66
        }
67
68
        return;
69
    }
70
}
71