@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | /** @var string|null */ |
38 | 38 | private $baseTag = null; |
39 | 39 | /** @var string|null */ |
40 | - private $starterPath=null; |
|
40 | + private $starterPath = null; |
|
41 | 41 | /** |
42 | 42 | * @var array|false|int|string|null |
43 | 43 | */ |
@@ -56,9 +56,9 @@ discard block |
||
56 | 56 | * ConvertToAbsolutePath constructor. |
57 | 57 | * @param $pagePath |
58 | 58 | */ |
59 | - public function __construct($pagePath=NULL) |
|
59 | + public function __construct($pagePath = NULL) |
|
60 | 60 | { |
61 | - if(isset($pagePath)) { |
|
61 | + if (isset($pagePath)) { |
|
62 | 62 | $this->setPagePath($pagePath); |
63 | 63 | } |
64 | 64 | } |
@@ -77,24 +77,24 @@ discard block |
||
77 | 77 | return ''; |
78 | 78 | } |
79 | 79 | // Convert //www.google.com to http://www.google.com |
80 | - if(substr($path, 0, 2) == '//') { |
|
80 | + if (substr($path, 0, 2) == '//') { |
|
81 | 81 | return 'http:' . $path; |
82 | 82 | } |
83 | 83 | // If the path is a fragment or query string, |
84 | 84 | // it will be appended to the base url |
85 | - if($this->isHaveQueryOrFragment($path)) { |
|
85 | + if ($this->isHaveQueryOrFragment($path)) { |
|
86 | 86 | return $this->getStarterPath() . $path; |
87 | 87 | } |
88 | 88 | // Treat paths with doc root, i.e, /about |
89 | - if(substr($path, 0, 1) == '/') { |
|
89 | + if (substr($path, 0, 1) == '/') { |
|
90 | 90 | return $this->onlySitePath($this->getStarterPath()) . $path; |
91 | 91 | } |
92 | 92 | // For paths like ./foo, it will be appended to the furthest directory |
93 | - if(substr($path, 0, 2) == './') { |
|
93 | + if (substr($path, 0, 2) == './') { |
|
94 | 94 | return $this->uptoLastDir($this->getStarterPath()) . substr($path, 2); |
95 | 95 | } |
96 | 96 | // Convert paths like ../foo or ../../bar |
97 | - if(substr($path, 0, 3) == '../') { |
|
97 | + if (substr($path, 0, 3) == '../') { |
|
98 | 98 | $removeTwoPointSlash = new RemovePathWithPointPointSlash($this, $path); |
99 | 99 | return $removeTwoPointSlash->compute(); |
100 | 100 | } |
@@ -111,9 +111,9 @@ discard block |
||
111 | 111 | $parseUrl = parse_url($url); |
112 | 112 | if ($this->isCorrectUrl($parseUrl)) { |
113 | 113 | return ''; |
114 | - }elseif(isset($parseUrl['scheme'])){ |
|
114 | + }elseif (isset($parseUrl['scheme'])) { |
|
115 | 115 | return $parseUrl['scheme'] . '://' . $parseUrl['host']; |
116 | - } else { |
|
116 | + }else { |
|
117 | 117 | return $parseUrl['host']; |
118 | 118 | } |
119 | 119 | } |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | public function upToLastDir($url) { |
124 | 124 | $parseUrl = parse_url($url); |
125 | 125 | $path = ''; |
126 | - if(isset($parseUrl['path'])) |
|
126 | + if (isset($parseUrl['path'])) |
|
127 | 127 | $path = preg_replace('/\/([^\/]+)$/i', '', $parseUrl['path']); |
128 | 128 | return rtrim($parseUrl['scheme'] . '://' . $parseUrl['host'] . $path, '/') . '/'; |
129 | 129 | } |
@@ -161,12 +161,12 @@ discard block |
||
161 | 161 | */ |
162 | 162 | public function getStarterPath(): string |
163 | 163 | { |
164 | - if($this->starterPath===null){ |
|
165 | - if($this->getBaseTag() === null) { |
|
166 | - $this->starterPath =$this->getPagePath(); |
|
167 | - }elseif(array_key_exists('scheme', $this->getBaseTagParsing())){ |
|
168 | - $this->starterPath = $this->getBaseTag() ; |
|
169 | - }else{ |
|
164 | + if ($this->starterPath === null) { |
|
165 | + if ($this->getBaseTag() === null) { |
|
166 | + $this->starterPath = $this->getPagePath(); |
|
167 | + }elseif (array_key_exists('scheme', $this->getBaseTagParsing())) { |
|
168 | + $this->starterPath = $this->getBaseTag(); |
|
169 | + }else { |
|
170 | 170 | $this->starterPath = $this->getPagePathParsing()['scheme'] . '://' . $this->getPagePathParsing()['host'] . $this->getBaseTag(); |
171 | 171 | } |
172 | 172 | } |
@@ -176,11 +176,11 @@ discard block |
||
176 | 176 | public function getDomain() |
177 | 177 | { |
178 | 178 | if ($this->domain === null) { |
179 | - if($this->getBaseTag() === null) { |
|
179 | + if ($this->getBaseTag() === null) { |
|
180 | 180 | $this->domain = $this->getPagePathParsing()['host'] . '/'; |
181 | - }elseif(array_key_exists('scheme', $this->getBaseTagParsing())){ |
|
181 | + }elseif (array_key_exists('scheme', $this->getBaseTagParsing())) { |
|
182 | 182 | $this->domain = $this->getBaseTagParsing()['host'] . '/'; |
183 | - }else{ |
|
183 | + }else { |
|
184 | 184 | $this->domain = $this->getPagePathParsing()['host'] . '/'; |
185 | 185 | } |
186 | 186 | } |
@@ -190,11 +190,11 @@ discard block |
||
190 | 190 | public function getScheme() |
191 | 191 | { |
192 | 192 | if ($this->scheme === null) { |
193 | - if($this->getBaseTag() === null) { |
|
193 | + if ($this->getBaseTag() === null) { |
|
194 | 194 | $this->scheme = $this->getPagePathParsing()['scheme']; |
195 | - }elseif(array_key_exists('scheme', $this->getBaseTagParsing())){ |
|
195 | + }elseif (array_key_exists('scheme', $this->getBaseTagParsing())) { |
|
196 | 196 | $this->scheme = $this->getBaseTagParsing()['scheme']; |
197 | - }else{ |
|
197 | + }else { |
|
198 | 198 | $this->scheme = $this->getPagePathParsing()['scheme']; |
199 | 199 | } |
200 | 200 | } |
@@ -203,14 +203,14 @@ discard block |
||
203 | 203 | |
204 | 204 | public function getBaseTagParsing() |
205 | 205 | { |
206 | - if($this->baseTagParsing == null) |
|
206 | + if ($this->baseTagParsing == null) |
|
207 | 207 | $this->baseTagParsing = parse_url($this->getBaseTag()); |
208 | 208 | return $this->baseTagParsing; |
209 | 209 | } |
210 | 210 | |
211 | 211 | public function getPagePathParsing() |
212 | 212 | { |
213 | - if($this->pagePathParsing == null) |
|
213 | + if ($this->pagePathParsing == null) |
|
214 | 214 | $this->pagePathParsing = parse_url($this->getPagePath()); |
215 | 215 | return $this->pagePathParsing; |
216 | 216 | } |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | $parseUrl = parse_url($url); |
112 | 112 | if ($this->isCorrectUrl($parseUrl)) { |
113 | 113 | return ''; |
114 | - }elseif(isset($parseUrl['scheme'])){ |
|
114 | + } elseif(isset($parseUrl['scheme'])){ |
|
115 | 115 | return $parseUrl['scheme'] . '://' . $parseUrl['host']; |
116 | 116 | } else { |
117 | 117 | return $parseUrl['host']; |
@@ -123,8 +123,9 @@ discard block |
||
123 | 123 | public function upToLastDir($url) { |
124 | 124 | $parseUrl = parse_url($url); |
125 | 125 | $path = ''; |
126 | - if(isset($parseUrl['path'])) |
|
127 | - $path = preg_replace('/\/([^\/]+)$/i', '', $parseUrl['path']); |
|
126 | + if(isset($parseUrl['path'])) { |
|
127 | + $path = preg_replace('/\/([^\/]+)$/i', '', $parseUrl['path']); |
|
128 | + } |
|
128 | 129 | return rtrim($parseUrl['scheme'] . '://' . $parseUrl['host'] . $path, '/') . '/'; |
129 | 130 | } |
130 | 131 | |
@@ -164,9 +165,9 @@ discard block |
||
164 | 165 | if($this->starterPath===null){ |
165 | 166 | if($this->getBaseTag() === null) { |
166 | 167 | $this->starterPath =$this->getPagePath(); |
167 | - }elseif(array_key_exists('scheme', $this->getBaseTagParsing())){ |
|
168 | + } elseif(array_key_exists('scheme', $this->getBaseTagParsing())){ |
|
168 | 169 | $this->starterPath = $this->getBaseTag() ; |
169 | - }else{ |
|
170 | + } else{ |
|
170 | 171 | $this->starterPath = $this->getPagePathParsing()['scheme'] . '://' . $this->getPagePathParsing()['host'] . $this->getBaseTag(); |
171 | 172 | } |
172 | 173 | } |
@@ -178,9 +179,9 @@ discard block |
||
178 | 179 | if ($this->domain === null) { |
179 | 180 | if($this->getBaseTag() === null) { |
180 | 181 | $this->domain = $this->getPagePathParsing()['host'] . '/'; |
181 | - }elseif(array_key_exists('scheme', $this->getBaseTagParsing())){ |
|
182 | + } elseif(array_key_exists('scheme', $this->getBaseTagParsing())){ |
|
182 | 183 | $this->domain = $this->getBaseTagParsing()['host'] . '/'; |
183 | - }else{ |
|
184 | + } else{ |
|
184 | 185 | $this->domain = $this->getPagePathParsing()['host'] . '/'; |
185 | 186 | } |
186 | 187 | } |
@@ -192,9 +193,9 @@ discard block |
||
192 | 193 | if ($this->scheme === null) { |
193 | 194 | if($this->getBaseTag() === null) { |
194 | 195 | $this->scheme = $this->getPagePathParsing()['scheme']; |
195 | - }elseif(array_key_exists('scheme', $this->getBaseTagParsing())){ |
|
196 | + } elseif(array_key_exists('scheme', $this->getBaseTagParsing())){ |
|
196 | 197 | $this->scheme = $this->getBaseTagParsing()['scheme']; |
197 | - }else{ |
|
198 | + } else{ |
|
198 | 199 | $this->scheme = $this->getPagePathParsing()['scheme']; |
199 | 200 | } |
200 | 201 | } |
@@ -203,15 +204,17 @@ discard block |
||
203 | 204 | |
204 | 205 | public function getBaseTagParsing() |
205 | 206 | { |
206 | - if($this->baseTagParsing == null) |
|
207 | - $this->baseTagParsing = parse_url($this->getBaseTag()); |
|
207 | + if($this->baseTagParsing == null) { |
|
208 | + $this->baseTagParsing = parse_url($this->getBaseTag()); |
|
209 | + } |
|
208 | 210 | return $this->baseTagParsing; |
209 | 211 | } |
210 | 212 | |
211 | 213 | public function getPagePathParsing() |
212 | 214 | { |
213 | - if($this->pagePathParsing == null) |
|
214 | - $this->pagePathParsing = parse_url($this->getPagePath()); |
|
215 | + if($this->pagePathParsing == null) { |
|
216 | + $this->pagePathParsing = parse_url($this->getPagePath()); |
|
217 | + } |
|
215 | 218 | return $this->pagePathParsing; |
216 | 219 | } |
217 | 220 | |
@@ -239,12 +242,15 @@ discard block |
||
239 | 242 | */ |
240 | 243 | public function checkPathIsAbsoluteOrForAnotherApp($path): string |
241 | 244 | { |
242 | - if (preg_match('/services:\/\//i', $path)) |
|
243 | - return ''; |
|
244 | - if (preg_match('/whatsapp:\/\//i', $path)) |
|
245 | - return ''; |
|
246 | - if (preg_match('/tel:/i', $path)) |
|
247 | - return ''; |
|
245 | + if (preg_match('/services:\/\//i', $path)) { |
|
246 | + return ''; |
|
247 | + } |
|
248 | + if (preg_match('/whatsapp:\/\//i', $path)) { |
|
249 | + return ''; |
|
250 | + } |
|
251 | + if (preg_match('/tel:/i', $path)) { |
|
252 | + return ''; |
|
253 | + } |
|
248 | 254 | return $path; |
249 | 255 | } |
250 | 256 |