Passed
Pull Request — master (#62)
by Eugene
12:23 queued 08:14
created

SqlQueryResult::__get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
/**
4
 * This file is part of the Tarantool Client package.
5
 *
6
 * (c) Eugene Leonovich <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Tarantool\Client;
15
16
final class SqlQueryResult implements \IteratorAggregate, \Countable
17
{
18
    private $data;
19
    private $metadata;
20
    private $keys;
21
22 28
    public function __construct(array $data, array $metadata)
23
    {
24 28
        $this->data = $data;
25 28
        $this->metadata = $metadata;
26 28
        $this->keys = ([] === $metadata) ? [] : \array_column($metadata, 0);
27 28
    }
28
29 10
    public function getData() : array
30
    {
31 10
        return $this->data;
32
    }
33
34 4
    public function getMetadata() : array
35
    {
36 4
        return $this->metadata;
37
    }
38
39 4
    public function isEmpty() : bool
40
    {
41 4
        return [] === $this->data;
42
    }
43
44 4
    public function getFirst() : ?array
45
    {
46 4
        return $this->data ? \array_combine($this->keys, \reset($this->data)) : null;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->data ? arr...et($this->data)) : null could return the type false which is incompatible with the type-hinted return array|null. Consider adding an additional type-check to rule them out.
Loading history...
47
    }
48
49 4
    public function getLast() : ?array
50
    {
51 4
        return $this->data ? \array_combine($this->keys, \end($this->data)) : null;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->data ? arr...nd($this->data)) : null could return the type false which is incompatible with the type-hinted return array|null. Consider adding an additional type-check to rule them out.
Loading history...
52
    }
53
54 2
    public function getIterator() : \Generator
55
    {
56 2
        foreach ($this->data as $item) {
57 2
            yield \array_combine($this->keys, $item);
58
        }
59 2
    }
60
61 2
    public function count() : int
62
    {
63 2
        return \count($this->data);
64
    }
65
}
66