Passed
Push — master ( 526e5d...00c05c )
by Pouya
01:28
created
src/ConvertToAbsolutePath.php 2 patches
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
     }
@@ -70,11 +70,11 @@  discard block
 block discarded – undo
70 70
     {
71 71
         // Skip converting if the relative url like http://... or android-app://... etc.
72 72
         if (preg_match('/[a-z0-9-]{1,}(:\/\/)/i', $path)) {
73
-            if(preg_match('/services:\/\//i', $path))
73
+            if (preg_match('/services:\/\//i', $path))
74 74
                 return '';
75
-            if(preg_match('/whatsapp:\/\//i', $path))
75
+            if (preg_match('/whatsapp:\/\//i', $path))
76 76
                 return '';
77
-            if(preg_match('/tel:/i', $path))
77
+            if (preg_match('/tel:/i', $path))
78 78
                 return '';
79 79
             return $path;
80 80
         }
@@ -83,33 +83,33 @@  discard block
 block discarded – undo
83 83
             return '';
84 84
         }
85 85
         // Convert //www.google.com to http://www.google.com
86
-        if(substr($path, 0, 2) == '//') {
86
+        if (substr($path, 0, 2) == '//') {
87 87
             return 'http:' . $path;
88 88
         }
89 89
         // If the path is a fragment or query string,
90 90
         // it will be appended to the base url
91
-        if(substr($path, 0, 1) == '#' || substr($path, 0, 1) == '?') {
91
+        if (substr($path, 0, 1) == '#' || substr($path, 0, 1) == '?') {
92 92
             return $this->getStarterPath() . $path;
93 93
         }
94 94
         // Treat paths with doc root, i.e, /about
95
-        if(substr($path, 0, 1) == '/') {
95
+        if (substr($path, 0, 1) == '/') {
96 96
             return $this->onlySitePath($this->getStarterPath()) . $path;
97 97
         }
98 98
         // For paths like ./foo, it will be appended to the furthest directory
99
-        if(substr($path, 0, 2) == './') {
99
+        if (substr($path, 0, 2) == './') {
100 100
             return $this->uptoLastDir($this->getStarterPath()) . substr($path, 2);
101 101
         }
102 102
         // Convert paths like ../foo or ../../bar
103
-        if(substr($path, 0, 3) == '../') {
103
+        if (substr($path, 0, 3) == '../') {
104 104
             $rel = $path;
105 105
             $base = $this->uptoLastDir($this->getStarterPath());
106
-            while(substr($rel, 0, 3) == '../') {
106
+            while (substr($rel, 0, 3) == '../') {
107 107
                 $base = preg_replace('/\/([^\/]+\/)$/i', '/', $base);
108 108
                 $rel = substr($rel, 3);
109 109
             }
110 110
             if ($base === ($this->getScheme() . '://')) {
111 111
                 $base .= $this->getDomain();
112
-            } elseif ($base===($this->getScheme(). ':/')) {
112
+            } elseif ($base === ($this->getScheme() . ':/')) {
113 113
                 $base .= '/' . $this->getDomain();
114 114
             }
115 115
             return $base . $rel;
@@ -127,9 +127,9 @@  discard block
 block discarded – undo
127 127
         $parseUrl = parse_url($url);
128 128
         if (!isset($parseUrl['scheme']) AND !isset($parseUrl['host'])) {
129 129
             return '';
130
-        }elseif(isset($parseUrl['scheme'])){
130
+        }elseif (isset($parseUrl['scheme'])) {
131 131
             return $parseUrl['scheme'] . '://' . $parseUrl['host'];
132
-        } else {
132
+        }else {
133 133
             return $parseUrl['host'];
134 134
         }
135 135
     }
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
     public function upToLastDir($url) {
140 140
         $parseUrl = parse_url($url);
141 141
         $path = '';
142
-        if(isset($parseUrl['path']))
142
+        if (isset($parseUrl['path']))
143 143
             $path = preg_replace('/\/([^\/]+)$/i', '', $parseUrl['path']);
144 144
         return rtrim($parseUrl['scheme'] . '://' . $parseUrl['host'] . $path, '/') . '/';
145 145
     }
@@ -177,12 +177,12 @@  discard block
 block discarded – undo
177 177
      */
178 178
     private function getStarterPath(): string
179 179
     {
180
-        if($this->starterPath===null){
181
-            if($this->getBaseTag() === null) {
182
-                $this->starterPath =$this->getPagePath();
183
-            }elseif(array_key_exists('scheme', $this->getBaseTagParsing())){
184
-                $this->starterPath = $this->getBaseTag() ;
185
-            }else{
180
+        if ($this->starterPath === null) {
181
+            if ($this->getBaseTag() === null) {
182
+                $this->starterPath = $this->getPagePath();
183
+            }elseif (array_key_exists('scheme', $this->getBaseTagParsing())) {
184
+                $this->starterPath = $this->getBaseTag();
185
+            }else {
186 186
                 $this->starterPath = $this->getPagePathParsing()['scheme'] . '://' . $this->getPagePathParsing()['host'] . $this->getBaseTag();
187 187
             }
188 188
         }
@@ -192,11 +192,11 @@  discard block
 block discarded – undo
192 192
     private function getDomain()
193 193
     {
194 194
         if ($this->domain === null) {
195
-            if($this->getBaseTag() === null) {
195
+            if ($this->getBaseTag() === null) {
196 196
                 $this->domain = $this->getPagePathParsing()['host'] . '/';
197
-            }elseif(array_key_exists('scheme', $this->getBaseTagParsing())){
197
+            }elseif (array_key_exists('scheme', $this->getBaseTagParsing())) {
198 198
                 $this->domain = $this->getBaseTagParsing()['host'] . '/';
199
-            }else{
199
+            }else {
200 200
                 $this->domain = $this->getPagePathParsing()['host'] . '/';
201 201
             }
202 202
         }
@@ -206,11 +206,11 @@  discard block
 block discarded – undo
206 206
     private function getScheme()
207 207
     {
208 208
         if ($this->scheme === null) {
209
-            if($this->getBaseTag() === null) {
209
+            if ($this->getBaseTag() === null) {
210 210
                 $this->scheme = $this->getPagePathParsing()['scheme'];
211
-            }elseif(array_key_exists('scheme', $this->getBaseTagParsing())){
211
+            }elseif (array_key_exists('scheme', $this->getBaseTagParsing())) {
212 212
                 $this->scheme = $this->getBaseTagParsing()['scheme'];
213
-            }else{
213
+            }else {
214 214
                 $this->scheme = $this->getPagePathParsing()['scheme'];
215 215
             }
216 216
         }
@@ -219,14 +219,14 @@  discard block
 block discarded – undo
219 219
 
220 220
     private function getBaseTagParsing()
221 221
     {
222
-        if($this->baseTagParsing == null)
222
+        if ($this->baseTagParsing == null)
223 223
             $this->baseTagParsing = parse_url($this->getBaseTag());
224 224
         return $this->baseTagParsing;
225 225
     }
226 226
 
227 227
     private function getPagePathParsing()
228 228
     {
229
-        if($this->pagePathParsing == null)
229
+        if ($this->pagePathParsing == null)
230 230
             $this->pagePathParsing = parse_url($this->getPagePath());
231 231
         return $this->pagePathParsing;
232 232
     }
Please login to merge, or discard this patch.
Braces   +25 added lines, -19 removed lines patch added patch discarded remove patch
@@ -70,12 +70,15 @@  discard block
 block discarded – undo
70 70
     {
71 71
         // Skip converting if the relative url like http://... or android-app://... etc.
72 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 '';
73
+            if(preg_match('/services:\/\//i', $path)) {
74
+                            return '';
75
+            }
76
+            if(preg_match('/whatsapp:\/\//i', $path)) {
77
+                            return '';
78
+            }
79
+            if(preg_match('/tel:/i', $path)) {
80
+                            return '';
81
+            }
79 82
             return $path;
80 83
         }
81 84
         // Treat path as invalid if it is like javascript:... etc.
@@ -127,7 +130,7 @@  discard block
 block discarded – undo
127 130
         $parseUrl = parse_url($url);
128 131
         if (!isset($parseUrl['scheme']) AND !isset($parseUrl['host'])) {
129 132
             return '';
130
-        }elseif(isset($parseUrl['scheme'])){
133
+        } elseif(isset($parseUrl['scheme'])){
131 134
             return $parseUrl['scheme'] . '://' . $parseUrl['host'];
132 135
         } else {
133 136
             return $parseUrl['host'];
@@ -139,8 +142,9 @@  discard block
 block discarded – undo
139 142
     public function upToLastDir($url) {
140 143
         $parseUrl = parse_url($url);
141 144
         $path = '';
142
-        if(isset($parseUrl['path']))
143
-            $path = preg_replace('/\/([^\/]+)$/i', '', $parseUrl['path']);
145
+        if(isset($parseUrl['path'])) {
146
+                    $path = preg_replace('/\/([^\/]+)$/i', '', $parseUrl['path']);
147
+        }
144 148
         return rtrim($parseUrl['scheme'] . '://' . $parseUrl['host'] . $path, '/') . '/';
145 149
     }
146 150
 
@@ -180,9 +184,9 @@  discard block
 block discarded – undo
180 184
         if($this->starterPath===null){
181 185
             if($this->getBaseTag() === null) {
182 186
                 $this->starterPath =$this->getPagePath();
183
-            }elseif(array_key_exists('scheme', $this->getBaseTagParsing())){
187
+            } elseif(array_key_exists('scheme', $this->getBaseTagParsing())){
184 188
                 $this->starterPath = $this->getBaseTag() ;
185
-            }else{
189
+            } else{
186 190
                 $this->starterPath = $this->getPagePathParsing()['scheme'] . '://' . $this->getPagePathParsing()['host'] . $this->getBaseTag();
187 191
             }
188 192
         }
@@ -194,9 +198,9 @@  discard block
 block discarded – undo
194 198
         if ($this->domain === null) {
195 199
             if($this->getBaseTag() === null) {
196 200
                 $this->domain = $this->getPagePathParsing()['host'] . '/';
197
-            }elseif(array_key_exists('scheme', $this->getBaseTagParsing())){
201
+            } elseif(array_key_exists('scheme', $this->getBaseTagParsing())){
198 202
                 $this->domain = $this->getBaseTagParsing()['host'] . '/';
199
-            }else{
203
+            } else{
200 204
                 $this->domain = $this->getPagePathParsing()['host'] . '/';
201 205
             }
202 206
         }
@@ -208,9 +212,9 @@  discard block
 block discarded – undo
208 212
         if ($this->scheme === null) {
209 213
             if($this->getBaseTag() === null) {
210 214
                 $this->scheme = $this->getPagePathParsing()['scheme'];
211
-            }elseif(array_key_exists('scheme', $this->getBaseTagParsing())){
215
+            } elseif(array_key_exists('scheme', $this->getBaseTagParsing())){
212 216
                 $this->scheme = $this->getBaseTagParsing()['scheme'];
213
-            }else{
217
+            } else{
214 218
                 $this->scheme = $this->getPagePathParsing()['scheme'];
215 219
             }
216 220
         }
@@ -219,15 +223,17 @@  discard block
 block discarded – undo
219 223
 
220 224
     private function getBaseTagParsing()
221 225
     {
222
-        if($this->baseTagParsing == null)
223
-            $this->baseTagParsing = parse_url($this->getBaseTag());
226
+        if($this->baseTagParsing == null) {
227
+                    $this->baseTagParsing = parse_url($this->getBaseTag());
228
+        }
224 229
         return $this->baseTagParsing;
225 230
     }
226 231
 
227 232
     private function getPagePathParsing()
228 233
     {
229
-        if($this->pagePathParsing == null)
230
-            $this->pagePathParsing = parse_url($this->getPagePath());
234
+        if($this->pagePathParsing == null) {
235
+                    $this->pagePathParsing = parse_url($this->getPagePath());
236
+        }
231 237
         return $this->pagePathParsing;
232 238
     }
233 239
 }
234 240
\ No newline at end of file
Please login to merge, or discard this patch.