From 3b5eecc0f2d70ede478082e80bcd53d6fdb244e5 Mon Sep 17 00:00:00 2001 From: Daniel Kurowski Date: Mon, 14 Aug 2023 08:54:58 +0200 Subject: [PATCH] administration units: fix url when invalid --- .../Response/AdministrationUnit.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/AdministrationUnit/Response/AdministrationUnit.php b/src/AdministrationUnit/Response/AdministrationUnit.php index 3c57595..d70bf63 100644 --- a/src/AdministrationUnit/Response/AdministrationUnit.php +++ b/src/AdministrationUnit/Response/AdministrationUnit.php @@ -4,6 +4,7 @@ use HnutiBrontosaurus\BisClient\AdministrationUnit\Category; use HnutiBrontosaurus\BisClient\Response\Coordinates; +use function str_starts_with; final class AdministrationUnit @@ -73,7 +74,7 @@ public static function fromResponseData(array $data): self : null, $data['phone'] !== '' ? $data['phone'] : null, $data['email'] !== '' ? $data['email'] : null, - $data['www'] !== '' ? $data['www'] : null, + $data['www'] !== '' ? self::fixUrl($data['www']) : null, Category::fromScalar($data['category']['slug']), $data['chairman'] !== null ? $data['chairman']['name'] : null, $data['manager'] !== null ? $data['manager']['name'] : null, @@ -81,6 +82,15 @@ public static function fromResponseData(array $data): self ); } + private static function fixUrl(string $url): string + { + if (str_starts_with($url, 'http')) { + return $url; + } + + return 'http://' . $url; + } + public function getId(): int {