Passed
Push — master ( f1e39a...75b946 )
by Adrian
04:36
created

PercolateDocsResultSet::getProfile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 1
1
<?php
2
3
4
namespace Manticoresearch\Results;
5
6
class PercolateDocsResultSet implements \Iterator, \Countable
7
{
8
9
    /** @var int The position of the iterator through the result set */
10
    protected $position = 0;
11
12
    /** @var Response */
0 ignored issues
show
Bug introduced by
The type Manticoresearch\Results\Response was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
    protected $response;
14
15
    protected $array = [];
16
17
    /** @var int|mixed Total number of results */
18
    protected $total = 0;
19
20
    protected $took;
21
22
    /** @var mixed Did the query time out? */
23
    protected $timed_out;
24
25
    protected $profile;
26
27
    public function __construct($responseObj, $docs)
28
    {
29
30
        foreach ($docs as $doc) {
31
            $this->array[] = ['doc' => $doc, 'queries' => []];
32
        }
33
        $this->response = $responseObj;
34
        $response = $responseObj->getResponse();
35
        if (isset($response['hits']['hits'])) {
36
            $hits = $response['hits']['hits'];
37
            foreach ($hits as $query) {
38
                if (isset($query['fields'], $query['fields']['_percolator_document_slot'])) {
39
                    foreach ($query['fields']['_percolator_document_slot'] as $d) {
40
                        if (isset($this->array[$d-1])) {
41
                            $this->array[$d-1]['queries'][] =$query;
42
                        }
43
44
                    }
45
                }
46
            }
47
        }
48
    }
49
50
    public function rewind()
51
    {
52
        $this->position = 0;
53
    }
54
55
    public function current()
56
    {
57
        return new PercolateResultDoc($this->array[$this->position]);
58
    }
59
60
    public function next()
61
    {
62
        $this->position++;
63
    }
64
65
    public function valid()
66
    {
67
        return isset($this->array[$this->position]);
68
    }
69
70
    public function key()
71
    {
72
        return $this->position;
73
    }
74
75
    public function getTotal()
76
    {
77
        return $this->total;
78
    }
79
80
    public function getTime()
81
    {
82
        return $this->took;
83
    }
84
85
    public function hasTimedout()
86
    {
87
        return $this->timed_out;
88
    }
89
90
    /**
91
     * @return Response
92
     */
93
    public function getResponse()
94
    {
95
        return $this->response;
96
    }
97
98
    public function count()
99
    {
100
        return count($this->array);
101
    }
102
103
    public function getProfile()
104
    {
105
        return $this->profile;
106
    }
107
}
108