Changed some InvalidArgumentException to the better suited ValueError

This commit is contained in:
the-djmaze 2023-12-31 13:09:14 +01:00
parent 4d66c02190
commit 4a2de54c3e
15 changed files with 72 additions and 58 deletions

View file

@ -56,7 +56,7 @@ trait Folders
} }
/** /**
* @throws \InvalidArgumentException * @throws \ValueError
* @throws \MailSo\RuntimeException * @throws \MailSo\RuntimeException
* @throws \MailSo\Net\Exceptions\* * @throws \MailSo\Net\Exceptions\*
* @throws \MailSo\Imap\Exceptions\* * @throws \MailSo\Imap\Exceptions\*
@ -64,7 +64,7 @@ trait Folders
public function FolderDelete(string $sFolderName) : void public function FolderDelete(string $sFolderName) : void
{ {
if (!$sFolderName || 'INBOX' === $sFolderName) { if (!$sFolderName || 'INBOX' === $sFolderName) {
throw new \InvalidArgumentException; throw new \ValueError;
} }
$oInfo = $this->hasCapability('IMAP4rev2') $oInfo = $this->hasCapability('IMAP4rev2')
@ -360,7 +360,7 @@ trait Folders
} }
if (!\strlen(\trim($sFolderName))) { if (!\strlen(\trim($sFolderName))) {
throw new \InvalidArgumentException; throw new \ValueError;
} }
$aSelectParams = array(); $aSelectParams = array();

View file

@ -27,7 +27,7 @@ use MailSo\Imap\Enumerations\StoreAction;
trait Messages trait Messages
{ {
/** /**
* @throws \InvalidArgumentException * @throws \ValueError
* @throws \MailSo\RuntimeException * @throws \MailSo\RuntimeException
* @throws \MailSo\Net\Exceptions\* * @throws \MailSo\Net\Exceptions\*
* @throws \MailSo\Imap\Exceptions\* * @throws \MailSo\Imap\Exceptions\*
@ -35,7 +35,7 @@ trait Messages
public function FetchIterate(array $aInputFetchItems, string $sIndexRange, bool $bIndexIsUid) : iterable public function FetchIterate(array $aInputFetchItems, string $sIndexRange, bool $bIndexIsUid) : iterable
{ {
if (!\strlen(\trim($sIndexRange))) { if (!\strlen(\trim($sIndexRange))) {
$this->writeLogException(new \InvalidArgumentException, \LOG_ERR); $this->writeLogException(new \ValueError('$sIndexRange is empty'), \LOG_ERR);
} }
$aReturn = array(); $aReturn = array();
@ -138,14 +138,21 @@ trait Messages
* @param resource $rMessageStream * @param resource $rMessageStream
* *
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
* @throws \ValueError
* @throws \MailSo\RuntimeException * @throws \MailSo\RuntimeException
* @throws \MailSo\Net\Exceptions\* * @throws \MailSo\Net\Exceptions\*
* @throws \MailSo\Imap\Exceptions\* * @throws \MailSo\Imap\Exceptions\*
*/ */
public function MessageAppendStream(string $sFolderName, $rMessageStream, int $iStreamSize, array $aFlagsList = null, int $iDateTime = 0) : ?int public function MessageAppendStream(string $sFolderName, $rMessageStream, int $iStreamSize, array $aFlagsList = null, int $iDateTime = 0) : ?int
{ {
if (!\is_resource($rMessageStream) || !\strlen($sFolderName) || 1 > $iStreamSize) { if (!\is_resource($rMessageStream)) {
throw new \InvalidArgumentException; throw new \InvalidArgumentException('$rMessageStream must be a resource');
}
if (!\strlen($sFolderName)) {
throw new \ValueError('$sFolderName is empty');
}
if (1 > $iStreamSize) {
throw new \ValueError('$iStreamSize must be higher then 0');
} }
$aParams = array( $aParams = array(
@ -202,7 +209,7 @@ trait Messages
*/ */
/** /**
* @throws \InvalidArgumentException * @throws \ValueError
* @throws \MailSo\RuntimeException * @throws \MailSo\RuntimeException
* @throws \MailSo\Net\Exceptions\* * @throws \MailSo\Net\Exceptions\*
* @throws \MailSo\Imap\Exceptions\* * @throws \MailSo\Imap\Exceptions\*
@ -210,7 +217,7 @@ trait Messages
public function MessageCopy(string $sFromFolder, string $sToFolder, SequenceSet $oRange) : ResponseCollection public function MessageCopy(string $sFromFolder, string $sToFolder, SequenceSet $oRange) : ResponseCollection
{ {
if (!$sFromFolder || !$sToFolder || !\count($oRange)) { if (!$sFromFolder || !$sToFolder || !\count($oRange)) {
$this->writeLogException(new \InvalidArgumentException, \LOG_ERR); $this->writeLogException(new \ValueError, \LOG_ERR);
} }
$this->FolderSelect($sFromFolder); $this->FolderSelect($sFromFolder);
@ -222,7 +229,7 @@ trait Messages
} }
/** /**
* @throws \InvalidArgumentException * @throws \ValueError
* @throws \MailSo\RuntimeException * @throws \MailSo\RuntimeException
* @throws \MailSo\Net\Exceptions\* * @throws \MailSo\Net\Exceptions\*
* @throws \MailSo\Imap\Exceptions\* * @throws \MailSo\Imap\Exceptions\*
@ -230,7 +237,7 @@ trait Messages
public function MessageMove(string $sFromFolder, string $sToFolder, SequenceSet $oRange) : void public function MessageMove(string $sFromFolder, string $sToFolder, SequenceSet $oRange) : void
{ {
if (!$sFromFolder || !$sToFolder || !\count($oRange)) { if (!$sFromFolder || !$sToFolder || !\count($oRange)) {
$this->writeLogException(new \InvalidArgumentException, \LOG_ERR); $this->writeLogException(new \ValueError, \LOG_ERR);
} }
if ($this->hasCapability('MOVE')) { if ($this->hasCapability('MOVE')) {
@ -246,7 +253,7 @@ trait Messages
} }
/** /**
* @throws \InvalidArgumentException * @throws \ValueError
* @throws \MailSo\RuntimeException * @throws \MailSo\RuntimeException
* @throws \MailSo\Net\Exceptions\* * @throws \MailSo\Net\Exceptions\*
* @throws \MailSo\Imap\Exceptions\* * @throws \MailSo\Imap\Exceptions\*
@ -254,7 +261,7 @@ trait Messages
public function MessageDelete(string $sFolder, SequenceSet $oRange, bool $bExpungeAll = false) : void public function MessageDelete(string $sFolder, SequenceSet $oRange, bool $bExpungeAll = false) : void
{ {
if (!$sFolder || !\count($oRange)) { if (!$sFolder || !\count($oRange)) {
$this->writeLogException(new \InvalidArgumentException, \LOG_ERR); $this->writeLogException(new \ValueError, \LOG_ERR);
} }
$this->FolderSelect($sFolder); $this->FolderSelect($sFolder);
@ -279,6 +286,7 @@ trait Messages
* @param resource $rMessageStream * @param resource $rMessageStream
* *
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
* @throws \ValueError
* @throws \MailSo\RuntimeException * @throws \MailSo\RuntimeException
* @throws \MailSo\Net\Exceptions\* * @throws \MailSo\Net\Exceptions\*
* @throws \MailSo\Imap\Exceptions\* * @throws \MailSo\Imap\Exceptions\*

View file

@ -112,7 +112,7 @@ trait Metadata
{ {
if ($this->hasCapability('METADATA')) { if ($this->hasCapability('METADATA')) {
if (!$aEntries) { if (!$aEntries) {
throw new \InvalidArgumentException('Wrong argument for SETMETADATA command'); throw new \ValueError('Wrong argument for SETMETADATA command');
} }
$arguments = [$this->EscapeFolderName($sFolderName)]; $arguments = [$this->EscapeFolderName($sFolderName)];

View file

@ -34,12 +34,12 @@ class Folder implements \JsonSerializable
public ?Responses\ACL $myRights = null; public ?Responses\ACL $myRights = null;
/** /**
* @throws \InvalidArgumentException * @throws \ValueError
*/ */
function __construct(string $sFullName, string $sDelimiter = null, array $aAttributes = array()) function __construct(string $sFullName, string $sDelimiter = null, array $aAttributes = array())
{ {
if (!\strlen($sFullName)) { if (!\strlen($sFullName)) {
throw new \InvalidArgumentException; throw new \ValueError;
} }
$this->FullName = $sFullName; $this->FullName = $sFullName;
$this->setDelimiter($sDelimiter); $this->setDelimiter($sDelimiter);

View file

@ -99,7 +99,7 @@ class ImapClient extends \MailSo\Net\NetClient
} }
/** /**
* @throws \InvalidArgumentException * @throws \UnexpectedValueException
* @throws \MailSo\RuntimeException * @throws \MailSo\RuntimeException
* @throws \MailSo\Net\Exceptions\* * @throws \MailSo\Net\Exceptions\*
* @throws \MailSo\Imap\Exceptions\* * @throws \MailSo\Imap\Exceptions\*
@ -123,7 +123,7 @@ class ImapClient extends \MailSo\Net\NetClient
$sLogin = \MailSo\Base\Utils::IdnToAscii(\MailSo\Base\Utils::Trim($sLogin)); $sLogin = \MailSo\Base\Utils::IdnToAscii(\MailSo\Base\Utils::Trim($sLogin));
if (!\strlen($sLogin) || !\strlen($sPassword)) { if (!\strlen($sLogin) || !\strlen($sPassword)) {
$this->writeLogException(new \InvalidArgumentException, \LOG_ERR); $this->writeLogException(new \UnexpectedValueException, \LOG_ERR);
} }
$type = ''; $type = '';
@ -421,7 +421,7 @@ class ImapClient extends \MailSo\Net\NetClient
} }
/** /**
* @throws \InvalidArgumentException * @throws \ValueError
* @throws \MailSo\RuntimeException * @throws \MailSo\RuntimeException
* @throws \MailSo\Net\Exceptions\* * @throws \MailSo\Net\Exceptions\*
* @throws \MailSo\Imap\Exceptions\* * @throws \MailSo\Imap\Exceptions\*
@ -430,7 +430,7 @@ class ImapClient extends \MailSo\Net\NetClient
{ {
$sCommand = \trim($sCommand); $sCommand = \trim($sCommand);
if (!\strlen($sCommand)) { if (!\strlen($sCommand)) {
$this->writeLogException(new \InvalidArgumentException, \LOG_ERR); $this->writeLogException(new \ValueError, \LOG_ERR);
} }
$this->IsConnected(true); $this->IsConnected(true);
@ -454,7 +454,7 @@ class ImapClient extends \MailSo\Net\NetClient
} }
/** /**
* @throws \InvalidArgumentException * @throws \ValueError
* @throws \MailSo\RuntimeException * @throws \MailSo\RuntimeException
* @throws \MailSo\Net\Exceptions\* * @throws \MailSo\Net\Exceptions\*
* @throws \MailSo\Imap\Exceptions\* * @throws \MailSo\Imap\Exceptions\*

View file

@ -118,7 +118,7 @@ class MailClient
public function Message(string $sFolderName, int $iIndex, bool $bIndexIsUid = true, ?\MailSo\Cache\CacheClient $oCacher = null) : ?Message public function Message(string $sFolderName, int $iIndex, bool $bIndexIsUid = true, ?\MailSo\Cache\CacheClient $oCacher = null) : ?Message
{ {
if (1 > $iIndex) { if (1 > $iIndex) {
throw new \InvalidArgumentException; throw new \ValueError;
} }
$this->oImapClient->FolderExamine($sFolderName); $this->oImapClient->FolderExamine($sFolderName);
@ -187,7 +187,7 @@ class MailClient
public function MessageMimeStream($mCallback, string $sFolderName, int $iIndex, string $sMimeIndex) : bool public function MessageMimeStream($mCallback, string $sFolderName, int $iIndex, string $sMimeIndex) : bool
{ {
if (!\is_callable($mCallback)) { if (!\is_callable($mCallback)) {
throw new \InvalidArgumentException; throw new \ValueError;
} }
$this->oImapClient->FolderExamine($sFolderName); $this->oImapClient->FolderExamine($sFolderName);
@ -278,7 +278,7 @@ class MailClient
public function MessageAppendFile(string $sMessageFileName, string $sFolderToSave, array $aAppendFlags = null) : int public function MessageAppendFile(string $sMessageFileName, string $sFolderToSave, array $aAppendFlags = null) : int
{ {
if (!\is_file($sMessageFileName) || !\is_readable($sMessageFileName)) { if (!\is_file($sMessageFileName) || !\is_readable($sMessageFileName)) {
throw new \InvalidArgumentException; throw new \ValueError;
} }
$iMessageStreamSize = \filesize($sMessageFileName); $iMessageStreamSize = \filesize($sMessageFileName);
@ -687,7 +687,7 @@ class MailClient
public function MessageList(MessageListParams $oParams) : MessageCollection public function MessageList(MessageListParams $oParams) : MessageCollection
{ {
if (0 > $oParams->iOffset || 0 > $oParams->iLimit || 999 < $oParams->iLimit) { if (0 > $oParams->iOffset || 0 > $oParams->iLimit || 999 < $oParams->iLimit) {
throw new \InvalidArgumentException; throw new \ValueError;
} }
$sSearch = \trim($oParams->sSearch); $sSearch = \trim($oParams->sSearch);
@ -707,7 +707,7 @@ class MailClient
$oParams->bUseThreads = $oParams->bUseThreads && $this->oImapClient->CapabilityValue('THREAD'); $oParams->bUseThreads = $oParams->bUseThreads && $this->oImapClient->CapabilityValue('THREAD');
// && ($this->oImapClient->hasCapability('THREAD=REFS') || $this->oImapClient->hasCapability('THREAD=REFERENCES') || $this->oImapClient->hasCapability('THREAD=ORDEREDSUBJECT')); // && ($this->oImapClient->hasCapability('THREAD=REFS') || $this->oImapClient->hasCapability('THREAD=REFERENCES') || $this->oImapClient->hasCapability('THREAD=ORDEREDSUBJECT'));
if ($oParams->iThreadUid && !$oParams->bUseThreads) { if ($oParams->iThreadUid && !$oParams->bUseThreads) {
throw new \InvalidArgumentException('THREAD not supported'); throw new \ValueError('THREAD not supported');
} }
if (!$oInfo->MESSAGES || $oParams->iOffset > $oInfo->MESSAGES) { if (!$oInfo->MESSAGES || $oParams->iOffset > $oInfo->MESSAGES) {
@ -851,7 +851,7 @@ class MailClient
public function FindMessageUidByMessageId(string $sFolderName, string $sMessageId) : ?int public function FindMessageUidByMessageId(string $sFolderName, string $sMessageId) : ?int
{ {
if (!\strlen($sMessageId)) { if (!\strlen($sMessageId)) {
throw new \InvalidArgumentException; throw new \ValueError;
} }
$this->oImapClient->FolderExamine($sFolderName); $this->oImapClient->FolderExamine($sFolderName);
@ -892,7 +892,7 @@ class MailClient
} }
/** /**
* @throws \InvalidArgumentException * @throws \ValueError
*/ */
public function FolderCreate(string $sFolderNameInUtf8, string $sFolderParentFullName = '', bool $bSubscribeOnCreation = true, string $sDelimiter = '') : ?\MailSo\Imap\Folder public function FolderCreate(string $sFolderNameInUtf8, string $sFolderParentFullName = '', bool $bSubscribeOnCreation = true, string $sDelimiter = '') : ?\MailSo\Imap\Folder
{ {
@ -900,7 +900,7 @@ class MailClient
$sFolderParentFullName = \trim($sFolderParentFullName); $sFolderParentFullName = \trim($sFolderParentFullName);
if (!\strlen($sFolderNameInUtf8)) { if (!\strlen($sFolderNameInUtf8)) {
throw new \InvalidArgumentException; throw new \ValueError;
} }
if (!\strlen($sDelimiter) || \strlen($sFolderParentFullName)) { if (!\strlen($sDelimiter) || \strlen($sFolderParentFullName)) {
@ -976,13 +976,13 @@ class MailClient
} }
/** /**
* @throws \InvalidArgumentException * @throws \ValueError
* @throws \MailSo\RuntimeException * @throws \MailSo\RuntimeException
*/ */
protected function folderModify(string $sPrevFolderFullName, string $sNewFolderFullName, bool $bSubscribe) : self protected function folderModify(string $sPrevFolderFullName, string $sNewFolderFullName, bool $bSubscribe) : self
{ {
if (!\strlen($sPrevFolderFullName) || !\strlen($sNewFolderFullName)) { if (!\strlen($sPrevFolderFullName) || !\strlen($sNewFolderFullName)) {
throw new \InvalidArgumentException; throw new \ValueError;
} }
$oSubscribedFolders = array(); $oSubscribedFolders = array();

View file

@ -24,12 +24,12 @@ class Email implements \JsonSerializable
private string $sDkimStatus = Enumerations\DkimStatus::NONE; private string $sDkimStatus = Enumerations\DkimStatus::NONE;
/** /**
* @throws \InvalidArgumentException * @throws \ValueError
*/ */
function __construct(string $sEmail, string $sDisplayName = '') function __construct(string $sEmail, string $sDisplayName = '')
{ {
if (!\strlen(\trim($sEmail)) && !\strlen(\trim($sDisplayName))) { if (!\strlen(\trim($sEmail)) && !\strlen(\trim($sDisplayName))) {
throw new \InvalidArgumentException; throw new \ValueError;
} }
$this->sEmail = \MailSo\Base\Utils::IdnToAscii( $this->sEmail = \MailSo\Base\Utils::IdnToAscii(
@ -39,13 +39,13 @@ class Email implements \JsonSerializable
} }
/** /**
* @throws \InvalidArgumentException * @throws \ValueError
*/ */
public static function Parse(string $sEmailAddress) : self public static function Parse(string $sEmailAddress) : self
{ {
$sEmailAddress = \MailSo\Base\Utils::Trim($sEmailAddress); $sEmailAddress = \MailSo\Base\Utils::Trim($sEmailAddress);
if (!\strlen(\trim($sEmailAddress))) { if (!\strlen(\trim($sEmailAddress))) {
throw new \InvalidArgumentException; throw new \ValueError;
} }
$sName = ''; $sName = '';

View file

@ -144,7 +144,7 @@ class EmailCollection extends \MailSo\Base\Collection
$iEmailStartPos = $iCurrentPos + 1; $iEmailStartPos = $iCurrentPos + 1;
} }
catch (\InvalidArgumentException $oException) catch (\Throwable $oException)
{ {
} }
} }
@ -161,7 +161,7 @@ class EmailCollection extends \MailSo\Base\Collection
Email::Parse(\substr($sRawEmails, $iEmailStartPos, $iCurrentPos - $iEmailStartPos)) Email::Parse(\substr($sRawEmails, $iEmailStartPos, $iCurrentPos - $iEmailStartPos))
); );
} }
catch (\InvalidArgumentException $oException) {} catch (\Throwable $oException) {}
} }
} }

