Completed
Push — master ( 04e24a...c0588a )
by Martijn
03:54 queued 38s
created

Rfc3513::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 1
dl 0
loc 21
ccs 7
cts 7
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php /** @noinspection PhpUndefinedFieldInspection */
2
3
/**
4
 * RFC 3513 - Internet Protocol Version 6 (IPv6) Addressing Architecture
5
 *
6
 * Obsoleted by RFC 4291
7
 * Obsoletes RFC 2373
8
 *
9
 * @see https://tools.ietf.org/html/rfc4408
10
 * @package Vanderlee\Comprehend\Library
11
 */
12
13
namespace Vanderlee\Comprehend\Library;
14
15
use Vanderlee\Comprehend\Builder\AbstractRuleset;
16
use Vanderlee\Comprehend\Parser\Parser;
17
use Vanderlee\Comprehend\Parser\Terminal\Integer;
18
19
require_once 'functions.php';
20
21
/**
22
 * IPv6 address
23
 * Supports formats:
24
 *  1234:0:0:0:0:0:200C:417A
25
 *  1234::200C:417A,
26
 *  1234:0:0:0:0:0:12.34.56.78
27
 *  1234::12.34.56.78
28
 *
29
 * @property-read Parser ipv6 IPv6 address with CIDR range
30
 * @property-read Parser ipv6_address IPv6 address without CIDR range
31
 *
32
 * @package Vanderlee\Comprehend\Library
33
 */
34
class Rfc3513 extends AbstractRuleset
35
{
36
    protected static $name = 'Rfc4408';
37
38 2
    public function __construct($overwrites = [])
39
    {
40
        /*
41
         * We'll use RFC3986 for the IPv6 definition for convenience sake.
42
         * This may not be 100% accurate, but RFC 3513's definition is sloppy at best.
43
         */
44 2
        $rfc3986 = new Rfc3986;
45
46
        /*
47
         * Normal rules
48
         */
49
        $rules = [
50
            // 2.3 Text Representation of Address Prefixes
51 2
            'ipv6'          => [$this->ipv6_address, '/', $this->prefix_length],
0 ignored issues
show
Bug Best Practice introduced by
The property prefix_length does not exist on Vanderlee\Comprehend\Library\Rfc3513. Since you implemented __get, consider adding a @property annotation.
Loading history...
52 2
            'ipv6_address'  => $rfc3986->IPv6address,
53 2
            'prefix_length' => new Integer(0, 128),
54
55 2
            self::ROOT => $this->ipv6,
56
        ];
57
58 2
        parent::__construct(array_merge($rules, $overwrites));
59
    }
60
}