Skip to content

Commit

Permalink
feat: add new properties
Browse files Browse the repository at this point in the history
  • Loading branch information
JaZo committed Mar 13, 2024
1 parent f4df2c3 commit dee0c54
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/Api/Situations.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

use Swis\Melvin\Client;
use Swis\Melvin\Parsers\AttachmentParser;
use Swis\Melvin\Parsers\ContactParser;
use Swis\Melvin\Parsers\DetourParser;
use Swis\Melvin\Parsers\GeometryParser;
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 @@ -27,7 +29,9 @@ public function __construct(Client $client, ?SituationParser $situationParser =
new PeriodParser(),
new AttachmentParser(),
new RestrictionParser($geometryParser),
new DetourParser($geometryParser)
new DetourParser($geometryParser),
new ContactParser(),
new UrlParser()
);
}

Expand Down
24 changes: 24 additions & 0 deletions src/Models/Contact.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Swis\Melvin\Models;

class Contact
{
public function __construct(
public int $contactId,
public string $firstName,
public string $prefix,
public string $lastName,
public string $email,
public string $phone,
public ?string $organisation,
public int $parentSituationId,
public string $function,
public string $publicPhone,
public bool $active,
public int $createdById
) {
}
}
12 changes: 11 additions & 1 deletion src/Models/Situation.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,17 @@ public function __construct(
/**
* @var \Swis\Melvin\Models\Detour[]
*/
public array $detours
public array $detours,
public ?string $permitId,
public ?string $referenceId,
/**
* @var string[]
*/
public array $remarks,
/**
* @var \Swis\Melvin\Models\Contact[]
*/
public array $contacts
) {
}
}
4 changes: 3 additions & 1 deletion src/Models/VehicleInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ class VehicleInformation
{
public function __construct(
public ?float $heightCharacteristic,
public ?float $lengthCharacteristic
public ?float $lengthCharacteristic,
public ?float $widthCharacteristic,
public ?float $grossWeightCharacteristic
) {
}
}
28 changes: 28 additions & 0 deletions src/Parsers/ContactParser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Swis\Melvin\Parsers;

use Swis\Melvin\Models\Contact;

class ContactParser
{
public function parse(\stdClass $object): Contact
{
return new Contact(
$object->contactId,
$object->firstName,
$object->prefix,
$object->lastName,
$object->email,
$object->phone,
$object->organisation ?? $object->organization,
$object->parentSituationId,
$object->function,
$object->publicPhone,
$object->active,
$object->createdById
);
}
}
4 changes: 3 additions & 1 deletion src/Parsers/RestrictionParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ public function parse(\stdClass $object, int $index): Restriction
if ($vehicleInformation = (array) ($object->properties->vehicleInformation ?? []) ? $object->properties->vehicleInformation : null) {
$vehicleInformation = new VehicleInformation(
$vehicleInformation->heightCharacteristic ?? null,
$vehicleInformation->lengthCharacteristic ?? null
$vehicleInformation->lengthCharacteristic ?? null,
$vehicleInformation->widthCharacteristic ?? null,
$vehicleInformation->grossWeightCharacteristic ?? null,
);
}

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

Expand Down Expand Up @@ -90,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 All @@ -107,7 +109,11 @@ public function parse(\stdClass $object, array $restrictions, array $detours = [
$lastChangedBy,
array_map([$this->attachmentParser, 'parse'], $object->properties->attachments ?? [], array_keys($object->properties->attachments ?? [])),
array_map([$this->restrictionParser, 'parse'], $restrictions, array_keys($restrictions)),
array_map([$this->detourParser, 'parse'], $detours, array_keys($detours))
array_map([$this->detourParser, 'parse'], $detours, array_keys($detours)),
$object->properties->permitId,
$object->properties->referenceId,
$object->properties->remarks,
array_map([$this->contactParser, 'parse'], $object->properties->contacts ?? []),
);
}

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 dee0c54

Please sign in to comment.