Ipv6::getHost()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BitWasp\Bitcoin\Networking\Ip;
6
7
use BitWasp\Buffertools\Buffer;
8
use BitWasp\Buffertools\BufferInterface;
9
10
class Ipv6 implements IpInterface
11
{
12
13
    /**
14
     * @var string
15
     */
16
    private $ip;
17
18
    /**
19
     * Ipv4 constructor.
20 11
     * @param string $ip
21
     */
22 11
    public function __construct(string $ip)
23 3
    {
24
        if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
25
            throw new \InvalidArgumentException('IPv6: a valid IPv6 address is required');
26 8
        }
27 8
28
        $this->ip = $ip;
29
    }
30
31
    /**
32 6
     * @return string
33
     */
34 6
    public function getHost(): string
35
    {
36
        return $this->ip;
37
    }
38
39
    /**
40 6
     * @return BufferInterface
41
     */
42 6
    public function getBuffer(): BufferInterface
43
    {
44
        return new Buffer(inet_pton($this->ip));
45
    }
46
}
47