diff --git a/psalm.xml b/psalm.xml
new file mode 100644
index 0000000..30258a7
--- /dev/null
+++ b/psalm.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
diff --git a/src/AWS/AWS.php b/src/AWS/AWS.php
index 1ab9411..92ffeda 100644
--- a/src/AWS/AWS.php
+++ b/src/AWS/AWS.php
@@ -155,7 +155,7 @@ class AWS
'Service' => $k_service_hexis,
]]);
- $url = 'https://' . (string)$endpoint . '/' . $service_operation;
+ $url = 'https://' . $endpoint . '/' . $service_operation;
$headers = $this->buildHeaders($payload, $authorization_value, $date_time_string, $service_target);
return (new Client())->request($url, $headers, $payload);
}
@@ -332,7 +332,7 @@ class AWS
'value' =>
[
'currencyCode' => $this->config->getCurrency(),
- 'amount' => (float)$amount
+ 'amount' => $amount
]
];
return (json_encode($payload)) ?: '';
diff --git a/src/Client/Client.php b/src/Client/Client.php
index 6002075..c4281b1 100644
--- a/src/Client/Client.php
+++ b/src/Client/Client.php
@@ -92,7 +92,6 @@ class Client implements ClientInterface
$message = 'Could not connect to AWS (' . $url . '). Please check your '
. 'internet connection and try again. [' . $message . ']';
break;
- case CURLE_SSL_CACERT:
case CURLE_SSL_PEER_CERTIFICATE:
$message = 'Could not verify AWS SSL certificate. Please make sure '
. 'that your network is not intercepting certificates. '
diff --git a/src/Config/Config.php b/src/Config/Config.php
index 00e8ed5..bd2c515 100644
--- a/src/Config/Config.php
+++ b/src/Config/Config.php
@@ -7,27 +7,27 @@ class Config implements ConfigInterface
/**
* @var string
*/
- private $endpoint;
+ private $endpoint = '';
/**
* @var string
*/
- private $access_key;
+ private $access_key = '';
/**
* @var string
*/
- private $secret_key;
+ private $secret_key = '';
/**
* @var string
*/
- private $partner_id;
+ private $partner_id = '';
/**
* @var string
*/
- private $currency;
+ private $currency = '';
/**
* @var bool
*/
- private $debug;
+ private $debug = false;
/**
* @param string|null $key
@@ -44,12 +44,36 @@ class Config implements ConfigInterface
?string $currency,
?bool $debug,
) {
- $this->setAccessKey(($key) ?: $this->parseEnv('AWS_GIFT_CARD_KEY')); /** @phpstan-ignore-line */
- $this->setSecret(($secret) ?: $this->parseEnv('AWS_GIFT_CARD_SECRET')); /** @phpstan-ignore-line */
- $this->setPartner(($partner) ?: $this->parseEnv('AWS_GIFT_CARD_PARTNER_ID')); /** @phpstan-ignore-line */
- $this->setEndpoint(($endpoint) ?: $this->parseEnv('AWS_GIFT_CARD_ENDPOINT')); /** @phpstan-ignore-line */
- $this->setCurrency(($currency) ?: $this->parseEnv('AWS_GIFT_CARD_CURRENCY')); /** @phpstan-ignore-line */
- $this->setDebug(($debug) ?: $this->parseEnv('AWS_DEBUG')); /** @phpstan-ignore-line */
+ /**
+ * @psalm-suppress InvalidScalarArgument
+ * @phpstan-ignore-next-line
+ */
+ $this->setAccessKey(($key) ?: $this->parseEnv('AWS_GIFT_CARD_KEY'));
+ /**
+ * @psalm-suppress InvalidScalarArgument
+ * @phpstan-ignore-next-line
+ */
+ $this->setSecret(($secret) ?: $this->parseEnv('AWS_GIFT_CARD_SECRET'));
+ /**
+ * @psalm-suppress InvalidScalarArgument
+ * @phpstan-ignore-next-line
+ */
+ $this->setPartner(($partner) ?: $this->parseEnv('AWS_GIFT_CARD_PARTNER_ID'));
+ /**
+ * @psalm-suppress InvalidScalarArgument
+ * @phpstan-ignore-next-line
+ */
+ $this->setEndpoint(($endpoint) ?: $this->parseEnv('AWS_GIFT_CARD_ENDPOINT'));
+ /**
+ * @psalm-suppress InvalidScalarArgument
+ * @phpstan-ignore-next-line
+ */
+ $this->setCurrency(($currency) ?: $this->parseEnv('AWS_GIFT_CARD_CURRENCY'));
+ /**
+ * @psalm-suppress InvalidScalarArgument
+ * @phpstan-ignore-next-line
+ */
+ $this->setDebug(($debug) ?: $this->parseEnv('AWS_DEBUG'));
}
/**
@@ -80,9 +104,9 @@ class Config implements ConfigInterface
}
/**
- * @return string|null
+ * @return string
*/
- public function getEndpoint(): ?string
+ public function getEndpoint(): string
{
return $this->endpoint;
}
@@ -100,9 +124,9 @@ class Config implements ConfigInterface
}
/**
- * @return string|null
+ * @return string
*/
- public function getAccessKey(): ?string
+ public function getAccessKey(): string
{
return $this->access_key;
}
@@ -119,9 +143,9 @@ class Config implements ConfigInterface
}
/**
- * @return string|null
+ * @return string
*/
- public function getSecret(): ?string
+ public function getSecret(): string
{
return $this->secret_key;
}
@@ -138,9 +162,9 @@ class Config implements ConfigInterface
}
/**
- * @return string|null
+ * @return string
*/
- public function getCurrency(): ?string
+ public function getCurrency(): string
{
return $this->currency;
}
@@ -158,9 +182,9 @@ class Config implements ConfigInterface
}
/**
- * @return string|null
+ * @return string
*/
- public function getPartner(): ?string
+ public function getPartner(): string
{
return $this->partner_id;
}
diff --git a/src/Config/ConfigInterface.php b/src/Config/ConfigInterface.php
index 6673130..2acc93a 100644
--- a/src/Config/ConfigInterface.php
+++ b/src/Config/ConfigInterface.php
@@ -5,68 +5,68 @@ namespace gullevek\AmazonIncentives\Config;
interface ConfigInterface
{
/**
- * @return string|null
+ * @return string
*/
- public function getEndpoint(): ?string;
+ public function getEndpoint(): string;
/**
* @param string $endpoint
- * @return $this
+ * @return ConfigInterface
*/
public function setEndpoint(string $endpoint): ConfigInterface;
/**
- * @return string|null
+ * @return string
*/
- public function getAccessKey(): ?string;
+ public function getAccessKey(): string;
/**
* @param string $key
- * @return $this
+ * @return ConfigInterface
*/
public function setAccessKey(string $key): ConfigInterface;
/**
- * @return string|null
+ * @return string
*/
- public function getSecret(): ?string;
+ public function getSecret(): string;
/**
* @param string $secret
- * @return $this
+ * @return ConfigInterface
*/
public function setSecret(string $secret): ConfigInterface;
/**
- * @return string|null
+ * @return string
*/
- public function getCurrency(): ?string;
+ public function getCurrency(): string;
/**
* @param string $currency
- * @return $this
+ * @return ConfigInterface
*/
public function setCurrency(string $currency): ConfigInterface;
/**
- * @return string|null
+ * @return string
*/
- public function getPartner(): ?string;
+ public function getPartner(): string;
/**
* @param string $partner
- * @return $this
+ * @return ConfigInterface
*/
public function setPartner(string $partner): ConfigInterface;
/**
- * @return bool|null
+ * @return bool
*/
- public function getDebug(): ?bool;
+ public function getDebug(): bool;
/**
* @param bool $debug
- * @return $this
+ * @return ConfigInterface
*/
public function setDebug(bool $debug): ConfigInterface;
}
diff --git a/src/Response/CancelResponse.php b/src/Response/CancelResponse.php
index 1b179a0..bce6dae 100644
--- a/src/Response/CancelResponse.php
+++ b/src/Response/CancelResponse.php
@@ -2,7 +2,6 @@
namespace gullevek\AmazonIncentives\Response;
-use gullevek\AmazonIncentives\Exceptions\AmazonErrors;
use gullevek\AmazonIncentives\Debug\AmazonDebug;
class CancelResponse
@@ -12,25 +11,25 @@ class CancelResponse
*
* @var string
*/
- protected $id;
+ protected $id = '';
/**
* Amazon Gift Card creationRequestId
*
* @var string
*/
- protected $creation_request_id;
+ protected $creation_request_id = '';
/**
* Amazon Gift Card status
*
* @var string
*/
- protected $status;
+ protected $status = '';
/**
* Amazon Gift Card Raw JSON
*
* @var array
*/
- protected $raw_json;
+ protected $raw_json = [];
/**
* Response constructor.
@@ -88,15 +87,6 @@ class CancelResponse
*/
public function parseJsonResponse(array $json_response): self
{
- if (!is_array($json_response)) {
- throw AmazonErrors::getError(
- 'FAILURE',
- 'E001',
- 'NonScalarValue',
- 'Response must be a scalar value',
- 0
- );
- }
if (array_key_exists('gcId', $json_response)) {
$this->id = $json_response['gcId'];
}
diff --git a/src/Response/CreateBalanceResponse.php b/src/Response/CreateBalanceResponse.php
index ef10719..d7509e4 100644
--- a/src/Response/CreateBalanceResponse.php
+++ b/src/Response/CreateBalanceResponse.php
@@ -2,7 +2,6 @@
namespace gullevek\AmazonIncentives\Response;
-use gullevek\AmazonIncentives\Exceptions\AmazonErrors;
use gullevek\AmazonIncentives\Debug\AmazonDebug;
class CreateBalanceResponse
@@ -12,31 +11,31 @@ class CreateBalanceResponse
*
* @var string
*/
- protected $amount;
+ protected $amount = '';
/**
* Amazon Gift Card Balance Currency
*
* @var string
*/
- protected $currency;
+ protected $currency = '';
/**
* Amazon Gift Card Balance Status
*
* @var string
*/
- protected $status;
+ protected $status = '';
/**
* Amazon Gift Card Balance Timestamp
*
* @var string
*/
- protected $timestamp;
+ protected $timestamp = '';
/**
* Amazon Gift Card Raw JSON
*
* @var array
*/
- protected $raw_json;
+ protected $raw_json = [];
/**
* Response constructor.
@@ -105,15 +104,6 @@ class CreateBalanceResponse
*/
public function parseJsonResponse(array $json_response): self
{
- if (!is_array($json_response)) {
- throw AmazonErrors::getError(
- 'FAILURE',
- 'E001',
- 'NonScalarValue',
- 'Response must be a scalar value',
- 0
- );
- }
if (array_key_exists('amount', $json_response['availableFunds'])) {
$this->amount = $json_response['availableFunds']['amount'];
}
diff --git a/src/Response/CreateResponse.php b/src/Response/CreateResponse.php
index a1085ea..8624d3d 100644
--- a/src/Response/CreateResponse.php
+++ b/src/Response/CreateResponse.php
@@ -2,7 +2,6 @@
namespace gullevek\AmazonIncentives\Response;
-use gullevek\AmazonIncentives\Exceptions\AmazonErrors;
use gullevek\AmazonIncentives\Debug\AmazonDebug;
class CreateResponse
@@ -12,59 +11,59 @@ class CreateResponse
*
* @var string
*/
- protected $id;
+ protected $id = '';
/**
* Amazon Gift Card creationRequestId
*
* @var string
*/
- protected $creation_request_id;
+ protected $creation_request_id = '';
/**
* Amazon Gift Card gcClaimCode
*
* @var string
*/
- protected $claim_code;
+ protected $claim_code = '';
/**
* Amazon Gift Card amount
*
* @var float
*/
- protected $value;
+ protected $value = 0;
/**
* Amazon Gift Card currency
*
* @var string
*/
- protected $currency;
+ protected $currency = '';
/**
* Amazon Gift Card status
*
* @var string
*/
- protected $status;
+ protected $status = '';
/**
* Amazon Gift Card Expiration Date
*
* @var string
*/
- protected $expiration_date;
+ protected $expiration_date = '';
/**
* Amazon Gift Card Expiration Date
*
* @var string
*/
- protected $card_status;
+ protected $card_status = '';
/**
* Amazon Gift Card Raw JSON
*
* @var array
*/
- protected $raw_json;
+ protected $raw_json = [];
/**
* Response constructor.
@@ -158,20 +157,11 @@ class CreateResponse
}
/**
- * @param array $json_response
+ * @param array $json_response
* @return CreateResponse
*/
public function parseJsonResponse(array $json_response): self
{
- if (!is_array($json_response)) {
- throw AmazonErrors::getError(
- 'FAILURE',
- 'E001',
- 'NonScalarValue',
- 'Response must be a scalar value',
- 0
- );
- }
if (array_key_exists('gcId', $json_response)) {
$this->id = $json_response['gcId'];
}