Skip to content

Commit e5c06ce

Browse files
committed
Avoiding TypeError or wrong CPR code of the child
1 parent 9cac753 commit e5c06ce

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/Plugin/os2web/DataLookup/ServiceplatformenCPRExtended.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,20 @@ public function lookup($cpr, $allowCprTestModeReplace = TRUE) {
122122
$relationship->barn = [$relationship->barn];
123123
}
124124

125-
foreach ($relationship->barn as $child) {
126-
$childCprResult = $this->lookup($child->personnummer, FALSE);
127-
128-
$children[] = [
129-
'cpr' => $childCprResult->getCpr(),
130-
'name' => $childCprResult->getName(),
125+
foreach ($relationship->barn as $relationshipChild) {
126+
// Sometimes CPR lookup can return no results, creating child without
127+
// name.
128+
$child = [
129+
'cpr' => $relationshipChild->personnummer,
130+
'name' => '',
131131
];
132+
133+
$childCprResult = $this->lookup($relationshipChild->personnummer, FALSE);
134+
if ($childCprResult->isSuccessful()) {
135+
$child['name'] = $childCprResult->getName();
136+
}
137+
138+
$children[] = $child;
132139
}
133140
}
134141
$cprResult->setChildren($children);

0 commit comments

Comments
 (0)