Response::isAtomic()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 1
cts 1
cp 1
rs 10
c 0
b 0
f 0
cc 3
eloc 1
nc 3
nop 0
crap 3
1
<?php
2
declare(strict_types = 1);
3
4
namespace TBolier\RethinkQL\Response;
5
6
use TBolier\RethinkQL\Types\Frame\FrameType;
7
use TBolier\RethinkQL\Types\Query\QueryType;
8
9
class Response implements ResponseInterface
10
{
11
    /**
12
     * @var array|null
13
     */
14
    private $backtrace;
15
    /**
16
     * @var array|null
17
     */
18
    private $data;
19
    /**
20
     * @var array|null
21
     */
22
    private $note;
23
    /**
24
     * @var array|null
25
     */
26
    private $profile;
27
    /**
28
     * @var int
29
     */
30
    private $type;
31
32
    public function __construct(int $t = null, array $r = null, array $b = null, array $p = null, array $n = null)
33
    {
34
        !$t ?: $this->type = $t;
35
        !$r ?: $this->data = $r;
36 17
        !$b ?: $this->backtrace = $b;
37
        !$p ?: $this->profile = $p;
38 17
        !$n ?: $this->note = $n;
39 17
    }
40 17
41 17
    public function getType(): ?int
42 17
    {
43 17
        return $this->type;
44
    }
45
46
    public function getData()
47
    {
48 17
        if (!\is_array($this->data)) {
49
            return null;
50 17
        }
51
52
        if (isset($this->data[0]['$reql_type$']) && $this->data[0]['$reql_type$'] === 'GROUPED_DATA') {
53
            $groups = [];
54
            foreach ($this->data[0]['data'] as $group) {
55
                $groups[] = [
56 17
                    'group' => $group[0],
57
                    'reduction' => $group[1],
58 17
                ];
59
            }
60
61
            return $groups;
62 17
        }
63
64
        return \count($this->data) === 1 && array_key_exists(0, $this->data) ? $this->data[0] : $this->data;
65
    }
66
67
    public function isAtomic(): bool
68 1
    {
69
        return \is_string($this->data) || (!\is_null($this->data) && \count($this->data) === 1);
70 1
    }
71
72
    public function getBacktrace(): ?array
73
    {
74
        return $this->backtrace;
75
    }
76 1
77
    public function getProfile(): ?array
78 1
    {
79
        return $this->profile;
80
    }
81
82
    public function getNote(): ?array
83
    {
84 1
        return $this->note;
85
    }
86
}
87