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

Ipv6   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 37
wmc 4
lcom 1
cbo 1
rs 10

3 Methods

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