Conditions | 1 |
Paths | 1 |
Total Lines | 65 |
Code Lines | 46 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 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 |
||
156 | private static function buildPatterns() |
||
157 | { |
||
158 | $alpha = 'A-Za-z'; |
||
159 | $digit = '0-9'; |
||
160 | $hex = $digit . 'A-Fa-f'; |
||
161 | $unreserved = "$alpha$digit\\-._~"; |
||
162 | $delimiters = "!$&'()*+,;="; |
||
163 | $utf8 = '\\x80-\\xFF'; |
||
164 | |||
165 | $octet = "(?:[$digit]|[1-9][$digit]|1[$digit]{2}|2[0-4]$digit|25[0-5])"; |
||
166 | $ipv4address = "(?>$octet\\.$octet\\.$octet\\.$octet)"; |
||
167 | |||
168 | $encoded = "%[$hex]{2}"; |
||
169 | $h16 = "[$hex]{1,4}"; |
||
170 | $ls32 = "(?:$h16:$h16|$ipv4address)"; |
||
171 | |||
172 | $data = "[$unreserved$delimiters:@$utf8]++|$encoded"; |
||
173 | |||
174 | // Defining the scheme |
||
175 | $scheme = "(?'scheme'(?>[$alpha][$alpha$digit+\\-.]*+))"; |
||
176 | |||
177 | // Defining the authority |
||
178 | $ipv6address = "(?'IPv6address'" . |
||
179 | "(?:(?:$h16:){6}$ls32)|" . |
||
180 | "(?:::(?:$h16:){5}$ls32)|" . |
||
181 | "(?:(?:$h16)?::(?:$h16:){4}$ls32)|" . |
||
182 | "(?:(?:(?:$h16:){0,1}$h16)?::(?:$h16:){3}$ls32)|" . |
||
183 | "(?:(?:(?:$h16:){0,2}$h16)?::(?:$h16:){2}$ls32)|" . |
||
184 | "(?:(?:(?:$h16:){0,3}$h16)?::$h16:$ls32)|" . |
||
185 | "(?:(?:(?:$h16:){0,4}$h16)?::$ls32)|" . |
||
186 | "(?:(?:(?:$h16:){0,5}$h16)?::$h16)|" . |
||
187 | "(?:(?:(?:$h16:){0,6}$h16)?::))"; |
||
188 | |||
189 | $regularName = "(?'reg_name'(?>(?:[$unreserved$delimiters$utf8]++|$encoded)*))"; |
||
190 | |||
191 | $ipvFuture = "(?'IPvFuture'v[$hex]++\\.[$unreserved$delimiters:]++)"; |
||
192 | $ipLiteral = "(?'IP_literal'\\[(?>$ipv6address|$ipvFuture)\\])"; |
||
193 | |||
194 | $port = "(?'port'(?>[$digit]*+))"; |
||
195 | $host = "(?'host'$ipLiteral|(?'IPv4address'$ipv4address)|$regularName)"; |
||
196 | $userInfo = "(?'userinfo'(?>(?:[$unreserved$delimiters:$utf8]++|$encoded)*))"; |
||
197 | $authority = "(?'authority'(?:$userInfo@)?$host(?::$port)?)"; |
||
198 | |||
199 | // Defining the path |
||
200 | $segment = "(?>(?:$data)*)"; |
||
201 | $segmentNotEmpty = "(?>(?:$data)+)"; |
||
202 | $segmentNoScheme = "(?>([$unreserved$delimiters@$utf8]++|$encoded)+)"; |
||
203 | |||
204 | $pathAbsoluteEmpty = "(?'path_abempty'(?:/$segment)*)"; |
||
205 | $pathAbsolute = "(?'path_absolute'/(?:$segmentNotEmpty(?:/$segment)*)?)"; |
||
206 | $pathNoScheme = "(?'path_noscheme'$segmentNoScheme(?:/$segment)*)"; |
||
207 | $pathRootless = "(?'path_rootless'$segmentNotEmpty(?:/$segment)*)"; |
||
208 | $pathEmpty = "(?'path_empty')"; |
||
209 | |||
210 | // Defining other parts |
||
211 | $query = "(?'query'(?>(?:$data|[/?])*))"; |
||
212 | $fragment = "(?'fragment'(?>(?:$data|[/?])*))"; |
||
213 | |||
214 | $absolutePath = "(?'hier_part'//$authority$pathAbsoluteEmpty|$pathAbsolute|$pathRootless|$pathEmpty)"; |
||
215 | $relativePath = "(?'relative_part'//$authority$pathAbsoluteEmpty|$pathAbsolute|$pathNoScheme|$pathEmpty)"; |
||
216 | |||
217 | self::$absoluteUri = "#^$scheme:$absolutePath(?:\\?$query)?(?:\\#$fragment)?$#"; |
||
218 | self::$relativeUri = "#^$relativePath(?:\\?$query)?(?:\\#$fragment)?$#"; |
||
219 | self::$scheme = "#^$scheme$#"; |
||
220 | self::$host = "#^$host$#"; |
||
221 | } |
||
223 |