Passed
Pull Request — master (#7)
by Sandro
03:17
created

ArrayAccessStreamHandlerTrait::scannedIndex()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * Sandro Keil (https://sandro-keil.de)
4
 *
5
 * @link      http://github.com/sandrokeil/arangodb-php-client for the canonical source repository
6
 * @copyright Copyright (c) 2018-2019 Sandro Keil
7
 * @license   http://github.com/sandrokeil/arangodb-php-client/blob/master/LICENSE.md New BSD License
8
 */
9
10
declare(strict_types=1);
11
12
namespace ArangoDb\Statement;
13
14
trait ArrayAccessStreamHandlerTrait
15
{
16
    /**
17
     * Current position in result set iteration (zero-based)
18
     *
19
     * @var int
20
     */
21
    private $position = 0;
22
23
    /**
24
     * Number of HTTP calls that were made to build the cursor result
25
     *
26
     * @var int
27
     */
28
    private $fetches = 0;
29
30
    /**
31
     * Total length of result set (in number of documents)
32
     *
33
     * @var int
34
     */
35
    private $length;
36
37
    /**
38
     * @var int
39
     */
40
    private $batchSize;
41
42 4
    public function cursorId(): ?string
43
    {
44 4
        return $this->data[$this->fetches]['id'] ?? null;
45
    }
46
47 7
    public function hasMore(): bool
48
    {
49 7
        return $this->data[$this->fetches]['hasMore'] ?? false;
50
    }
51
52 1
    public function resultCount(): ?int
53
    {
54 1
        return $this->data[$this->fetches]['count'] ?? null;
55
    }
56
57
    /**
58
     * Get the total number of current loaded results.
59
     *
60
     * @return int Total number of laoded results
61
     */
62 1
    public function count()
63
    {
64 1
        return $this->length;
65
    }
66
67
    public function rewind(): void
68
    {
69
        $this->position = 0;
70
    }
71
72 3
    public function key(): int
73
    {
74 3
        return $this->position;
75
    }
76
77 3
    public function next(): void
78
    {
79 3
        $this->position++;
80 3
    }
81
82
    /**
83
     * @return bool
84
     */
85 3
    public function valid(): bool
86
    {
87 3
        if ($this->position <= $this->length - 1) {
88
            // we have more results than the current position is
89 3
            return true;
90
        }
91
92 3
        return ($this->position <= $this->length - 1);
93
    }
94
95
    public function writesExecuted(): ?int
96
    {
97
        return $this->data[$this->fetches]['extra']['stats']['writesExecuted'] ?? null;
98
    }
99
100
    public function writesIgnored(): ?int
101
    {
102
        return $this->data[$this->fetches]['extra']['stats']['writesIgnored'] ?? null;
103
    }
104
105
    public function scannedFull(): ?int
106
    {
107
        return $this->data[$this->fetches]['extra']['stats']['scannedFull'] ?? null;
108
    }
109
110
    public function scannedIndex(): ?int
111
    {
112
        return $this->data[$this->fetches]['extra']['stats']['scannedIndex'] ?? null;
113
    }
114
115
    public function filtered(): ?int
116
    {
117
        return $this->data[$this->fetches]['extra']['stats']['filtered'] ?? null;
118
    }
119
120 1
    public function fullCount(): ?int
121
    {
122 1
        return $this->data[$this->fetches]['extra']['stats']['fullCount'] ?? null;
123
    }
124
125
    public function warnings(): array
126
    {
127
        return $this->data[$this->fetches]['extra']['warnings'] ?? [];
128
    }
129
130
    public function isCached(): bool
131
    {
132
        return $this->data[$this->fetches]['cached'] ?? false;
133
    }
134
}
135