From df96d894a8389e1dca2ce0a1f847c8a78652b8ab Mon Sep 17 00:00:00 2001 From: netkas Date: Thu, 13 Mar 2025 00:25:13 -0400 Subject: [PATCH] Refactor ResolvePeer to improve peer address handling by removing unnecessary exception handling and ensuring proper type casting for the peer parameter. https://github.com/nosial/Socialbox-PHP/issues/43 --- .../Classes/StandardMethods/Core/ResolvePeer.php | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/Socialbox/Classes/StandardMethods/Core/ResolvePeer.php b/src/Socialbox/Classes/StandardMethods/Core/ResolvePeer.php index 5c728e2..8ed8206 100644 --- a/src/Socialbox/Classes/StandardMethods/Core/ResolvePeer.php +++ b/src/Socialbox/Classes/StandardMethods/Core/ResolvePeer.php @@ -2,7 +2,6 @@ namespace Socialbox\Classes\StandardMethods\Core; - use InvalidArgumentException; use Socialbox\Abstracts\Method; use Socialbox\Enums\ReservedUsernames; use Socialbox\Enums\StandardError; @@ -30,20 +29,13 @@ } // Parse the peer address - try - { - $peerAddress = PeerAddress::fromAddress($rpcRequest->getParameter('peer')); - } - catch(InvalidArgumentException $e) - { - throw new StandardRpcException('Peer Address Error: ' . $e->getMessage(), StandardError::RPC_INVALID_ARGUMENTS, $e); - } + $peerAddress = PeerAddress::fromAddress((string)$rpcRequest->getParameter('peer')); // Check if host is making the request & the identifier is not empty try { $identifyAs = null; - if ($request->getPeer()->getUsername() == ReservedUsernames::HOST && $request->getIdentifyAs() != null) + if ($request->getPeer()->getUsername() === ReservedUsernames::HOST->value && $request->getIdentifyAs() !== null) { $identifyAs = $request->getIdentifyAs(); }