Ipv6   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 35
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getBuffer() 0 3 1
A getHost() 0 3 1
A __construct() 0 7 2
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