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 14, 2024
1 parent a182e95 commit 4ce5c61
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/Api/Situations.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

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;
Expand All @@ -27,7 +28,8 @@ public function __construct(Client $client, ?SituationParser $situationParser =
new PeriodParser(),
new AttachmentParser(),
new RestrictionParser($geometryParser),
new DetourParser($geometryParser)
new DetourParser($geometryParser),
new ContactParser()
);
}

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
9 changes: 7 additions & 2 deletions src/Parsers/SituationParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public function __construct(
protected PeriodParser $periodParser,
protected AttachmentParser $attachmentParser,
protected RestrictionParser $restrictionParser,
protected DetourParser $detourParser
protected DetourParser $detourParser,
protected ContactParser $contactParser
) {
}

Expand Down Expand Up @@ -107,7 +108,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

0 comments on commit 4ce5c61

Please sign in to comment.