@@ -26,15 +26,15 @@ function resolve(string $basePath, string $newPath): string
26
26
27
27
// If the new path defines a scheme, it's absolute and we can just return
28
28
// that.
29
- if ($ delta ['scheme ' ]) {
29
+ if (null !== $ delta ['scheme ' ]) {
30
30
return build ($ delta );
31
31
}
32
32
33
33
$ base = parse ($ basePath );
34
34
$ pick = function ($ part ) use ($ base , $ delta ) {
35
- if ($ delta [$ part ]) {
35
+ if (null !== $ delta [$ part ]) {
36
36
return $ delta [$ part ];
37
- } elseif ($ base [$ part ]) {
37
+ } elseif (null !== $ base [$ part ]) {
38
38
return $ base [$ part ];
39
39
}
40
40
@@ -85,13 +85,13 @@ function resolve(string $basePath, string $newPath): string
85
85
86
86
// If the source url ended with a /, we want to preserve that.
87
87
$ newParts ['path ' ] = 0 === strpos ($ path , '/ ' ) ? $ path : '/ ' .$ path ;
88
- if ($ delta ['query ' ]) {
88
+ if (null !== $ delta ['query ' ]) {
89
89
$ newParts ['query ' ] = $ delta ['query ' ];
90
90
} elseif (!empty ($ base ['query ' ]) && empty ($ delta ['host ' ]) && empty ($ delta ['path ' ])) {
91
91
// Keep the old query if host and path didn't change
92
92
$ newParts ['query ' ] = $ base ['query ' ];
93
93
}
94
- if ($ delta ['fragment ' ]) {
94
+ if (null !== $ delta ['fragment ' ]) {
95
95
$ newParts ['fragment ' ] = $ delta ['fragment ' ];
96
96
}
97
97
@@ -134,7 +134,7 @@ function normalize(string $uri): string
134
134
$ parts ['path ' ] = '/ ' .implode ('/ ' , $ newPathParts );
135
135
}
136
136
137
- if ($ parts ['scheme ' ]) {
137
+ if (null !== $ parts ['scheme ' ]) {
138
138
$ parts ['scheme ' ] = strtolower ($ parts ['scheme ' ]);
139
139
$ defaultPorts = [
140
140
'http ' => '80 ' ,
@@ -157,7 +157,7 @@ function normalize(string $uri): string
157
157
}
158
158
}
159
159
160
- if ($ parts ['host ' ]) {
160
+ if (null !== $ parts ['host ' ]) {
161
161
$ parts ['host ' ] = strtolower ($ parts ['host ' ]);
162
162
}
163
163
@@ -201,7 +201,7 @@ function ($matches) {
201
201
}
202
202
203
203
$ result = parse_url ($ uri );
204
- if (! $ result ) {
204
+ if (false === $ result ) {
205
205
$ result = _parse_fallback ($ uri );
206
206
} else {
207
207
// Add empty host and leading slash to Windows file paths
@@ -212,7 +212,7 @@ function ($matches) {
212
212
// that is used as the regex. The 2 backslash are then the way to get 1 backslash
213
213
// character into the character set "a forward slash or a backslash"
214
214
if (isset ($ result ['scheme ' ]) && 'file ' === $ result ['scheme ' ] && isset ($ result ['path ' ]) &&
215
- preg_match ('/^(?<windows_path> [a-zA-Z]:([\/ \\\\].*)?)$/x ' , $ result ['path ' ])) {
215
+ 1 === preg_match ('/^(?<windows_path> [a-zA-Z]:([\/ \\\\].*)?)$/x ' , $ result ['path ' ])) {
216
216
$ result ['path ' ] = '/ ' .$ result ['path ' ];
217
217
$ result ['host ' ] = '' ;
218
218
}
@@ -265,7 +265,7 @@ function build(array $parts): string
265
265
// If there's a scheme, there's also a host.
266
266
$ uri = $ parts ['scheme ' ].': ' ;
267
267
}
268
- if ($ authority || (!empty ($ parts ['scheme ' ]) && 'file ' === $ parts ['scheme ' ])) {
268
+ if ('' !== $ authority || (!empty ($ parts ['scheme ' ]) && 'file ' === $ parts ['scheme ' ])) {
269
269
// No scheme, but there is a host.
270
270
$ uri .= '// ' .$ authority ;
271
271
}
@@ -303,7 +303,7 @@ function build(array $parts): string
303
303
function split (string $ path ): array
304
304
{
305
305
$ matches = [];
306
- if (preg_match ('/^(?:(?:(.*)(?:\/+))?([^\/]+))(?:\/?)$/u ' , $ path , $ matches )) {
306
+ if (1 === preg_match ('/^(?:(?:(.*)(?:\/+))?([^\/]+))(?:\/?)$/u ' , $ path , $ matches )) {
307
307
return [$ matches [1 ], $ matches [2 ]];
308
308
}
309
309
@@ -353,7 +353,7 @@ function ($matches) {
353
353
'query ' => null ,
354
354
];
355
355
356
- if (preg_match ('% ^([A-Za-z][A-Za-z0-9+-\.]+): %x ' , $ uri , $ matches )) {
356
+ if (1 === preg_match ('% ^([A-Za-z][A-Za-z0-9+-\.]+): %x ' , $ uri , $ matches )) {
357
357
$ result ['scheme ' ] = $ matches [1 ];
358
358
// Take what's left.
359
359
$ uri = substr ($ uri , strlen ($ result ['scheme ' ]) + 1 );
@@ -382,10 +382,10 @@ function ($matches) {
382
382
(?: : (?<port> [0-9]+))?
383
383
(?<path> / .*)?
384
384
$%x ' ;
385
- if (! preg_match ($ regex , $ uri , $ matches )) {
385
+ if (1 !== preg_match ($ regex , $ uri , $ matches )) {
386
386
throw new InvalidUriException ('Invalid, or could not parse URI ' );
387
387
}
388
- if ($ matches ['host ' ]) {
388
+ if (isset ( $ matches [ ' host ' ]) && '' !== $ matches ['host ' ]) {
389
389
$ result ['host ' ] = $ matches ['host ' ];
390
390
}
391
391
if (isset ($ matches ['port ' ])) {
@@ -394,10 +394,10 @@ function ($matches) {
394
394
if (isset ($ matches ['path ' ])) {
395
395
$ result ['path ' ] = $ matches ['path ' ];
396
396
}
397
- if ($ matches ['user ' ]) {
397
+ if (isset ( $ matches [ ' user ' ]) && '' !== $ matches ['user ' ]) {
398
398
$ result ['user ' ] = $ matches ['user ' ];
399
399
}
400
- if ($ matches ['pass ' ]) {
400
+ if (isset ( $ matches [ ' pass ' ]) && '' !== $ matches ['pass ' ]) {
401
401
$ result ['pass ' ] = $ matches ['pass ' ];
402
402
}
403
403
} else {
0 commit comments