Passed
Push — master ( 87c83f...ac88b3 )
by Sam
03:00
created

AAAA   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 33
ccs 12
cts 12
cp 1
rs 10
c 1
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromWire() 0 11 2
A setAddress() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Badcow DNS Library.
7
 *
8
 * (c) Samuel Williams <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Badcow\DNS\Rdata;
15
16
use Badcow\DNS\Validator;
17
18
/**
19
 * @see https://tools.ietf.org/html/rfc3596#section-2.1
20
 */
21
class AAAA extends A
22
{
23
    const TYPE = 'AAAA';
24
    const TYPE_CODE = 28;
25
26
    /**
27
     * @param string $address
28
     */
29 25
    public function setAddress(string $address): void
30
    {
31 25
        if (!Validator::ipv6($address)) {
32 1
            throw new \InvalidArgumentException(sprintf('The address "%s" is not a valid IPv6 address.', $address));
33
        }
34
35 25
        $this->address = $address;
36 25
    }
37
38
    /**
39
     * {@inheritdoc}
40
     *
41
     * @throws DecodeException
42
     */
43 2
    public static function fromWire(string $rdata, int &$offset = 0, ?int $rdLength = null): RdataInterface
44
    {
45 2
        if (false === $address = @inet_ntop(substr($rdata, $offset, 16))) {
46 1
            throw new DecodeException(static::TYPE, $rdata);
47
        }
48 2
        $offset += 16;
49
50 2
        $a = new self();
51 2
        $a->setAddress($address);
52
53 2
        return $a;
54
    }
55
}
56