View file

@ -71,7 +71,7 @@ abstract class NetClient
} }
/** /**
* @throws \InvalidArgumentException * @throws \ValueError
* @throws \MailSo\RuntimeException * @throws \MailSo\RuntimeException
* @throws \MailSo\Net\Exceptions\SocketAlreadyConnectedException * @throws \MailSo\Net\Exceptions\SocketAlreadyConnectedException
* @throws \MailSo\Net\Exceptions\SocketCanNotConnectToHostException * @throws \MailSo\Net\Exceptions\SocketCanNotConnectToHostException
@ -80,7 +80,7 @@ abstract class NetClient
{ {
$oSettings->host = \trim($oSettings->host); $oSettings->host = \trim($oSettings->host);
if (!\strlen($oSettings->host) || 0 > $oSettings->port || 65535 < $oSettings->port) { if (!\strlen($oSettings->host) || 0 > $oSettings->port || 65535 < $oSettings->port) {
$this->writeLogException(new \InvalidArgumentException, \LOG_ERR); $this->writeLogException(new \ValueError, \LOG_ERR);
} }
if ($this->IsConnected()) { if ($this->IsConnected()) {

View file

@ -108,6 +108,7 @@ class SieveClient extends \MailSo\Net\NetClient
$this->StartTLS(); $this->StartTLS();
return $this->Login($oSettings); return $this->Login($oSettings);
} }
// $this->writeLogException(new \UnexpectedValueException('No supported SASL mechanism found'), \LOG_ERR);
$this->writeLogException(new \MailSo\Sieve\Exceptions\LoginException, \LOG_ERR); $this->writeLogException(new \MailSo\Sieve\Exceptions\LoginException, \LOG_ERR);
} }

View file

@ -772,7 +772,7 @@ class PdoAddressBook
} }
/** /**
* @throws \InvalidArgumentException * @throws \ValueError
*/ */
public function GetSuggestions(string $sSearch, int $iLimit = 20) : array public function GetSuggestions(string $sSearch, int $iLimit = 20) : array
{ {
@ -782,7 +782,7 @@ class PdoAddressBook
$sSearch = \trim($sSearch); $sSearch = \trim($sSearch);
if (!\strlen($sSearch)) { if (!\strlen($sSearch)) {
throw new \InvalidArgumentException('Empty Search argument'); throw new \ValueError('Empty Search argument');
} }
$sTypes = \implode(',', static::$aSearchInFields); $sTypes = \implode(',', static::$aSearchInFields);
@ -936,6 +936,9 @@ class PdoAddressBook
return array(); return array();
} }
/**
* @throws \ValueError
*/
public function IncFrec(array $aEmails, bool $bCreateAuto = true) : bool public function IncFrec(array $aEmails, bool $bCreateAuto = true) : bool
{ {
if (1 > $this->iUserID) { if (1 > $this->iUserID) {
@ -959,7 +962,7 @@ class PdoAddressBook
}); });
if (!\count($aEmailsObjects)) { if (!\count($aEmailsObjects)) {
throw new \InvalidArgumentException('Empty Emails argument'); throw new \ValueError('Empty Emails argument');
} }
$aExists = array(); $aExists = array();
@ -1302,13 +1305,16 @@ SQLITEINITIAL;
return $this->settings; return $this->settings;
} }
/**
* @throws \ValueError
*/
protected function getUserId(string $sEmail, bool $bSkipInsert = false, bool $bCache = true) : int protected function getUserId(string $sEmail, bool $bSkipInsert = false, bool $bCache = true) : int
{ {
static $aCache = array(); static $aCache = array();
$sEmail = \MailSo\Base\Utils::IdnToAscii(\trim($sEmail), true); $sEmail = \MailSo\Base\Utils::IdnToAscii(\trim($sEmail), true);
if (empty($sEmail)) { if (empty($sEmail)) {
throw new \InvalidArgumentException('Empty Email argument'); throw new \ValueError('Empty Email argument');
} }
if ($bCache && isset($aCache[$sEmail])) { if ($bCache && isset($aCache[$sEmail])) {

View file

@ -210,7 +210,7 @@ abstract class Crypt
) /* : string|false */ ) /* : string|false */
{ {
if (!$data || !$iv) { if (!$data || !$iv) {
throw new \InvalidArgumentException('$data or $iv is empty string'); throw new \ValueError('$data or $iv is empty string');
} }
if (!\is_callable('openssl_decrypt')) { if (!\is_callable('openssl_decrypt')) {
throw new \Exception('openssl_decrypt not callable'); throw new \Exception('openssl_decrypt not callable');
@ -237,7 +237,7 @@ abstract class Crypt
) : string ) : string
{ {
if (!$data || !$iv) { if (!$data || !$iv) {
throw new \InvalidArgumentException('$data or $iv is empty string'); throw new \ValueError('$data or $iv is empty string');
} }
if (!\is_callable('openssl_encrypt')) { if (!\is_callable('openssl_encrypt')) {
throw new \Exception('openssl_encrypt not callable'); throw new \Exception('openssl_encrypt not callable');
@ -265,7 +265,7 @@ abstract class Crypt
) /* : mixed */ ) /* : mixed */
{ {
if (!$data || !$salt) { if (!$data || !$salt) {
throw new \InvalidArgumentException('$data or $salt is empty string'); throw new \ValueError('$data or $salt is empty string');
} }
$key = $salt . static::Passphrase($key); $key = $salt . static::Passphrase($key);
return \is_callable('xxtea_decrypt') return \is_callable('xxtea_decrypt')
@ -282,7 +282,7 @@ abstract class Crypt
) : string ) : string
{ {
if (!$data || !$salt) { if (!$data || !$salt) {
throw new \InvalidArgumentException('$data or $salt is empty string'); throw new \ValueError('$data or $salt is empty string');
} }
$key = $salt . static::Passphrase($key); $key = $salt . static::Passphrase($key);
$result = \is_callable('xxtea_encrypt') $result = \is_callable('xxtea_encrypt')

View file

@ -32,7 +32,7 @@ class Client
function __construct(array $settings) function __construct(array $settings)
{ {
if (!isset($settings['baseUri'])) { if (!isset($settings['baseUri'])) {
throw new \InvalidArgumentException('A baseUri must be provided'); throw new \ValueError('A baseUri must be provided');
} }
$this->baseUri = $settings['baseUri']; $this->baseUri = $settings['baseUri'];
@ -114,7 +114,7 @@ class Client
foreach ($properties as $property) { foreach ($properties as $property) {
if (!\preg_match('/^{([^}]*)}(.*)$/', $property, $match)) { if (!\preg_match('/^{([^}]*)}(.*)$/', $property, $match)) {
throw new \InvalidArgumentException('\'' . $property . '\' is not a valid clark-notation formatted string'); throw new \ValueError('\'' . $property . '\' is not a valid clark-notation formatted string');
} }
if ('DAV:' === $match[1]) { if ('DAV:' === $match[1]) {
$body .= "<d:{$match[2]}/>"; $body .= "<d:{$match[2]}/>";

View file

@ -31,7 +31,7 @@ abstract class JWT
$timestamp = $timestamp ?: \time(); $timestamp = $timestamp ?: \time();
if (empty($key)) { if (empty($key)) {
throw new \InvalidArgumentException('Key may not be empty'); throw new \ValueError('Key may not be empty');
} }
$jwt = \explode('.', $jwt); $jwt = \explode('.', $jwt);
@ -39,7 +39,6 @@ abstract class JWT
throw new \UnexpectedValueException('Wrong number of segments'); throw new \UnexpectedValueException('Wrong number of segments');
} }
try { try {
;
$header = static::jsonDecode($jwt[0]); $header = static::jsonDecode($jwt[0]);
} catch (\Throwable $e) { } catch (\Throwable $e) {
throw new \UnexpectedValueException("Invalid header encoding ({$e->getMessage()})"); throw new \UnexpectedValueException("Invalid header encoding ({$e->getMessage()})");
@ -137,13 +136,13 @@ abstract class JWT
if ($free_key) { if ($free_key) {
$key = \openssl_pkey_get_private($key, $passphrase); $key = \openssl_pkey_get_private($key, $passphrase);
if (!$key) { if (!$key) {
throw new \InvalidArgumentException('Invalid key, reason: ' . \openssl_error_string()); throw new \ValueError('Invalid key, reason: ' . \openssl_error_string());
} }
} }
try { try {
$details = \openssl_pkey_get_details($key); $details = \openssl_pkey_get_details($key);
if (!isset($details['key']) || OPENSSL_KEYTYPE_RSA !== $details['type']) { if (!isset($details['key']) || OPENSSL_KEYTYPE_RSA !== $details['type']) {
throw new \InvalidArgumentException('Key is not compatible with RSA signatures'); throw new \ValueError('Key is not compatible with RSA signatures');
} }
$signature = ''; $signature = '';
if (!\openssl_sign($msg, $signature, $key, 'SHA'.\substr($alg,2))) { if (!\openssl_sign($msg, $signature, $key, 'SHA'.\substr($alg,2))) {
@ -165,7 +164,7 @@ abstract class JWT
} }
default: default:
throw new \InvalidArgumentException("Algorithm '{$alg}' not supported"); throw new \ValueError("Algorithm '{$alg}' not supported");
} }
} }
@ -191,13 +190,13 @@ abstract class JWT
if ($free_key) { if ($free_key) {
$key = \openssl_pkey_get_public($key); $key = \openssl_pkey_get_public($key);
if (!$key) { if (!$key) {
throw new \InvalidArgumentException('Invalid key, reason: ' . openssl_error_string()); throw new \ValueError('Invalid key, reason: ' . openssl_error_string());
} }
} }
try { try {
$details = \openssl_pkey_get_details($key); $details = \openssl_pkey_get_details($key);
if (!isset($details['key']) || OPENSSL_KEYTYPE_RSA !== $details['type']) { if (!isset($details['key']) || OPENSSL_KEYTYPE_RSA !== $details['type']) {
throw new \InvalidArgumentException('Key is not compatible with RSA signatures'); throw new \ValueError('Key is not compatible with RSA signatures');
} }
$success = \openssl_verify($msg, $signature, $key, 'SHA'.\substr($alg,2)); $success = \openssl_verify($msg, $signature, $key, 'SHA'.\substr($alg,2));
if (-1 == $success) { if (-1 == $success) {
@ -223,7 +222,7 @@ abstract class JWT
// case 'ES384': // case 'ES384':
// case 'ES512': // case 'ES512':
default: default:
throw new \InvalidArgumentException("Algorithm '{$alg}' not supported"); throw new \ValueError("Algorithm '{$alg}' not supported");
} }
} }

View file

@ -26,7 +26,7 @@ abstract class SASL
return new $class($m[2] ?? ''); return new $class($m[2] ?? '');
} }
} }
throw new \Exception("Unsupported SASL mechanism type: {$type}"); throw new \ValueError("Unsupported SASL mechanism type: {$type}");
} }
public static function isSupported(string $type) : bool public static function isSupported(string $type) : bool