Skip to content

Commit

Permalink
feat: cleanup URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
JaZo committed Mar 14, 2024
1 parent 4ce5c61 commit 91648b7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Api/Situations.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Swis\Melvin\Parsers\PeriodParser;
use Swis\Melvin\Parsers\RestrictionParser;
use Swis\Melvin\Parsers\SituationParser;
use Swis\Melvin\Parsers\UrlParser;
use Swis\Melvin\SituationFilterParameters;

class Situations extends AbstractApi
Expand All @@ -29,7 +30,8 @@ public function __construct(Client $client, ?SituationParser $situationParser =
new AttachmentParser(),
new RestrictionParser($geometryParser),
new DetourParser($geometryParser),
new ContactParser()
new ContactParser(),
new UrlParser()
);
}

Expand Down
5 changes: 3 additions & 2 deletions src/Parsers/SituationParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public function __construct(
protected AttachmentParser $attachmentParser,
protected RestrictionParser $restrictionParser,
protected DetourParser $detourParser,
protected ContactParser $contactParser
protected ContactParser $contactParser,
protected UrlParser $urlParser
) {
}

Expand Down Expand Up @@ -91,7 +92,7 @@ public function parse(\stdClass $object, array $restrictions, array $detours = [
$object->properties->project,
Source::from($object->properties->source),
$object->properties->published,
($object->properties->url ?? '') ?: null,
$this->urlParser->parse($object->properties->url ?? ''),
($object->properties->urlDescription ?? '') ?: null,
Delay::from($object->properties->delay),
($object->properties->workType ?? '') ? WorkType::from($object->properties->workType) : null,
Expand Down
27 changes: 27 additions & 0 deletions src/Parsers/UrlParser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Swis\Melvin\Parsers;

class UrlParser
{
private const EMPTY_VALUES = [
'',
'n.v.t.',
'n.v.t',
];

public function parse(?string $url): ?string
{
if (in_array($url, self::EMPTY_VALUES, true)) {
return null;
}

if (!str_contains($url, '://')) {
$url = 'https://'.$url;
}

return $url;
}
}

0 comments on commit 91648b7

Please sign in to comment.