Rfc3986::__construct()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 119
Code Lines 72

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 72
CRAP Score 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 72
nc 1
nop 1
dl 0
loc 119
ccs 72
cts 72
cp 1
crap 1
rs 8.6109
c 1
b 1
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/** @noinspection PhpUndefinedFieldInspection */
4
5
/**
6
 * RFC 3986 - Uniform Resource Identifier (URI): Generic Syntax.
7
 *
8
 * @see https://tools.ietf.org/html/rfc3986
9
 */
10
11
namespace Vanderlee\Comprehend\Library;
12
13
use Vanderlee\Comprehend\Builder\AbstractRuleset;
14
use Vanderlee\Comprehend\Parser\Parser;
15
use Vanderlee\Comprehend\Parser\Terminal\Nothing;
16
17
require_once 'functions.php';
18
19
/**
20
 * @property-read Parser IPv6address
21
 * @property-read Parser IPv4address
22
 * @property-read Parser sub_delims
23
 */
24
class Rfc3986 extends AbstractRuleset
25
{
26
    protected static $name = 'Rfc3986';
27
28 4
    public function __construct($overwrites = [])
29
    {
30
        /** @noinspection PhpUndefinedMethodInspection */
31 4
        $abnf = new Rfc2234();
32
33
        // Defined out-of-order for performance reasons
34
        $rules = [
35
            // 2.1.  Percent-Encoding
36 4
            'pct_encoded' => s('%', $abnf->HEXDIG, $abnf->HEXDIG),
37
38
            // 2.2.  Reserved Characters
39 4
            'sub_delims' => set('!$&\'()*+,;='),
40 4
            'gen_delims' => set(':/?#[]@'),
41 4
            'reserved' => c($this->gen_delims, $this->sub_delims),
0 ignored issues
show
Bug Best Practice introduced by
The property gen_delims does not exist on Vanderlee\Comprehend\Library\Rfc3986. Since you implemented __get, consider adding a @property annotation.
Loading history...
42
43
            // 2.3.  Unreserved Characters
44 4
            'unreserved' => c($abnf->ALPHA, $abnf->DIGIT, set('-._~')),
45
46
            // 3.3.  Path
47 4
            'pchar' => c($this->unreserved, $this->pct_encoded, $this->sub_delims, ':', '@'),
0 ignored issues
show
Bug Best Practice introduced by
The property pct_encoded does not exist on Vanderlee\Comprehend\Library\Rfc3986. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property unreserved does not exist on Vanderlee\Comprehend\Library\Rfc3986. Since you implemented __get, consider adding a @property annotation.
Loading history...
48 4
            'segment' => star($this->pchar),
0 ignored issues
show
Bug Best Practice introduced by
The property pchar does not exist on Vanderlee\Comprehend\Library\Rfc3986. Since you implemented __get, consider adding a @property annotation.
Loading history...
49 4
            'segment_nz' => plus($this->pchar),
50 4
            'segment_nz_nc' => plus(c($this->unreserved, $this->pct_encoded, $this->sub_delims, '@')),
51 4
            'path_abempty' => star(['/', $this->segment]),
0 ignored issues
show
Bug Best Practice introduced by
The property segment does not exist on Vanderlee\Comprehend\Library\Rfc3986. Since you implemented __get, consider adding a @property annotation.
Loading history...
52 4
            'path_absolute' => s('/', opt([$this->segment_nz, star(['/', $this->segment])])),
0 ignored issues
show
Bug Best Practice introduced by
The property segment_nz does not exist on Vanderlee\Comprehend\Library\Rfc3986. Since you implemented __get, consider adding a @property annotation.
Loading history...
53 4
            'path_noscheme' => s($this->segment_nz_nc, star(['/', $this->segment])),
0 ignored issues
show
Bug Best Practice introduced by
The property segment_nz_nc does not exist on Vanderlee\Comprehend\Library\Rfc3986. Since you implemented __get, consider adding a @property annotation.
Loading history...
54 4
            'path_rootless' => s($this->segment_nz, star(['/', $this->segment])),
55 4
            'path_empty' => new Nothing(),
56 4
            'path' => c($this->path_abempty,
0 ignored issues
show
Bug Best Practice introduced by
The property path_abempty does not exist on Vanderlee\Comprehend\Library\Rfc3986. Since you implemented __get, consider adding a @property annotation.
Loading history...
57 4
                $this->path_absolute,
0 ignored issues
show
Bug Best Practice introduced by
The property path_absolute does not exist on Vanderlee\Comprehend\Library\Rfc3986. Since you implemented __get, consider adding a @property annotation.
Loading history...
58 4
                $this->path_noscheme,
0 ignored issues
show
Bug Best Practice introduced by
The property path_noscheme does not exist on Vanderlee\Comprehend\Library\Rfc3986. Since you implemented __get, consider adding a @property annotation.
Loading history...
59 4
                $this->path_rootless,
0 ignored issues
show
Bug Best Practice introduced by
The property path_rootless does not exist on Vanderlee\Comprehend\Library\Rfc3986. Since you implemented __get, consider adding a @property annotation.
Loading history...
60 4
                $this->path_empty
0 ignored issues
show
Bug Best Practice introduced by
The property path_empty does not exist on Vanderlee\Comprehend\Library\Rfc3986. Since you implemented __get, consider adding a @property annotation.
Loading history...
61
            ),
62
63
            // 3.4.  Query
64 4
            'query' => star(c($this->pchar, '/', '?')),
65
66
            // 3.5.  Fragment
67 4
            'fragment    ' => star(c($this->pchar, '/', '?')),
68
69
            // 3.  Syntax Components
70 4
            'hier_part' => s('//', $this->authority, [
0 ignored issues
show
Bug Best Practice introduced by
The property authority does not exist on Vanderlee\Comprehend\Library\Rfc3986. Since you implemented __get, consider adding a @property annotation.
Loading history...
71 4
                $this->path_abempty,
72 4
                $this->path_absolute,
73 4
                $this->path_rootless,
74 4
                $this->path_empty,
75
            ]),
76 4
            'URI' => s($this->scheme, ':', $this->hier_part, opt(['?', $this->query]),
0 ignored issues
show
Bug Best Practice introduced by
The property query does not exist on Vanderlee\Comprehend\Library\Rfc3986. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property hier_part does not exist on Vanderlee\Comprehend\Library\Rfc3986. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property scheme does not exist on Vanderlee\Comprehend\Library\Rfc3986. Since you implemented __get, consider adding a @property annotation.
Loading history...
77 4
                opt(['#', $this->fragment])),
0 ignored issues
show
Bug Best Practice introduced by
The property fragment does not exist on Vanderlee\Comprehend\Library\Rfc3986. Since you implemented __get, consider adding a @property annotation.
Loading history...
78
79
            // 3.1.  Scheme
80 4
            'scheme' => s($abnf->ALPHA, star(c($abnf->ALPHA, $abnf->DIGIT, '+', '-', '.'))),
81
82
            // 3.2.  Authority
83 4
            'authority' => s(opt([$this->userinfo, '@']), $this->host, opt([':', $this->port])),
0 ignored issues
show
Bug Best Practice introduced by
The property host does not exist on Vanderlee\Comprehend\Library\Rfc3986. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property port does not exist on Vanderlee\Comprehend\Library\Rfc3986. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property userinfo does not exist on Vanderlee\Comprehend\Library\Rfc3986. Since you implemented __get, consider adding a @property annotation.
Loading history...
84
85
            // 3.2.1.  User Information
86 4
            'userinfo' => star(c($this->unreserved, $this->pct_encoded, $this->sub_delims, ':')),
87
88
            // 3.2.3.  Port
89 4
            'port' => star($abnf->DIGIT),
90
91
            // 3.2.2.  Host
92 4
            'h16' => repeat(1, 4, $abnf->HEXDIG),
93 4
            'ls32' => c([$this->h16, ':', $this->h16], $this->IPv4address),
0 ignored issues
show
Bug Best Practice introduced by
The property h16 does not exist on Vanderlee\Comprehend\Library\Rfc3986. Since you implemented __get, consider adding a @property annotation.
Loading history...
94 4
            'IPv6address' => c(
95 4
                [repeat(6, 6, [$this->h16, ':']), $this->ls32],
0 ignored issues
show
Bug Best Practice introduced by
The property ls32 does not exist on Vanderlee\Comprehend\Library\Rfc3986. Since you implemented __get, consider adding a @property annotation.
Loading history...
96 4
                ['::', repeat(5, 5, [$this->h16, ':']), $this->ls32],
97 4
                [opt($this->h16), '::', repeat(4, 4, [$this->h16, ':']), $this->ls32],
98
                [
99 4
                    opt([repeat(0, 1, [$this->h16, ':']), $this->h16]),
100 4
                    '::',
101 4
                    repeat(3, 3, [$this->h16, ':']),
102 4
                    $this->ls32,
103
                ],
104
                [
105 4
                    opt([repeat(0, 2, [$this->h16, ':']), $this->h16]),
106 4
                    '::',
107 4
                    repeat(2, 2, [$this->h16, ':']),
108 4
                    $this->ls32,
109
                ],
110 4
                [opt([repeat(0, 3, [$this->h16, ':']), $this->h16]), '::', $this->h16, ':', $this->ls32],
111 4
                [opt([repeat(0, 4, [$this->h16, ':']), $this->h16]), '::', $this->ls32],
112 4
                [opt([repeat(0, 5, [$this->h16, ':']), $this->h16]), '::', $this->h16],
113 4
                [opt([repeat(0, 6, [$this->h16, ':']), $this->h16]), '::']
114
            ),
115 4
            'dec_octet' => c(
116 4
                ['25', range('0', '5')], // 250-255
117 4
                ['2', range('0', '4'), $abnf->DIGIT], // 200-249
118 4
                ['1', repeat(2, 2, $abnf->DIGIT)], // 100-199
119 4
                [range('1', '9'), $abnf->DIGIT], // 10-99
120 4
                $abnf->DIGIT   // 0-9
121
            ),
122 4
            'IPv4address' => s($this->dec_octet, '.', $this->dec_octet, '.', $this->dec_octet, '.', $this->dec_octet),
0 ignored issues
show
Bug Best Practice introduced by
The property dec_octet does not exist on Vanderlee\Comprehend\Library\Rfc3986. Since you implemented __get, consider adding a @property annotation.
Loading history...
123 4
            'IPvFuture' => s('v', plus($abnf->HEXDIG), '.', plus(c($this->unreserved, $this->sub_delims, ':'))),
124 4
            'IP_literal' => s('[', [$this->IPv6address, $this->IPvFuture], ']'),
0 ignored issues
show
Bug Best Practice introduced by
The property IPvFuture does not exist on Vanderlee\Comprehend\Library\Rfc3986. Since you implemented __get, consider adding a @property annotation.
Loading history...
125 4
            'reg_name' => star(c($this->unreserved, $this->pct_encoded, $this->sub_delims)),
126 4
            'host' => c($this->IP_literal, $this->IPv4address, $this->reg_name),
0 ignored issues
show
Bug Best Practice introduced by
The property IP_literal does not exist on Vanderlee\Comprehend\Library\Rfc3986. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property reg_name does not exist on Vanderlee\Comprehend\Library\Rfc3986. Since you implemented __get, consider adding a @property annotation.
Loading history...
127
128
            // 4.2.  Relative Reference
129 4
            'relative_part' => s('//', $this->authority, [
130 4
                $this->path_abempty,
131 4
                $this->path_absolute,
132 4
                $this->path_noscheme,
133 4
                $this->path_empty,
134
            ]),
135 4
            'relative_ref' => s($this->relative_part, opt(['?', $this->query]), opt(['#', $this->fragment])),
0 ignored issues
show
Bug Best Practice introduced by
The property relative_part does not exist on Vanderlee\Comprehend\Library\Rfc3986. Since you implemented __get, consider adding a @property annotation.
Loading history...
136
137
            // 4.1.  URI Reference
138 4
            'URI_reference' => c($this->URI, $this->relative_ref),
0 ignored issues
show
Bug Best Practice introduced by
The property URI does not exist on Vanderlee\Comprehend\Library\Rfc3986. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property relative_ref does not exist on Vanderlee\Comprehend\Library\Rfc3986. Since you implemented __get, consider adding a @property annotation.
Loading history...
139
140
            // 4.3.  Absolute URI
141 4
            'absolute_URI' => s($this->scheme, ':', $this->hier_part, opt(['?', $this->query])),
142
143
            //            self::ROOT => $this->rulelist,
144
        ];
145
146 4
        parent::__construct(array_merge($rules, $overwrites));
147 4
    }
148
}
149