HeaderBag::isQuery()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Thruster\Component\Dns;
4
5
/**
6
 * Class HeaderBag
7
 *
8
 * @package Thruster\Component\Dns
9
 * @author  Aurimas Niekis <[email protected]>
10
 */
11
class HeaderBag
12
{
13
    /**
14
     * @var string
15
     */
16
    private $data;
17
18
    /**
19
     * @var array
20
     */
21
    private $attributes;
22
23
    public function __construct()
24
    {
25
        $this->data = '';
26
        $this->attributes = [
27
            'qdCount'   => 0,
28
            'anCount'   => 0,
29
            'nsCount'   => 0,
30
            'arCount'   => 0,
31
            'qr'        => 0,
32
            'opcode'    => Message::OPCODE_QUERY,
33
            'aa'        => 0,
34
            'tc'        => 0,
35
            'rd'        => 0,
36
            'ra'        => 0,
37
            'z'         => 0,
38
            'rcode'     => Message::RCODE_OK,
39
        ];
40
    }
41
42
    public function get($name)
43
    {
44
        return $this->attributes[$name] ?? null;
45
    }
46
47
    public function set($name, $value) : self
48
    {
49
        $this->attributes[$name] = $value;
50
51
        return $this;
52
    }
53
54
    public function isQuery() : bool
55
    {
56
        return 0 === $this->attributes['qr'];
57
    }
58
59
    public function isResponse() : bool
60
    {
61
        return 1 === $this->attributes['qr'];
62
    }
63
64
    public function isTruncated() : bool
65
    {
66
        return 1 === $this->attributes['tc'];
67
    }
68
69
    public function populateCounts(Message $message)
70
    {
71
        $this->attributes['qdCount'] = count($message->questions);
72
        $this->attributes['anCount'] = count($message->answers);
73
        $this->attributes['nsCount'] = count($message->authority);
74
        $this->attributes['arCount'] = count($message->additional);
75
    }
76
}
77