Passed
Push — master ( 636f09...526e5d )
by Pouya
07:50
created
src/ConvertToAbsolutePath.php 2 patches
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
     /** @var string */
38 38
     private $baseTag;
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
      */
@@ -59,11 +59,11 @@  discard block
 block discarded – undo
59 59
     {
60 60
         // Skip converting if the relative url like http://... or android-app://... etc.
61 61
         if (preg_match('/[a-z0-9-]{1,}(:\/\/)/i', $path)) {
62
-            if(preg_match('/services:\/\//i', $path))
62
+            if (preg_match('/services:\/\//i', $path))
63 63
                 return null;
64
-            if(preg_match('/whatsapp:\/\//i', $path))
64
+            if (preg_match('/whatsapp:\/\//i', $path))
65 65
                 return null;
66
-            if(preg_match('/tel:/i', $path))
66
+            if (preg_match('/tel:/i', $path))
67 67
                 return null;
68 68
             return $path;
69 69
         }
@@ -72,33 +72,33 @@  discard block
 block discarded – undo
72 72
             return NULL;
73 73
         }
74 74
         // Convert //www.google.com to http://www.google.com
75
-        if(substr($path, 0, 2) == '//') {
75
+        if (substr($path, 0, 2) == '//') {
76 76
             return 'http:' . $path;
77 77
         }
78 78
         // If the path is a fragment or query string,
79 79
         // it will be appended to the base url
80
-        if(substr($path, 0, 1) == '#' || substr($path, 0, 1) == '?') {
80
+        if (substr($path, 0, 1) == '#' || substr($path, 0, 1) == '?') {
81 81
             return $this->getStarterPath() . $path;
82 82
         }
83 83
         // Treat paths with doc root, i.e, /about
84
-        if(substr($path, 0, 1) == '/') {
84
+        if (substr($path, 0, 1) == '/') {
85 85
             return static::onlySitePath($this->getStarterPath()) . $path;
86 86
         }
87 87
         // For paths like ./foo, it will be appended to the furthest directory
88
-        if(substr($path, 0, 2) == './') {
88
+        if (substr($path, 0, 2) == './') {
89 89
             return static::uptoLastDir($this->getStarterPath()) . substr($path, 2);
90 90
         }
91 91
         // Convert paths like ../foo or ../../bar
92
-        if(substr($path, 0, 3) == '../') {
92
+        if (substr($path, 0, 3) == '../') {
93 93
             $rel = $path;
94 94
             $base = static::uptoLastDir($this->getStarterPath());
95
-            while(substr($rel, 0, 3) == '../') {
95
+            while (substr($rel, 0, 3) == '../') {
96 96
                 $base = preg_replace('/\/([^\/]+\/)$/i', '/', $base);
97 97
                 $rel = substr($rel, 3);
98 98
             }
99 99
             if ($base === ($this->getScheme() . '://')) {
100 100
                 $base .= $this->getDomain();
101
-            } elseif ($base===($this->getScheme(). ':/')) {
101
+            } elseif ($base === ($this->getScheme() . ':/')) {
102 102
                 $base .= '/' . $this->getDomain();
103 103
             }
104 104
             return $base . $rel;
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
     public function upToLastDir($url) {
121 121
         $parseUrl = parse_url($url);
122 122
         $path = '';
123
-        if(isset($parseUrl['path']))
123
+        if (isset($parseUrl['path']))
124 124
             $path = preg_replace('/\/([^\/]+)$/i', '', $parseUrl['path']);
125 125
         return rtrim($parseUrl['scheme'] . '://' . $parseUrl['host'] . $path, '/') . '/';
126 126
     }
@@ -162,12 +162,12 @@  discard block
 block discarded – undo
162 162
      */
163 163
     private function getStarterPath(): string
164 164
     {
165
-        if($this->starterPath===null){
166
-            if($this->getBaseTag() === null) {
167
-                $this->starterPath =$this->getPagePath();
168
-            }elseif(array_key_exists('scheme', $this->getBaseTagParsing())){
169
-                $this->starterPath = $this->getBaseTag() ;
170
-            }else{
165
+        if ($this->starterPath === null) {
166
+            if ($this->getBaseTag() === null) {
167
+                $this->starterPath = $this->getPagePath();
168
+            }elseif (array_key_exists('scheme', $this->getBaseTagParsing())) {
169
+                $this->starterPath = $this->getBaseTag();
170
+            }else {
171 171
                 $this->starterPath = $this->getPagePathParsing()['scheme'] . '://' . $this->getPagePathParsing()['host'] . $this->getBaseTag();
172 172
             }
173 173
         }
@@ -177,11 +177,11 @@  discard block
 block discarded – undo
177 177
     private function getDomain()
178 178
     {
179 179
         if ($this->domain === null) {
180
-            if($this->getBaseTag() === null) {
180
+            if ($this->getBaseTag() === null) {
181 181
                 $this->domain = $this->getPagePathParsing()['host'] . '/';
182
-            }elseif(array_key_exists('scheme', $this->getBaseTagParsing())){
182
+            }elseif (array_key_exists('scheme', $this->getBaseTagParsing())) {
183 183
                 $this->domain = $this->getBaseTagParsing()['host'] . '/';
184
-            }else{
184
+            }else {
185 185
                 $this->domain = $this->getPagePathParsing()['host'] . '/';
186 186
             }
187 187
         }
@@ -191,11 +191,11 @@  discard block
 block discarded – undo
191 191
     private function getScheme()
192 192
     {
193 193
         if ($this->scheme === null) {
194
-            if($this->getBaseTag() === null) {
194
+            if ($this->getBaseTag() === null) {
195 195
                 $this->scheme = $this->getPagePathParsing()['scheme'];
196
-            }elseif(array_key_exists('scheme', $this->getBaseTagParsing())){
196
+            }elseif (array_key_exists('scheme', $this->getBaseTagParsing())) {
197 197
                 $this->scheme = $this->getBaseTagParsing()['scheme'];
198
-            }else{
198
+            }else {
199 199
                 $this->scheme = $this->getPagePathParsing()['scheme'];
200 200
             }
201 201
         }
@@ -204,14 +204,14 @@  discard block
 block discarded – undo
204 204
 
205 205
     private function getBaseTagParsing()
206 206
     {
207
-        if($this->baseTagParsing == null)
207
+        if ($this->baseTagParsing == null)
208 208
             $this->baseTagParsing = parse_url($this->getBaseTag());
209 209
         return $this->baseTagParsing;
210 210
     }
211 211
 
212 212
     private function getPagePathParsing()
213 213
     {
214
-        if($this->pagePathParsing == null)
214
+        if ($this->pagePathParsing == null)
215 215
             $this->pagePathParsing = parse_url($this->getPagePath());
216 216
         return $this->pagePathParsing;
217 217
     }
Please login to merge, or discard this patch.
Braces   +24 added lines, -18 removed lines patch added patch discarded remove patch
@@ -59,12 +59,15 @@  discard block
 block discarded – undo
59 59
     {
60 60
         // Skip converting if the relative url like http://... or android-app://... etc.
61 61
         if (preg_match('/[a-z0-9-]{1,}(:\/\/)/i', $path)) {
62
-            if(preg_match('/services:\/\//i', $path))
63
-                return null;
64
-            if(preg_match('/whatsapp:\/\//i', $path))
65
-                return null;
66
-            if(preg_match('/tel:/i', $path))
67
-                return null;
62
+            if(preg_match('/services:\/\//i', $path)) {
63
+                            return null;
64
+            }
65
+            if(preg_match('/whatsapp:\/\//i', $path)) {
66
+                            return null;
67
+            }
68
+            if(preg_match('/tel:/i', $path)) {
69
+                            return null;
70
+            }
68 71
             return $path;
69 72
         }
70 73
         // Treat path as invalid if it is like javascript:... etc.
@@ -120,8 +123,9 @@  discard block
 block discarded – undo
120 123
     public function upToLastDir($url) {
121 124
         $parseUrl = parse_url($url);
122 125
         $path = '';
123
-        if(isset($parseUrl['path']))
124
-            $path = preg_replace('/\/([^\/]+)$/i', '', $parseUrl['path']);
126
+        if(isset($parseUrl['path'])) {
127
+                    $path = preg_replace('/\/([^\/]+)$/i', '', $parseUrl['path']);
128
+        }
125 129
         return rtrim($parseUrl['scheme'] . '://' . $parseUrl['host'] . $path, '/') . '/';
126 130
     }
127 131
 
@@ -165,9 +169,9 @@  discard block
 block discarded – undo
165 169
         if($this->starterPath===null){
166 170
             if($this->getBaseTag() === null) {
167 171
                 $this->starterPath =$this->getPagePath();
168
-            }elseif(array_key_exists('scheme', $this->getBaseTagParsing())){
172
+            } elseif(array_key_exists('scheme', $this->getBaseTagParsing())){
169 173
                 $this->starterPath = $this->getBaseTag() ;
170
-            }else{
174
+            } else{
171 175
                 $this->starterPath = $this->getPagePathParsing()['scheme'] . '://' . $this->getPagePathParsing()['host'] . $this->getBaseTag();
172 176
             }
173 177
         }
@@ -179,9 +183,9 @@  discard block
 block discarded – undo
179 183
         if ($this->domain === null) {
180 184
             if($this->getBaseTag() === null) {
181 185
                 $this->domain = $this->getPagePathParsing()['host'] . '/';
182
-            }elseif(array_key_exists('scheme', $this->getBaseTagParsing())){
186
+            } elseif(array_key_exists('scheme', $this->getBaseTagParsing())){
183 187
                 $this->domain = $this->getBaseTagParsing()['host'] . '/';
184
-            }else{
188
+            } else{
185 189
                 $this->domain = $this->getPagePathParsing()['host'] . '/';
186 190
             }
187 191
         }
@@ -193,9 +197,9 @@  discard block
 block discarded – undo
193 197
         if ($this->scheme === null) {
194 198
             if($this->getBaseTag() === null) {
195 199
                 $this->scheme = $this->getPagePathParsing()['scheme'];
196
-            }elseif(array_key_exists('scheme', $this->getBaseTagParsing())){
200
+            } elseif(array_key_exists('scheme', $this->getBaseTagParsing())){
197 201
                 $this->scheme = $this->getBaseTagParsing()['scheme'];
198
-            }else{
202
+            } else{
199 203
                 $this->scheme = $this->getPagePathParsing()['scheme'];
200 204
             }
201 205
         }
@@ -204,15 +208,17 @@  discard block
 block discarded – undo
204 208
 
205 209
     private function getBaseTagParsing()
206 210
     {
207
-        if($this->baseTagParsing == null)
208
-            $this->baseTagParsing = parse_url($this->getBaseTag());
211
+        if($this->baseTagParsing == null) {
212
+                    $this->baseTagParsing = parse_url($this->getBaseTag());
213
+        }
209 214
         return $this->baseTagParsing;
210 215
     }
211 216
 
212 217
     private function getPagePathParsing()
213 218
     {
214
-        if($this->pagePathParsing == null)
215
-            $this->pagePathParsing = parse_url($this->getPagePath());
219
+        if($this->pagePathParsing == null) {
220
+                    $this->pagePathParsing = parse_url($this->getPagePath());
221
+        }
216 222
         return $this->pagePathParsing;
217 223
     }
218 224
 }
219 225
\ No newline at end of file
Please login to merge, or discard this patch.