Skip to content

Commit fa0913c

Browse files
authored
refactor: fix phpstan errors in URI and SiteURI (#9525)
1 parent 92ff74e commit fa0913c

File tree

7 files changed

+104
-147
lines changed

7 files changed

+104
-147
lines changed

system/HTTP/SiteURI.php

+22-9
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class SiteURI extends URI
6868
* 0 => 'test',
6969
* ];
7070
*
71-
* @var array
71+
* @var array<int, string>
7272
*
7373
* @deprecated This property will be private.
7474
*/
@@ -331,35 +331,48 @@ public function refreshPath()
331331

332332
/**
333333
* Saves our parts from a parse_url() call.
334+
*
335+
* @param array{
336+
* host?: string,
337+
* user?: string,
338+
* path?: string,
339+
* query?: string,
340+
* fragment?: string,
341+
* scheme?: string,
342+
* port?: int,
343+
* pass?: string,
344+
* } $parts
334345
*/
335346
protected function applyParts(array $parts): void
336347
{
337-
if (! empty($parts['host'])) {
348+
if (isset($parts['host']) && $parts['host'] !== '') {
338349
$this->host = $parts['host'];
339350
}
340-
if (! empty($parts['user'])) {
351+
352+
if (isset($parts['user']) && $parts['user'] !== '') {
341353
$this->user = $parts['user'];
342354
}
355+
343356
if (isset($parts['path']) && $parts['path'] !== '') {
344357
$this->path = $this->filterPath($parts['path']);
345358
}
346-
if (! empty($parts['query'])) {
359+
360+
if (isset($parts['query']) && $parts['query'] !== '') {
347361
$this->setQuery($parts['query']);
348362
}
349-
if (! empty($parts['fragment'])) {
363+
364+
if (isset($parts['fragment']) && $parts['fragment'] !== '') {
350365
$this->fragment = $parts['fragment'];
351366
}
352367

353-
// Scheme
354368
if (isset($parts['scheme'])) {
355369
$this->setScheme(rtrim($parts['scheme'], ':/'));
356370
} else {
357371
$this->setScheme('http');
358372
}
359373

360-
// Port
361-
if (isset($parts['port']) && $parts['port'] !== null) {
362-
// Valid port numbers are enforced by earlier parse_url() or setPort()
374+
if (isset($parts['port'])) {
375+
// Valid port numbers are enforced by earlier parse_url or setPort()
363376
$this->port = $parts['port'];
364377
}
365378

0 commit comments

Comments
 (0)