Completed
Branch master (f0bd78)
by Sam
04:24 queued 01:02
created

AAAA::fromWire()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.0116

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 3
dl 0
loc 11
ccs 6
cts 7
cp 0.8571
crap 2.0116
rs 10
c 0
b 0
f 0
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 24
    public function setAddress(string $address): void
30
    {
31 24
        if (!Validator::ipv6($address)) {
32
            throw new \InvalidArgumentException(sprintf('The address "%s" is not a valid IPv6 address.', $address));
33
        }
34
35 24
        $this->address = $address;
36 24
    }
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
            throw new DecodeException(static::TYPE, $rdata);
47
        }
48 2
        $offset += 16;
49
50 2
        $a = new static();
51 2
        $a->setAddress($address);
52
53 2
        return $a;
54
    }
55
}
56