Conditions | 1 |
Paths | 1 |
Total Lines | 120 |
Code Lines | 72 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
29 | public function __construct($overwrites = []) |
||
30 | { |
||
31 | /** @var Rfc2234 $abnf */ |
||
32 | /** @noinspection PhpUndefinedMethodInspection */ |
||
33 | $abnf = new Rfc2234(); |
||
34 | |||
35 | // Defined out-of-order for performance reasons |
||
36 | $rules = [ |
||
37 | // 2.1. Percent-Encoding |
||
38 | 'pct_encoded' => s("%", $abnf->HEXDIG, $abnf->HEXDIG), |
||
39 | |||
40 | // 2.2. Reserved Characters |
||
41 | 'sub_delims' => set('!$&\'()*+,;='), |
||
42 | 'gen_delims' => set(':/?#[]@'), |
||
43 | 'reserved' => c($this->gen_delims, $this->sub_delims), |
||
|
|||
44 | |||
45 | // 2.3. Unreserved Characters |
||
46 | 'unreserved' => c($abnf->ALPHA, $abnf->DIGIT, set('-._~')), |
||
47 | |||
48 | // 3.3. Path |
||
49 | 'pchar' => c($this->unreserved, $this->pct_encoded, $this->sub_delims, ':', '@'), |
||
50 | 'segment' => star($this->pchar), |
||
51 | 'segment_nz' => plus($this->pchar), |
||
52 | 'segment_nz_nc' => plus(c($this->unreserved, $this->pct_encoded, $this->sub_delims, '@')), |
||
53 | 'path_abempty' => star(['/', $this->segment]), |
||
54 | 'path_absolute' => s('/', opt([$this->segment_nz, star(['/', $this->segment])])), |
||
55 | 'path_noscheme' => s($this->segment_nz_nc, star(['/', $this->segment])), |
||
56 | 'path_rootless' => s($this->segment_nz, star(['/', $this->segment])), |
||
57 | 'path_empty' => new Nothing(), |
||
58 | 'path' => c($this->path_abempty, |
||
59 | $this->path_absolute, |
||
60 | $this->path_noscheme, |
||
61 | $this->path_rootless, |
||
62 | $this->path_empty |
||
63 | ), |
||
64 | |||
65 | // 3.4. Query |
||
66 | 'query' => star(c($this->pchar, '/', '?')), |
||
67 | |||
68 | // 3.5. Fragment |
||
69 | 'fragment ' => star(c($this->pchar, '/', '?')), |
||
70 | |||
71 | // 3. Syntax Components |
||
72 | 'hier_part' => s('//', $this->authority, [ |
||
73 | $this->path_abempty, |
||
74 | $this->path_absolute, |
||
75 | $this->path_rootless, |
||
76 | $this->path_empty, |
||
77 | ]), |
||
78 | 'URI' => s($this->scheme, ':', $this->hier_part, opt(['?', $this->query]), |
||
79 | opt(['#', $this->fragment])), |
||
80 | |||
81 | // 3.1. Scheme |
||
82 | 'scheme' => s($abnf->ALPHA, star(c($abnf->ALPHA, $abnf->DIGIT, '+', '-', '.'))), |
||
83 | |||
84 | // 3.2. Authority |
||
85 | 'authority' => s(opt([$this->userinfo, '@']), $this->host, opt([':', $this->port])), |
||
86 | |||
87 | // 3.2.1. User Information |
||
88 | 'userinfo' => star(c($this->unreserved, $this->pct_encoded, $this->sub_delims, ':')), |
||
89 | |||
90 | // 3.2.3. Port |
||
91 | 'port' => star($abnf->DIGIT), |
||
92 | |||
93 | // 3.2.2. Host |
||
94 | 'h16' => repeat(1, 4, $abnf->HEXDIG), |
||
95 | 'ls32' => c([$this->h16, ':', $this->h16], $this->IPv4address), |
||
96 | 'IPv6address' => c( |
||
97 | [repeat(6, 6, [$this->h16, ':']), $this->ls32], |
||
98 | ['::', repeat(5, 5, [$this->h16, ':']), $this->ls32], |
||
99 | [opt($this->h16), '::', repeat(4, 4, [$this->h16, ':']), $this->ls32], |
||
100 | [ |
||
101 | opt([repeat(0, 1, [$this->h16, ':',]), $this->h16]), |
||
102 | '::', |
||
103 | repeat(3, 3, [$this->h16, ':']), |
||
104 | $this->ls32 |
||
105 | ], |
||
106 | [ |
||
107 | opt([repeat(0, 2, [$this->h16, ':',]), $this->h16]), |
||
108 | '::', |
||
109 | repeat(2, 2, [$this->h16, ':']), |
||
110 | $this->ls32 |
||
111 | ], |
||
112 | [opt([repeat(0, 3, [$this->h16, ':',]), $this->h16]), '::', $this->h16, ':', $this->ls32], |
||
113 | [opt([repeat(0, 4, [$this->h16, ':',]), $this->h16]), '::', $this->ls32], |
||
114 | [opt([repeat(0, 5, [$this->h16, ':',]), $this->h16]), '::', $this->h16], |
||
115 | [opt([repeat(0, 6, [$this->h16, ':',]), $this->h16]), '::'] |
||
116 | ), |
||
117 | 'dec_octet' => c( |
||
118 | ['25', range('0', '5')], // 250-255 |
||
119 | ['2', range('0', '4'), $abnf->DIGIT], // 200-249 |
||
120 | ['1', repeat(2, 2, $abnf->DIGIT)], // 100-199 |
||
121 | [range('1', '9'), $abnf->DIGIT], // 10-99 |
||
122 | $abnf->DIGIT // 0-9 |
||
123 | ), |
||
124 | 'IPv4address' => s($this->dec_octet, '.', $this->dec_octet, '.', $this->dec_octet, '.', $this->dec_octet), |
||
125 | 'IPvFuture' => s('v', plus($abnf->HEXDIG), '.', plus(c($this->unreserved, $this->sub_delims, ':'))), |
||
126 | 'IP_literal' => s('[', [$this->IPv6address, $this->IPvFuture], ']'), |
||
127 | 'reg_name' => star(c($this->unreserved, $this->pct_encoded, $this->sub_delims)), |
||
128 | 'host' => c($this->IP_literal, $this->IPv4address, $this->reg_name), |
||
129 | |||
130 | // 4.2. Relative Reference |
||
131 | 'relative_part' => s('//', $this->authority, [ |
||
132 | $this->path_abempty, |
||
133 | $this->path_absolute, |
||
134 | $this->path_noscheme, |
||
135 | $this->path_empty |
||
136 | ]), |
||
137 | 'relative_ref' => s($this->relative_part, opt(['?', $this->query]), opt(['#', $this->fragment])), |
||
138 | |||
139 | // 4.1. URI Reference |
||
140 | 'URI_reference' => c($this->URI, $this->relative_ref), |
||
141 | |||
142 | // 4.3. Absolute URI |
||
143 | 'absolute_URI' => s($this->scheme, ':', $this->hier_part, opt(['?', $this->query])), |
||
144 | |||
145 | // self::DEFAULT => $this->rulelist, |
||
146 | ]; |
||
147 | |||
148 | parent::__construct(array_merge($rules, $overwrites)); |
||
149 | } |
||
150 | } |