Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

Commit

Permalink
DHLGW-148: Fix leaking InvalidArgumentException, make exceptions more…
Browse files Browse the repository at this point in the history
… verbose
  • Loading branch information
Max Melzer committed Sep 24, 2018
1 parent 8707ce0 commit b1dac35
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cache:
- vendor/

variables:
MODULE_VERSION: "1.0.0"
MODULE_VERSION: "1.0.1"
MODULE_NAME: "Dhl_SdkApiExpress"

before_script:
Expand Down
1 change: 1 addition & 0 deletions Webservice/Adapter/RateServiceAdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface RateServiceAdapterInterface
*
* @throws SoapException
* @throws \Dhl\Express\Exception\RateRequestException
* @throws \InvalidArgumentException
*/
public function collectRates(RateRequestInterface $request);
}
12 changes: 10 additions & 2 deletions Webservice/Soap/RateServiceAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Dhl\Express\Webservice\Soap;

use Dhl\Express\Api\Data\RateRequestInterface;
use Dhl\Express\Exception\RateRequestException;
use Dhl\Express\Exception\SoapException;
use Dhl\Express\Webservice\Adapter\RateServiceAdapterInterface;
use Dhl\Express\Webservice\Adapter\TraceableInterface;
Expand Down Expand Up @@ -56,11 +57,18 @@ public function __construct(
}

/**
* {@inheritdoc}
* @param RateRequestInterface $request
* @return \Dhl\Express\Api\Data\RateResponseInterface
* @throws SoapException
* @throws \Dhl\Express\Exception\RateRequestException
*/
public function collectRates(RateRequestInterface $request)
{
$soapRequest = $this->requestMapper->map($request);
try {
$soapRequest = $this->requestMapper->map($request);
} catch (\InvalidArgumentException $e) {
throw new RateRequestException($e->getMessage());
}

try {
$soapResponse = $this->client->__soapCall('getRateRequest', [$soapRequest]);
Expand Down
7 changes: 5 additions & 2 deletions Webservice/Soap/Type/Common/AlphaNumeric.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,22 @@ class AlphaNumeric implements ValueInterface
* Constructor.
*
* @param string $value The value
* @throws \InvalidArgumentException
*
*/
public function __construct($value)
{
if (\strlen($value) < static::MIN_LENGTH) {
throw new \InvalidArgumentException(
'Only values with a minimum length of ' . static::MIN_LENGTH . ' characters are allowed'
'Invalid argument for ' . get_class($this) . ': Only values with a minimum length of ' .
static::MIN_LENGTH . ' characters are allowed'
);
}

if (\strlen($value) > static::MAX_LENGTH) {
throw new \InvalidArgumentException(
'Only values with a maximum length of ' . static::MAX_LENGTH . ' characters are allowed'
'Invalid argument for ' . get_class($this) . ': Only values with a maximum length of ' .
static::MAX_LENGTH . ' characters are allowed'
);
}

Expand Down
2 changes: 2 additions & 0 deletions Webservice/Soap/Type/Common/Billing.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Billing
* @param string $shipperAccountNumber The shipper account number
* @param string $shippingPaymentType The shipping payment type
* @param string $billingAccountNumber The billing account number (Required if payment type is R or T)
* @throws \InvalidArgumentException
*
*/
public function __construct($shipperAccountNumber, $shippingPaymentType, $billingAccountNumber = null)
Expand Down Expand Up @@ -82,6 +83,7 @@ public function getShipperAccountNumber()
* Sets the shipper account number.
*
* @param string $shipperAccountNumber The shipper account number
* @throws \InvalidArgumentException
*
* @return self
*/
Expand Down
2 changes: 1 addition & 1 deletion Webservice/Soap/Type/Common/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Content implements ValueInterface
public function __construct($value = self::DOCUMENTS)
{
if (!\in_array($value, [self::DOCUMENTS, self::NON_DOCUMENTS], true)) {
throw new \InvalidArgumentException('Argument must be either "DOCUMENTS" or "NON_DOCUMENTS"');
throw new \InvalidArgumentException('Content type must be either "DOCUMENTS" or "NON_DOCUMENTS"');
}

$this->value = $value;
Expand Down
5 changes: 4 additions & 1 deletion Webservice/Soap/Type/Common/CurrencyCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ class CurrencyCode implements ValueInterface
public function __construct($value)
{
if (\strlen($value) !== self::NUMBER_OF_CHARS) {
throw new \InvalidArgumentException('The argument must be a three letter currency code');
throw new \InvalidArgumentException(
'Invalid argument for ' . get_class($this) .
': The argument must be a three letter currency code'
);
}

$this->value = $value;
Expand Down
4 changes: 3 additions & 1 deletion Webservice/Soap/Type/RateRequest/RequestedShipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,13 +419,15 @@ public function getAccount()
/**
* Sets the account number.
*
* @param string $account The account number
* @param string $account The account number
* @throws \InvalidArgumentException
*
* @return self
*/
public function setAccount($account)
{
$this->Account = new Account($account);

return $this;
}

Expand Down

0 comments on commit b1dac35

Please sign in to comment.