Skip to content

Commit 3f1b418

Browse files
author
JoeyZandvliet
committed
fix: contact and person attributes can be null now, the object itself is always there, also remarks can be null
1 parent 4c2e14a commit 3f1b418

6 files changed

Lines changed: 121 additions & 37 deletions

File tree

src/Models/Contact.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@
77
class Contact
88
{
99
public function __construct(
10-
public int $contactId,
11-
public string $firstName,
12-
public string $prefix,
13-
public string $lastName,
10+
public ?int $contactId,
11+
public ?string $firstName,
12+
public ?string $prefix,
13+
public ?string $lastName,
1414
public string $email,
15-
public string $phone,
15+
public ?string $phone,
1616
public ?string $organisation,
17-
public int $parentSituationId,
17+
public ?int $parentSituationId,
1818
public string $function,
19-
public string $publicPhone,
20-
public bool $active,
21-
public int $createdById,
22-
public int $changedById,
19+
public ?string $publicPhone,
20+
public ?bool $active,
21+
public ?int $createdById,
22+
public ?int $changedById,
2323
) {
2424
}
2525
}

src/Models/Person.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Person
1010
{
1111
public function __construct(
1212
public string $firstName,
13-
public string $prefix,
13+
public ?string $prefix,
1414
public string $lastName,
1515
public PersonType $type,
1616
) {

src/Models/Situation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function __construct(
6363
/**
6464
* @var string[]
6565
*/
66-
public array $remarks,
66+
public ?array $remarks,
6767
/**
6868
* @var \Swis\Melvin\Models\Contact[]
6969
*/

src/Parsers/ContactParser.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ class ContactParser
1111
public function parse(\stdClass $object): Contact
1212
{
1313
return new Contact(
14-
$object->contactId,
15-
$object->firstName,
16-
$object->prefix,
17-
$object->lastName,
14+
$object->contactId ?? null,
15+
$object->firstName ?? null,
16+
$object->prefix ?? null,
17+
$object->lastName ?? null,
1818
$object->email,
1919
$object->phone,
2020
$object->organisation ?? $object->organization,
21-
$object->parentSituationId,
21+
$object->parentSituationId ?? null,
2222
$object->function,
23-
$object->publicPhone,
24-
$object->active,
25-
$object->createdById,
26-
$object->changedById
23+
$object->publicPhone ?? null,
24+
$object->active ?? null,
25+
$object->createdById ?? null,
26+
$object->changedById ?? null
2727
);
2828
}
2929
}

src/Parsers/SituationParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function parse(\stdClass $object, array $restrictions, array $detours = [
112112
array_map([$this->detourParser, 'parse'], $detours, array_keys($detours)),
113113
($object->properties->permitId ?? '') ?: null,
114114
($object->properties->referenceId ?? '') ?: null,
115-
$object->properties->remarks,
115+
($object->properties->remarks ?? '') ?: null,
116116
array_map([$this->contactParser, 'parse'], $object->properties->contacts ?? []),
117117
);
118118
}

tests/_files/situations-schema.json

Lines changed: 99 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,17 @@
378378
]
379379
},
380380
"remarks": {
381-
"type": "array",
382-
"items": {
383-
"type": "string"
384-
}
381+
"anyOf": [
382+
{
383+
"type": "array",
384+
"items": {
385+
"type": "string"
386+
}
387+
},
388+
{
389+
"type": "null"
390+
}
391+
]
385392
},
386393
"contacts": {
387394
"type": "array",
@@ -421,19 +428,47 @@
421428
"additionalProperties": false,
422429
"properties": {
423430
"firstName": {
424-
"type": "string"
431+
"anyOf": [
432+
{
433+
"type": "string"
434+
},
435+
{
436+
"type": "null"
437+
}
438+
]
425439
},
426440
"prefix": {
427-
"type": "string"
441+
"anyOf": [
442+
{
443+
"type": "string"
444+
},
445+
{
446+
"type": "null"
447+
}
448+
]
428449
},
429450
"lastName": {
430-
"type": "string"
451+
"anyOf": [
452+
{
453+
"type": "string"
454+
},
455+
{
456+
"type": "null"
457+
}
458+
]
431459
},
432460
"email": {
433461
"type": "string"
434462
},
435463
"phone": {
436-
"type": "string"
464+
"anyOf": [
465+
{
466+
"type": "string"
467+
},
468+
{
469+
"type": "null"
470+
}
471+
]
437472
},
438473
"organisation": {
439474
"anyOf": [
@@ -446,10 +481,24 @@
446481
]
447482
},
448483
"parentSituationId": {
449-
"type": "integer"
484+
"anyOf": [
485+
{
486+
"type": "integer"
487+
},
488+
{
489+
"type": "null"
490+
}
491+
]
450492
},
451493
"contactId": {
452-
"type": "integer"
494+
"anyOf": [
495+
{
496+
"type": "integer"
497+
},
498+
{
499+
"type": "null"
500+
}
501+
]
453502
},
454503
"organization": {
455504
"anyOf": [
@@ -465,16 +514,44 @@
465514
"type": "string"
466515
},
467516
"publicPhone": {
468-
"type": "string"
517+
"anyOf": [
518+
{
519+
"type": "string"
520+
},
521+
{
522+
"type": "null"
523+
}
524+
]
469525
},
470526
"active": {
471-
"type": "boolean"
527+
"anyOf": [
528+
{
529+
"type": "boolean"
530+
},
531+
{
532+
"type": "null"
533+
}
534+
]
472535
},
473536
"createdById": {
474-
"type": "integer"
537+
"anyOf": [
538+
{
539+
"type": "integer"
540+
},
541+
{
542+
"type": "null"
543+
}
544+
]
475545
},
476546
"changedById": {
477-
"type": "integer"
547+
"anyOf": [
548+
{
549+
"type": "integer"
550+
},
551+
{
552+
"type": "null"
553+
}
554+
]
478555
}
479556
},
480557
"required": [
@@ -502,7 +579,14 @@
502579
"type": "string"
503580
},
504581
"prefix": {
505-
"type": "string"
582+
"anyOf": [
583+
{
584+
"type": "string"
585+
},
586+
{
587+
"type": "null"
588+
}
589+
]
506590
},
507591
"lastName": {
508592
"type": "string"

0 commit comments

Comments
 (0)