Conditions | 7 |
Paths | 32 |
Total Lines | 54 |
Code Lines | 21 |
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 |
||
37 | protected static function resolveRelativeUrlAfterEarlyChecks($base, $rel) |
||
38 | { |
||
39 | $re = array( |
||
40 | '#(/\.?/)#', |
||
41 | '#/(?!\.\.)[^/]+/\.\./#' |
||
42 | ); |
||
43 | |||
44 | /* fix url file for Windows */ |
||
45 | $base = preg_replace('#^file:\/\/([^/])#', 'file:///\1', $base); |
||
46 | |||
47 | /* |
||
48 | * parse base URL and convert to local variables: |
||
49 | * $scheme, $host, $path |
||
50 | */ |
||
51 | $parts = parse_url($base); |
||
52 | |||
53 | /* remove non-directory element from path */ |
||
54 | $path = isset($parts['path']) ? preg_replace('#/[^/]*$#', '', $parts["path"]) : ''; |
||
55 | |||
56 | /* destroy path if relative url points to root */ |
||
57 | if ($rel[0] === '/') { |
||
58 | $path = ''; |
||
59 | } |
||
60 | |||
61 | /* Build absolute URL */ |
||
62 | $abs = ''; |
||
63 | |||
64 | if (isset($parts["host"])) { |
||
65 | $abs .= $parts['host']; |
||
66 | } |
||
67 | |||
68 | if (isset($parts["port"])) { |
||
69 | $abs .= ":".$parts["port"]; |
||
70 | } |
||
71 | |||
72 | $abs .= $path."/".$rel; |
||
73 | |||
74 | /* |
||
75 | * replace superfluous slashes with a single slash. |
||
76 | * covers: |
||
77 | * // |
||
78 | * /./ |
||
79 | * /foo/../ |
||
80 | */ |
||
81 | $n = 1; |
||
82 | do { |
||
83 | $abs = preg_replace($re, '/', $abs, -1, $n); |
||
84 | } while ($n > 0); |
||
85 | |||
86 | if (isset($parts["scheme"])) { |
||
87 | $abs = $parts["scheme"].'://'.$abs; |
||
88 | } |
||
89 | |||
90 | return $abs; |
||
91 | } |
||
94 |