Refactor SettingsUpdateInformationField and PeerInformationManager to enhance UUID validation and improve error handling for property values

https://github.com/nosial/Socialbox-PHP/issues/68
This commit is contained in:
netkas 2025-03-12 14:22:19 -04:00
parent 2967c87990
commit d47251c251
Signed by: netkas
GPG key ID: 4D8629441B76E4CC
2 changed files with 22 additions and 7 deletions

View file

@ -27,7 +27,8 @@
{
throw new MissingRpcArgumentException('field');
}
$fieldName = InformationFieldName::tryFrom(strtoupper($rpcRequest->getParameter('field')));
$fieldName = InformationFieldName::tryFrom(strtoupper((string)$rpcRequest->getParameter('field')));
if($fieldName === null)
{
throw new InvalidRpcArgumentException('field');
@ -38,11 +39,7 @@
{
throw new MissingRpcArgumentException('value');
}
$value = $rpcRequest->getParameter('value');
if(!$fieldName->validate($value))
{
throw new InvalidRpcArgumentException('value');
}
$value = (string)$rpcRequest->getParameter('value');
try
{

View file

@ -31,6 +31,15 @@
{
$peerUuid = $peerUuid->getUuid();
}
elseif(!Validator::validateUuid($peerUuid))
{
throw new InvalidArgumentException('The given internal peer UUID is not a valid UUID V4');
}
if(!$property->validate($value))
{
throw new InvalidArgumentException(sprintf('The given value %s is not valid for property %s', $value, $property->value));
}
if($privacyState === null)
{
@ -79,10 +88,19 @@
{
$peerUuid = $peerUuid->getUuid();
}
elseif(!Validator::validateUuid($peerUuid))
{
throw new InvalidArgumentException('The given internal peer UUID is not a valid UUID V4');
}
if(!self::fieldExists($peerUuid, $property))
{
throw new DatabaseOperationException(sprintf('Cannot to update property %s for peer %s, property does not exist', $property->value, $peerUuid));
self::addField($peerUuid, $property, $value);
}
if(!$property->validate($value))
{
throw new InvalidArgumentException(sprintf('The given value %s is not valid for property %s', $value, $property->value));
}
try