Skip to content

Commit

Permalink
administration units: fix url when invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Kurowski committed Aug 14, 2023
1 parent 1a30977 commit 3b5eecc
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/AdministrationUnit/Response/AdministrationUnit.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use HnutiBrontosaurus\BisClient\AdministrationUnit\Category;
use HnutiBrontosaurus\BisClient\Response\Coordinates;
use function str_starts_with;


final class AdministrationUnit
Expand Down Expand Up @@ -73,14 +74,23 @@ 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,
$data,
);
}

private static function fixUrl(string $url): string
{
if (str_starts_with($url, 'http')) {
return $url;
}

return 'http://' . $url;
}


public function getId(): int
{
Expand Down

0 comments on commit 3b5eecc

Please sign in to comment.