Conditions | 16 |
Paths | 17 |
Total Lines | 53 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
69 | public function convert($path) |
||
70 | { |
||
71 | // Skip converting if the relative url like http://... or android-app://... etc. |
||
72 | if (preg_match('/[a-z0-9-]{1,}(:\/\/)/i', $path)) { |
||
73 | if(preg_match('/services:\/\//i', $path)) |
||
74 | return ''; |
||
75 | if(preg_match('/whatsapp:\/\//i', $path)) |
||
76 | return ''; |
||
77 | if(preg_match('/tel:/i', $path)) |
||
78 | return ''; |
||
79 | return $path; |
||
80 | } |
||
81 | // Treat path as invalid if it is like javascript:... etc. |
||
82 | if (preg_match('/^[a-zA-Z]{0,}:[^\/]{0,1}/i', $path)) { |
||
83 | return ''; |
||
84 | } |
||
85 | // Convert //www.google.com to http://www.google.com |
||
86 | if(substr($path, 0, 2) == '//') { |
||
87 | return 'http:' . $path; |
||
88 | } |
||
89 | // If the path is a fragment or query string, |
||
90 | // it will be appended to the base url |
||
91 | if(substr($path, 0, 1) == '#' || substr($path, 0, 1) == '?') { |
||
92 | return $this->getStarterPath() . $path; |
||
93 | } |
||
94 | // Treat paths with doc root, i.e, /about |
||
95 | if(substr($path, 0, 1) == '/') { |
||
96 | return $this->onlySitePath($this->getStarterPath()) . $path; |
||
97 | } |
||
98 | // For paths like ./foo, it will be appended to the furthest directory |
||
99 | if(substr($path, 0, 2) == './') { |
||
100 | return $this->uptoLastDir($this->getStarterPath()) . substr($path, 2); |
||
101 | } |
||
102 | // Convert paths like ../foo or ../../bar |
||
103 | if(substr($path, 0, 3) == '../') { |
||
104 | $rel = $path; |
||
105 | $base = $this->uptoLastDir($this->getStarterPath()); |
||
106 | while(substr($rel, 0, 3) == '../') { |
||
107 | $base = preg_replace('/\/([^\/]+\/)$/i', '/', $base); |
||
108 | $rel = substr($rel, 3); |
||
109 | } |
||
110 | if ($base === ($this->getScheme() . '://')) { |
||
111 | $base .= $this->getDomain(); |
||
112 | } elseif ($base===($this->getScheme(). ':/')) { |
||
113 | $base .= '/' . $this->getDomain(); |
||
114 | } |
||
115 | return $base . $rel; |
||
116 | } |
||
117 | if (empty($path)) { |
||
118 | return $this->getPagePath(); |
||
119 | } |
||
120 | // else |
||
121 | return $this->uptoLastDir($this->getStarterPath()) . $path; |
||
122 | } |
||
233 | } |