SearchResult::getShards()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Triadev\Es\Dsl\Model;
3
4
use Illuminate\Support\Collection;
5
6
class SearchResult
7
{
8
    /** @var int */
9
    private $took;
10
    
11
    /** @var bool */
12
    private $timedOut;
13
    
14
    /** @var array */
15
    private $shards;
16
    
17
    /** @var Collection */
18
    private $hits;
19
    
20
    /** @var int */
21
    private $totalHits;
22
    
23
    /** @var float */
24
    private $maxScore;
25
    
26
    /** @var array|null */
27
    private $aggregation;
28
    
29
    /**
30
     * SearchResult constructor.
31
     * @param array $result
32
     */
33 1
    public function __construct(array $result)
34
    {
35 1
        $this->took = (int)array_get($result, 'took');
36 1
        $this->timedOut = (bool)array_get($result, 'timed_out');
37 1
        $this->shards = (array)array_get($result, '_shards');
38 1
        $this->hits = new Collection(array_get($result, 'hits.hits'));
39 1
        $this->totalHits = (int)array_get($result, 'hits.total');
40 1
        $this->maxScore = (float)array_get($result, 'hits.max_score');
41 1
        $this->aggregation = array_get($result, 'aggregations', null);
42 1
    }
43
    
44
    /**
45
     * @return int
46
     */
47 1
    public function getTook(): int
48
    {
49 1
        return $this->took;
50
    }
51
    
52
    /**
53
     * @return bool
54
     */
55 1
    public function isTimedOut(): bool
56
    {
57 1
        return $this->timedOut;
58
    }
59
    
60
    /**
61
     * @return array
62
     */
63 1
    public function getShards(): array
64
    {
65 1
        return $this->shards;
66
    }
67
    
68
    /**
69
     * @return Collection
70
     */
71 1
    public function getHits(): Collection
72
    {
73 1
        return $this->hits;
74
    }
75
    
76
    /**
77
     * @param Collection $hits
78
     */
79
    public function setHits(Collection $hits)
80
    {
81
        $this->hits = $hits;
82
    }
83
    
84
    /**
85
     * @return int
86
     */
87 1
    public function getTotalHits(): int
88
    {
89 1
        return $this->totalHits;
90
    }
91
    
92
    /**
93
     * @return float
94
     */
95 1
    public function getMaxScore(): float
96
    {
97 1
        return $this->maxScore;
98
    }
99
    
100
    /**
101
     * @return array|null
102
     */
103 1
    public function getAggregation(): ?array
104
    {
105 1
        return $this->aggregation;
106
    }
107
}
108