Passed
Push — master ( 1b2537...c847ff )
by Timon
05:27 queued 02:23
created

Response::isAtomic()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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