AAAA::fromWire()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 3
crap 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 28
    public function setAddress(string $address): void
27
    {
28 28
        if (!Validator::ipv6($address)) {
29 1
            throw new \InvalidArgumentException(sprintf('The address "%s" is not a valid IPv6 address.', $address));
30
        }
31
32 28
        $this->address = $address;
33 28
    }
34
35
    /**
36
     * @throws DecodeException
37
     */
38 2
    public function fromWire(string $rdata, int &$offset = 0, ?int $rdLength = null): void
39
    {
40 2
        if (false === $address = @inet_ntop(substr($rdata, $offset, 16))) {
41 1
            throw new DecodeException(static::TYPE, $rdata);
42
        }
43 2
        $offset += 16;
44
45 2
        $this->setAddress($address);
46 2
    }
47
}
48