SRVData::__unserialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 6
rs 10
1
<?php
2
3
namespace RemotelyLiving\PHPDNS\Entities;
4
5
use function serialize;
6
use function unserialize;
7
8
final class SRVData extends DataAbstract implements \Stringable
9
{
10
    public function __construct(private int $priority, private int $weight, private int $port, private Hostname $target)
11
    {
12
    }
13
14
    public function __toString(): string
15
    {
16
        return "{$this->priority} {$this->weight} {$this->port} {$this->target}";
17
    }
18
19
    public function getPriority(): int
20
    {
21
        return $this->priority;
22
    }
23
24
    public function getWeight(): int
25
    {
26
        return $this->weight;
27
    }
28
29
    public function getPort(): int
30
    {
31
        return $this->port;
32
    }
33
34
    public function getTarget(): Hostname
35
    {
36
        return $this->target;
37
    }
38
39
    public function toArray(): array
40
    {
41
        return [
42
            'priority' => $this->priority,
43
            'weight'  => $this->weight,
44
            'port'    => $this->port,
45
            'target' => (string)$this->target,
46
        ];
47
    }
48
49
    public function __unserialize(array $unserialized): void
50
    {
51
        $this->priority = $unserialized['priority'];
52
        $this->weight = $unserialized['weight'];
53
        $this->port = $unserialized['port'];
54
        $this->target = new Hostname($unserialized['target']);
55
    }
56
}
57