Passed
Pull Request — master (#34)
by Marc
05:44
created

Response   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Test Coverage

Coverage 95.24%

Importance

Changes 0
Metric Value
wmc 16
dl 0
loc 89
ccs 20
cts 21
cp 0.9524
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getData() 0 7 4
A getNote() 0 3 1
B __construct() 0 7 6
A getProfile() 0 3 1
A getBacktrace() 0 3 1
A getType() 0 3 1
A isAtomic() 0 3 2
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 17
    public function __construct(int $t = null, array $r = null, array $b = null, array $p = null, array $n = null)
37
    {
38 17
        !$t ?: $this->type = $t;
39 17
        !$r ?: $this->data = $r;
40 17
        !$b ?: $this->backtrace = $b;
41 17
        !$p ?: $this->profile = $p;
42 17
        !$n ?: $this->note = $n;
43 17
    }
44
45
    /**
46
     * @inheritdoc
47
     */
48 17
    public function getType(): ?int
49
    {
50 17
        return $this->type;
51
    }
52
53
    /**
54
     * @inheritdoc
55
     */
56 17
    public function getData()
57
    {
58 17
        if (!\is_array($this->data)) {
59
            return null;
60
        }
61
62 17
        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 \is_string($this->data) || \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