Passed
Pull Request — master (#7)
by Sandro
02:05
created

ArrayStreamHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 12
dl 0
loc 30
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A appendStream() 0 4 1
A completeResult() 0 8 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
use ArangoDb\Util\Json;
15
use Psr\Http\Message\StreamInterface;
16
17
class ArrayStreamHandler implements StreamHandler
18
{
19
    use ArrayAccessStreamHandlerTrait;
20
21
    /**
22
     * @var mixed
23
     */
24
    private $data = [];
25
26 7
    public function __construct(StreamInterface $stream)
27
    {
28 7
        $this->data[$this->fetches] = Json::decode($stream->getContents());
29 7
        $this->length = count($this->data[$this->fetches]['result']);
30 7
        $this->batchSize = $this->length;
31 7
    }
32
33 4
    public function completeResult()
34
    {
35 4
        $completeResult = [[]];
36
37 4
        foreach ($this->data as $result) {
38 4
            $completeResult[] = $result['result'];
39
        }
40 4
        return array_merge(...$completeResult);
41
    }
42
43 4
    public function appendStream(StreamInterface $stream): void
44
    {
45 4
        $this->data[++$this->fetches] = Json::decode($stream->getContents());
46 4
        $this->length += count($this->data[$this->fetches]['result']);
47 4
    }
48
}
49