ScrollReader::getItems()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.2
c 0
b 0
f 0
cc 4
eloc 10
nc 3
nop 0
1
<?php declare(strict_types=1);
2
3
namespace Port\Elasticsearch;
4
5
use Elasticsearch\Client;
6
use Port\Reader;
7
8
class ScrollReader implements Reader
0 ignored issues
show
Bug introduced by
There is at least one abstract method in this class. Maybe declare it as abstract, or implement the remaining methods: current, key, next, rewind, valid
Loading history...
9
{
10
    private $client;
11
12
    private $query;
13
14
    private $scrollTTL = '1m';
15
16
    public function __construct($client, array $query)
17
    {
18
        $this->client = $client;
19
        $this->query = $query;
20
    }
21
22
    public function setScrollTTL(string $ttl): void
23
    {
24
        $this->scrollTTL = $ttl;
25
    }
26
27
    public function getItems(): \Generator
28
    {
29
        $query = $this->query;
30
        $query['scroll'] = $this->scollTTL;
0 ignored issues
show
Bug introduced by
The property scollTTL does not seem to exist. Did you mean scrollTTL?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
31
32
        $response = $this->client->search($this->query);
33
34
        while (isset($response['hits']['hits']) && count($response['hits']['hits']) > 0) {
35
36
            foreach ($response['hits']['hits'] as $doc) {
37
                yield $doc;
38
            }
39
        
40
            $response = $client->scroll([
0 ignored issues
show
Bug introduced by
The variable $client does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
41
                    'scroll_id' => $response['_scroll_id'],
42
                    'scroll' => $this->scrollTTL,
43
                ]
44
            );
45
        }
46
    }
47
}