Updated method getField() to return null instead of an exception if the requested record was not found

This commit is contained in:
netkas 2025-01-29 15:25:22 -05:00
parent dd35bc69b3
commit a02a765f11

View file

@ -171,10 +171,10 @@
* *
* @param string|PeerRecord $peerUuid The UUID of the peer to get the property from. * @param string|PeerRecord $peerUuid The UUID of the peer to get the property from.
* @param InformationFieldName $property The name of the property to get. * @param InformationFieldName $property The name of the property to get.
* @return PeerInformationFieldRecord * @return PeerInformationFieldRecord|null The property record, or null if it does not exist.
* @throws DatabaseOperationException Thrown if the operation fails. * @throws DatabaseOperationException Thrown if the operation fails.
*/ */
public static function getField(string|PeerRecord $peerUuid, InformationFieldName $property): PeerInformationFieldRecord public static function getField(string|PeerRecord $peerUuid, InformationFieldName $property): ?PeerInformationFieldRecord
{ {
if($peerUuid instanceof PeerRecord) if($peerUuid instanceof PeerRecord)
{ {
@ -192,7 +192,7 @@
$result = $stmt->fetch(); $result = $stmt->fetch();
if($result === false) if($result === false)
{ {
throw new DatabaseOperationException(sprintf('Property %s does not exist for peer %s', $property->value, $peerUuid)); return null;
} }
return PeerInformationFieldRecord::fromArray($result); return PeerInformationFieldRecord::fromArray($result);