From ef810a2b942a6988f63db694c611f0c4f5818144 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sat, 19 Oct 2024 14:45:12 +0200 Subject: [PATCH] fix psalm errors --- src/Authority/Port.php | 5 ++++- src/Url.php | 40 ++++++++++++++++++++++++++++++++-------- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/Authority/Port.php b/src/Authority/Port.php index 015d86e..8c77133 100644 --- a/src/Authority/Port.php +++ b/src/Authority/Port.php @@ -53,7 +53,10 @@ public function format(): string public function value(): int { - return $this->value ?: 0; + return match ($this->value) { + null => 0, + default => $this->value, + }; } public function toString(): string diff --git a/src/Url.php b/src/Url.php index ef9cc73..a4d502f 100644 --- a/src/Url.php +++ b/src/Url.php @@ -55,18 +55,42 @@ public static function of(string $string): self } return new self( - $data['scheme'] ? Scheme::of($data['scheme']) : Scheme::none(), + match ($data['scheme']) { + null, '' => Scheme::none(), + default => Scheme::of($data['scheme']), + }, Authority::of( UserInformation::of( - $data['user'] ? User::of($data['user']) : User::none(), - $data['pass'] ? Password::of($data['pass']) : Password::none(), + match ($data['user']) { + null, '' => User::none(), + default => User::of($data['user']), + }, + match ($data['pass']) { + null, '' => Password::none(), + default => Password::of($data['pass']), + }, ), - $data['host'] ? Host::of($data['host']) : Host::none(), - $data['port'] ? Port::of((int) $data['port']) : Port::none(), + match ($data['host']) { + null, '' => Host::none(), + default => Host::of($data['host']), + }, + match ($data['port']) { + null, '' => Port::none(), + default => Port::of((int) $data['port']), + }, ), - $data['path'] && !empty($data['path']) ? Path::of($data['path']) : Path::none(), - $data['query'] ? Query::of($data['query']) : Query::none(), - $data['fragment'] ? Fragment::of($data['fragment']) : Fragment::none(), + match ($data['path']) { + null, '' => Path::none(), + default => Path::of($data['path']), + }, + match ($data['query']) { + null, '' => Query::none(), + default => Query::of($data['query']), + }, + match ($data['fragment']) { + null, '' => Fragment::none(), + default => Fragment::of($data['fragment']), + }, ); }