Passed
Pull Request — master (#48)
by Christian
08:09
created

MXData   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 9
c 1
b 0
f 1
dl 0
loc 38
rs 10
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 3 1
A toArray() 0 5 1
A __unserialize() 0 4 1
A serialize() 0 3 1
A getTarget() 0 3 1
A getPriority() 0 3 1
A __construct() 0 2 1
1
<?php
2
3
namespace RemotelyLiving\PHPDNS\Entities;
4
5
use function serialize;
6
use function unserialize;
7
8
final class MXData extends DataAbstract implements \Stringable
9
{
10
    public function __construct(private Hostname $target, private int $priority = 0)
11
    {
12
    }
13
14
    public function __toString(): string
15
    {
16
        return "{$this->priority} {$this->target}";
17
    }
18
19
    public function getTarget(): Hostname
20
    {
21
        return $this->target;
22
    }
23
24
    public function getPriority(): int
25
    {
26
        return $this->priority;
27
    }
28
29
    public function toArray(): array
30
    {
31
        return [
32
            'target' => (string)$this->target,
33
            'priority' => $this->priority,
34
        ];
35
    }
36
37
    public function serialize(): string
38
    {
39
        return serialize($this->toArray());
40
    }
41
42
    public function __unserialize(array $unserialized): void
43
    {
44
        $this->target = new Hostname($unserialized['target']);
45
        $this->priority = $unserialized['priority'];
46
    }
47
}
48