use assertion library

This commit is contained in:
Daniel Seifert 2023-02-02 00:18:09 +01:00
parent 5683c6fd6e
commit 3d0578bd9a
Signed by: DanielS
GPG Key ID: 6A513E13AEE66170
4 changed files with 20 additions and 27 deletions

View File

@ -21,11 +21,12 @@
"GPL-3.0-or-later"
],
"require": {
"php": "^7.1 || ^8.0",
"oxid-esales/oxideshop-ce": "~6.7.0 || ~6.9.0 || 6.10 - 6.13",
"d3/linkmobility-php-client": "^1.2.0 || ^2.0.0",
"d3/oxid-dic-handler": "^1.0",
"d3/testingtools": "^1.1"
"php": "^7.1 || ^8.0",
"oxid-esales/oxideshop-ce": "~6.7.0 || ~6.9.0 || 6.10 - 6.13",
"d3/linkmobility-php-client": "^1.2.0 || ^2.0.0",
"d3/oxid-dic-handler": "^1.0",
"d3/testingtools": "^1.1",
"beberlei/assert": "^3.3"
},
"require-dev": {
"oxid-esales/oxideshop-ce": "~6.10.0",

View File

@ -15,6 +15,9 @@ declare(strict_types=1);
namespace D3\Linkmobility4OXID\Application\Controller\Admin;
use Assert\Assert;
use Assert\AssertionFailedException;
use Assert\InvalidArgumentException;
use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
use D3\Linkmobility4OXID\Application\Model\Exceptions\successfullySentException;
use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms;
@ -24,7 +27,6 @@ use D3\LinkmobilityClient\Response\ResponseInterface;
use D3\LinkmobilityClient\ValueObject\Recipient;
use D3\TestingTools\Production\IsMockable;
use Exception;
use InvalidArgumentException;
use OxidEsales\Eshop\Application\Controller\Admin\AdminController;
use OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\Eshop\Core\Language;
@ -125,7 +127,7 @@ class AdminOrder extends AdminController
try {
$utilsView->addErrorToDisplay($this->sendMessage());
} catch (InvalidArgumentException $e) {
} catch (AssertionFailedException $e) {
$utilsView->addErrorToDisplay($e->getMessage());
}
}
@ -140,14 +142,8 @@ class AdminOrder extends AdminController
$request = d3GetOxidDIC()->get('d3ox.linkmobility.'.Request::class);
$messageBody = $request->getRequestEscapedParameter('messagebody');
if (false === is_string($messageBody) || strlen(trim($messageBody)) <= 1) {
/** @var InvalidArgumentException $exc */
$exc = oxNew(
InvalidArgumentException::class,
Registry::getLang()->translateString('D3LM_EXC_MESSAGE_NO_LENGTH')
);
throw $exc;
}
$excMessage = Registry::getLang()->translateString('D3LM_EXC_MESSAGE_NO_LENGTH');
Assert::that($messageBody)->string($excMessage)->minLength(2, $excMessage);
return $messageBody;
}

View File

@ -15,6 +15,9 @@ declare(strict_types=1);
namespace D3\Linkmobility4OXID\Application\Controller\Admin;
use Assert\Assert;
use Assert\AssertionFailedException;
use Assert\InvalidArgumentException;
use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
use D3\Linkmobility4OXID\Application\Model\Exceptions\successfullySentException;
use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms;
@ -23,7 +26,6 @@ use D3\LinkmobilityClient\LoggerHandler;
use D3\LinkmobilityClient\Response\ResponseInterface;
use D3\LinkmobilityClient\ValueObject\Recipient;
use Exception;
use InvalidArgumentException;
use OxidEsales\Eshop\Application\Controller\Admin\AdminController;
use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\Language;
@ -128,7 +130,7 @@ class AdminUser extends AdminController
try {
$utilsView->addErrorToDisplay($this->sendMessage());
} catch (InvalidArgumentException $e) {
} catch (AssertionFailedException $e) {
$utilsView->addErrorToDisplay($e->getMessage());
}
}
@ -143,14 +145,8 @@ class AdminUser extends AdminController
$request = d3GetOxidDIC()->get('d3ox.linkmobility.'.Request::class);
$messageBody = $request->getRequestEscapedParameter('messagebody');
if (false === is_string($messageBody) || strlen(trim($messageBody)) <= 1) {
/** @var InvalidArgumentException $exc */
$exc = oxNew(
InvalidArgumentException::class,
Registry::getLang()->translateString('D3LM_EXC_MESSAGE_NO_LENGTH')
);
throw $exc;
}
$excMessage = Registry::getLang()->translateString('D3LM_EXC_MESSAGE_NO_LENGTH');
Assert::that($messageBody)->string($excMessage)->minLength(2, $excMessage);
return $messageBody;
}

View File

@ -15,6 +15,7 @@ declare(strict_types=1);
namespace D3\Linkmobility4OXID\Application\Model\MessageTypes;
use Assert\AssertionFailedException;
use D3\Linkmobility4OXID\Application\Model\Configuration;
use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
use D3\Linkmobility4OXID\Application\Model\MessageClient;
@ -33,7 +34,6 @@ use D3\LinkmobilityClient\ValueObject\Recipient;
use D3\LinkmobilityClient\ValueObject\Sender;
use Exception;
use GuzzleHttp\Exception\GuzzleException;
use InvalidArgumentException;
use libphonenumber\NumberParseException;
use OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\Eshop\Application\Model\User;
@ -143,7 +143,7 @@ class Sms extends AbstractMessage
$this->response = $response = $this->submitMessage($recipientsList);
return $response->isSuccessful();
} catch (GuzzleException|InvalidArgumentException $e) {
} catch (GuzzleException|AssertionFailedException $e) {
$this->getLogger()->error($e->getMessage());
// Oxid does not accept throwable interface only exceptions according to definition
/** @var UtilsView $utilsView */