Skip to content

Commit 44a363f

Browse files
committed
Simplifies external ID retrieval logic
Streamlines how external IDs are extracted and returned, reducing complexity and improving maintainability. Ensures more predictable and direct access to requested external IDs.
1 parent e9514e5 commit 44a363f

File tree

1 file changed

+4
-37
lines changed

1 file changed

+4
-37
lines changed

src/AbraFlexi/RO.php

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,10 +1108,10 @@ public function fixRecordTypes(array $record, $evidence = null)
11081108
$value,
11091109
);
11101110
}
1111-
} else {
1111+
} else { // ExtIDs
11121112
foreach ($record[$column] as $relPos => $rawRelation) {
11131113
[,$ext,$extId] = explode(':', $rawRelation);
1114-
$record[$column][$ext] = new Relation($extId, $column, $ext, $rawRelation);
1114+
$record[$column][$ext] = new Relation($rawRelation, $ext, $extId, $column.' '.$ext.':'.$extId );
11151115
unset($record[$column][$relPos]);
11161116
}
11171117
}
@@ -2077,41 +2077,8 @@ public function getPrevRecordID($conditions = [])
20772077
*/
20782078
public function getExternalID($want = null)
20792079
{
2080-
$extid = null;
2081-
$ids = $this->getExternalIDs();
2082-
2083-
// If $ids is an array of Relation objects, extract their 'value' property
2084-
if (\is_array($ids) && isset($ids[0]) && \is_object($ids[0]) && property_exists($ids[0], 'value')) {
2085-
$values = array_map(static function ($relation) {
2086-
return $relation->value;
2087-
}, $ids);
2088-
} elseif (\is_object($ids) && property_exists($ids, 'value')) {
2089-
$values = \is_array($ids->value) ? $ids->value : [$ids->value];
2090-
} else {
2091-
$values = \is_array($ids) ? $ids : [$ids];
2092-
}
2093-
2094-
if (null === $want) {
2095-
if (!empty($values)) {
2096-
$extid = current($values);
2097-
}
2098-
} else {
2099-
foreach ($values as $id) {
2100-
if ($id && strstr($id, 'ext:'.$want)) {
2101-
if (null === $extid) {
2102-
$extid = str_replace('ext:'.$want.':', '', $id);
2103-
} else {
2104-
if (\is_array($extid)) {
2105-
$extid[] = str_replace('ext:'.$want.':', '', $id);
2106-
} else {
2107-
$extid = [$extid, str_replace('ext:'.$want.':', '', $id)];
2108-
}
2109-
}
2110-
}
2111-
}
2112-
}
2113-
2114-
return $extid;
2080+
$ids = (array) $this->getExternalIDs();
2081+
return array_key_exists($want, $ids) ? $ids[$want] : current($ids);
21152082
}
21162083

21172084
/**

0 commit comments

Comments
 (0)