Skip to content

Commit a94f34d

Browse files
committed
First pass at fixing things reported by phpstan-strict-rules
1 parent 01ce5c0 commit a94f34d

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

lib/functions.php

+16-16
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ function resolve(string $basePath, string $newPath): string
2626

2727
// If the new path defines a scheme, it's absolute and we can just return
2828
// that.
29-
if ($delta['scheme']) {
29+
if (null !== $delta['scheme']) {
3030
return build($delta);
3131
}
3232

3333
$base = parse($basePath);
3434
$pick = function ($part) use ($base, $delta) {
35-
if ($delta[$part]) {
35+
if (null !== $delta[$part]) {
3636
return $delta[$part];
37-
} elseif ($base[$part]) {
37+
} elseif (null !== $base[$part]) {
3838
return $base[$part];
3939
}
4040

@@ -85,13 +85,13 @@ function resolve(string $basePath, string $newPath): string
8585

8686
// If the source url ended with a /, we want to preserve that.
8787
$newParts['path'] = 0 === strpos($path, '/') ? $path : '/'.$path;
88-
if ($delta['query']) {
88+
if (null !== $delta['query']) {
8989
$newParts['query'] = $delta['query'];
9090
} elseif (!empty($base['query']) && empty($delta['host']) && empty($delta['path'])) {
9191
// Keep the old query if host and path didn't change
9292
$newParts['query'] = $base['query'];
9393
}
94-
if ($delta['fragment']) {
94+
if (null !== $delta['fragment']) {
9595
$newParts['fragment'] = $delta['fragment'];
9696
}
9797

@@ -134,7 +134,7 @@ function normalize(string $uri): string
134134
$parts['path'] = '/'.implode('/', $newPathParts);
135135
}
136136

137-
if ($parts['scheme']) {
137+
if (null !== $parts['scheme']) {
138138
$parts['scheme'] = strtolower($parts['scheme']);
139139
$defaultPorts = [
140140
'http' => '80',
@@ -157,7 +157,7 @@ function normalize(string $uri): string
157157
}
158158
}
159159

160-
if ($parts['host']) {
160+
if (null !== $parts['host']) {
161161
$parts['host'] = strtolower($parts['host']);
162162
}
163163

@@ -201,7 +201,7 @@ function ($matches) {
201201
}
202202

203203
$result = parse_url($uri);
204-
if (!$result) {
204+
if (false === $result) {
205205
$result = _parse_fallback($uri);
206206
} else {
207207
// Add empty host and leading slash to Windows file paths
@@ -212,7 +212,7 @@ function ($matches) {
212212
// that is used as the regex. The 2 backslash are then the way to get 1 backslash
213213
// character into the character set "a forward slash or a backslash"
214214
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'])) {
216216
$result['path'] = '/'.$result['path'];
217217
$result['host'] = '';
218218
}
@@ -265,7 +265,7 @@ function build(array $parts): string
265265
// If there's a scheme, there's also a host.
266266
$uri = $parts['scheme'].':';
267267
}
268-
if ($authority || (!empty($parts['scheme']) && 'file' === $parts['scheme'])) {
268+
if ('' !== $authority || (!empty($parts['scheme']) && 'file' === $parts['scheme'])) {
269269
// No scheme, but there is a host.
270270
$uri .= '//'.$authority;
271271
}
@@ -303,7 +303,7 @@ function build(array $parts): string
303303
function split(string $path): array
304304
{
305305
$matches = [];
306-
if (preg_match('/^(?:(?:(.*)(?:\/+))?([^\/]+))(?:\/?)$/u', $path, $matches)) {
306+
if (1 === preg_match('/^(?:(?:(.*)(?:\/+))?([^\/]+))(?:\/?)$/u', $path, $matches)) {
307307
return [$matches[1], $matches[2]];
308308
}
309309

@@ -353,7 +353,7 @@ function ($matches) {
353353
'query' => null,
354354
];
355355

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)) {
357357
$result['scheme'] = $matches[1];
358358
// Take what's left.
359359
$uri = substr($uri, strlen($result['scheme']) + 1);
@@ -382,10 +382,10 @@ function ($matches) {
382382
(?: : (?<port> [0-9]+))?
383383
(?<path> / .*)?
384384
$%x';
385-
if (!preg_match($regex, $uri, $matches)) {
385+
if (1 !== preg_match($regex, $uri, $matches)) {
386386
throw new InvalidUriException('Invalid, or could not parse URI');
387387
}
388-
if ($matches['host']) {
388+
if (isset($matches['host']) && '' !== $matches['host']) {
389389
$result['host'] = $matches['host'];
390390
}
391391
if (isset($matches['port'])) {
@@ -394,10 +394,10 @@ function ($matches) {
394394
if (isset($matches['path'])) {
395395
$result['path'] = $matches['path'];
396396
}
397-
if ($matches['user']) {
397+
if (isset($matches['user']) && '' !== $matches['user']) {
398398
$result['user'] = $matches['user'];
399399
}
400-
if ($matches['pass']) {
400+
if (isset($matches['pass']) && '' !== $matches['pass']) {
401401
$result['pass'] = $matches['pass'];
402402
}
403403
} else {

phpstan.neon

+4
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
parameters:
22
level: 9
3+
ignoreErrors:
4+
-
5+
message: "#^.* will always evaluate to true\\.$#"
6+
path: tests/*

0 commit comments

Comments
 (0)