fix: type mismatches and handle nullable values

This commit is contained in:
2026-08-27 10:16:03 +02:00
parent c33c1b6bf0
commit e7f3233dbc
9 changed files with 67 additions and 47 deletions
+12 -4
View File
@@ -31,12 +31,15 @@ class ResponseParser
public function parseXmlString(string $type, string $content): mixed
{
$xml = simplexml_load_string($content);
if (false === $xml) {
throw new ResponseParserException('Unable to parse XML response');
}
// Override type when present in XML to catch error responses
$responseType = $type;
$responseTypeXml = $xml->xpath('satz/@typ');
$responseTypeXml = $xml->xpath('satz/@typ') ?: [];
if (0 < count($responseTypeXml)) {
$responseType = (string) $xml->xpath('satz/@typ')[0];
$responseType = (string) $responseTypeXml[0];
}
switch ($responseType) {
@@ -91,7 +94,12 @@ class ResponseParser
$gender = 'W' === strtoupper($gender) ? 'F' : strtoupper($gender);
$dateString = (string) $addressXml->geburtsdatum;
$dateOfBirth = empty($dateString) ? null : \DateTimeImmutable::createFromFormat('d.m.Y', $dateString);
$dateOfBirth = null;
if ('' !== $dateString) {
$parsedDate = \DateTimeImmutable::createFromFormat('d.m.Y', $dateString);
$dateOfBirth = false === $parsedDate ? null : $parsedDate;
}
$response = new ProfileResponse();
$response
@@ -146,7 +154,7 @@ class ResponseParser
$personId = (int) $xml->idperson;
$updated = false;
$updatedXml = $xml->xpath('änderung|aenderung');
$updatedXml = $xml->xpath('änderung|aenderung') ?: [];
if (0 < count($updatedXml)) {
$updated = 'true' === strtolower((string) $updatedXml[0]);
}