Passed
Pull Request — master (#14)
by Sandro
03:13
created

SimdjsonHandler::appendStream()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
cc 1
nc 1
nop 1
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-2020 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
use Psr\Http\Message\StreamInterface;
15
16
final class SimdjsonHandler implements StreamHandler
17
{
18
    use SimdjsonStreamHandlerTrait;
19
20
    /**
21
     * @var mixed
22
     */
23
    private $data = [];
24
25 2
    public function __construct(StreamInterface $stream)
26
    {
27 2
        $this->data[$this->fetches] = \simdjson_resource($stream->getContents());
0 ignored issues
show
Bug introduced by
The function simdjson_resource was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

27
        $this->data[$this->fetches] = /** @scrutinizer ignore-call */ \simdjson_resource($stream->getContents());
Loading history...
28
        $this->length = count(\simdjson_key_value($this->data[$this->fetches], 'result', true));
0 ignored issues
show
Bug introduced by
The function simdjson_key_value was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
        $this->length = count(/** @scrutinizer ignore-call */ \simdjson_key_value($this->data[$this->fetches], 'result', true));
Loading history...
29
        $this->batchSize = $this->length;
30
    }
31
32
    /**
33
     * Return the current result row
34
     *
35
     * @return array
36
     */
37
    public function current(): array
38
    {
39
        return \simdjson_key_value(
0 ignored issues
show
Bug introduced by
The function simdjson_key_value was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

39
        return /** @scrutinizer ignore-call */ \simdjson_key_value(
Loading history...
40
            $this->data[$this->fetches],
41
            "result\t" . ($this->position - ($this->batchSize * $this->fetches)),
42
            true
43
        );
44
    }
45
46
    public function result(): array
47
    {
48
        return \simdjson_key_value(
0 ignored issues
show
Bug introduced by
The function simdjson_key_value was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

48
        return /** @scrutinizer ignore-call */ \simdjson_key_value(
Loading history...
49
            $this->data[$this->fetches],
50
            "result",
51
            true
52
        );
53
    }
54
55
    public function raw(): array
56
    {
57
        return $this->data[$this->fetches];
58
    }
59
60
    public function completeResult()
61
    {
62
        $completeResult = [[]];
63
64
        foreach ($this->data as $result) {
65
            $completeResult[] = \simdjson_key_value($result, 'result', true);
0 ignored issues
show
Bug introduced by
The function simdjson_key_value was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

65
            $completeResult[] = /** @scrutinizer ignore-call */ \simdjson_key_value($result, 'result', true);
Loading history...
66
        }
67
        return array_merge(...$completeResult);
68
    }
69
70
    public function appendStream(StreamInterface $stream): void
71
    {
72
        $this->data[++$this->fetches] = \simdjson_resource($stream->getContents());
0 ignored issues
show
Bug introduced by
The function simdjson_resource was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

72
        $this->data[++$this->fetches] = /** @scrutinizer ignore-call */ \simdjson_resource($stream->getContents());
Loading history...
73
        $this->length += count(\simdjson_key_value($this->data[$this->fetches], 'result', true));
0 ignored issues
show
Bug introduced by
The function simdjson_key_value was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

73
        $this->length += count(/** @scrutinizer ignore-call */ \simdjson_key_value($this->data[$this->fetches], 'result', true));
Loading history...
74
    }
75
76
}
77