Completed
Push — master ( 00a863...d2dd08 )
by thomas
50:05 queued 12:04
created

Ipv6::getHost()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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