Refactor SettingsUpdateInformationPrivacy and PeerInformationManager to ensure proper UUID validation and improve error handling for privacy state updates

https://github.com/nosial/Socialbox-PHP/issues/69
This commit is contained in:
netkas 2025-03-12 14:16:34 -04:00
parent 9c8945141c
commit 2967c87990
Signed by: netkas
GPG key ID: 4D8629441B76E4CC
2 changed files with 16 additions and 8 deletions

View file

@ -2,9 +2,11 @@
namespace Socialbox\Managers;
use InvalidArgumentException;
use PDOException;
use Socialbox\Classes\Configuration;
use Socialbox\Classes\Database;
use Socialbox\Classes\Validator;
use Socialbox\Enums\PrivacyState;
use Socialbox\Enums\Types\InformationFieldName;
use Socialbox\Exceptions\DatabaseOperationException;
@ -113,10 +115,14 @@
{
$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 \InvalidArgumentException(sprintf('Cannot update privacy state, the requested property %s does not exist with %s', $property->value, $peerUuid));
throw new InvalidArgumentException(sprintf('Cannot update privacy state, the requested property %s does not exist with %s', $property->value, $peerUuid));
}
try
@ -149,6 +155,10 @@
{
$peerUuid = $peerUuid->getUuid();
}
elseif(!Validator::validateUuid($peerUuid))
{
throw new InvalidArgumentException('The given internal peer UUID is not a valid UUID V4');
}
try
{
@ -253,7 +263,6 @@
}
$results = [];
/** @var PrivacyState $privacyState */
foreach($privacyFilters as $privacyState)
{
try