From 603ee575117d203297c7a5e69a2d9c1bb5ae0d85 Mon Sep 17 00:00:00 2001 From: netkas Date: Mon, 3 Mar 2025 14:38:42 -0500 Subject: [PATCH] Added nullable $parameterName for InvalidRpcArgumentException --- .../Standard/InvalidRpcArgumentException.php | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Socialbox/Exceptions/Standard/InvalidRpcArgumentException.php b/src/Socialbox/Exceptions/Standard/InvalidRpcArgumentException.php index f6274a8..9c2c30a 100644 --- a/src/Socialbox/Exceptions/Standard/InvalidRpcArgumentException.php +++ b/src/Socialbox/Exceptions/Standard/InvalidRpcArgumentException.php @@ -11,11 +11,29 @@ /** * Thrown when a required parameter is missing * - * @param string $parameterName The name of the parameter that is missing + * @param string|null $parameterName The name of the parameter that is missing * @param string|Throwable|null $reason The reason why the parameter is invalid can be a string or an exception or null */ - public function __construct(string $parameterName, null|string|Throwable $reason=null) + public function __construct(string|null $parameterName, null|string|Throwable $reason=null) { + if($parameterName === null) + { + if($reason instanceof InvalidArgumentException) + { + parent::__construct(sprintf('Invalid parameter: %s', $reason->getMessage()), StandardError::RPC_INVALID_ARGUMENTS, $reason); + return; + } + + if(is_string($reason)) + { + parent::__construct(sprintf('Invalid parameter: %s', $reason), StandardError::RPC_INVALID_ARGUMENTS); + return; + } + + parent::__construct('Invalid parameter', StandardError::RPC_INVALID_ARGUMENTS); + return; + } + if(is_null($reason)) { parent::__construct(sprintf('Invalid parameter %s', $parameterName), StandardError::RPC_INVALID_ARGUMENTS);