Passed
Push — 1.x ( 77e7f6...966118 )
by Adrian
02:40 queued 12s
created

ResultHit   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 57
rs 10
wmc 12

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __isset() 0 3 2
A __get() 0 3 1
A has() 0 3 1
A __construct() 0 3 1
A getData() 0 3 1
A get() 0 6 2
A setId() 0 3 1
A getScore() 0 3 1
A getHighlight() 0 3 1
A getId() 0 3 1
1
<?php
2
3
4
namespace Manticoresearch;
5
6
/**
7
 * Result hit object
8
 * Element of a result set
9
 * @category ManticoreSearch
10
 * @package ManticoreSearch
11
 * @author Adrian Nuta <[email protected]>
12
 * @link https://manticoresearch.com
13
 */
14
class ResultHit
15
{
16
    private $_data;
17
18
    public function __construct($data = [])
19
    {
20
        $this->_data = $data;
21
22
    }
23
24
    public function getId()
25
    {
26
        return $this->_data['_id'];
27
    }
28
29
    public function setId($id)
30
    {
31
        $this->_data['id'] = $id;
32
    }
33
34
    public function getScore()
35
    {
36
        return $this->_data['_score'];
37
    }
38
39
    public function getHighlight()
40
    {
41
        return $this->_data['highlight'];
42
    }
43
44
    public function __get(string $key)
45
    {
46
        return $this->get($key);
47
    }
48
49
    public function __isset(string $key): bool
50
    {
51
        return $this->has($key) && null !== $this->get($key);
52
    }
53
54
    public function get($key)
55
    {
56
        if (isset($this->_data['_source'][$key])) {
57
            return $this->_data['_source'][$key];
58
        }
59
        return [];
60
    }
61
62
63
    public function has($key)
64
    {
65
        return isset($this->data['_source'][$key]);
0 ignored issues
show
Bug Best Practice introduced by
The property data does not exist on Manticoresearch\ResultHit. Since you implemented __get, consider adding a @property annotation.
Loading history...
66
    }
67
68
    public function getData()
69
    {
70
        return $this->_data['_source'];
71
    }
72
73
}