AAAA   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 27
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setAddress() 0 8 2
A fromWire() 0 9 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