diff --git a/composer.json b/composer.json index ed7472f..eda9925 100644 --- a/composer.json +++ b/composer.json @@ -25,8 +25,8 @@ "test": "phpunit" }, "require": { - "php": "^5.6|^7.0|^8.0" - }, + "php": "^7.1|^8.0" + }, "require-dev": { "friendsofphp/php-cs-fixer": "3.90.0", "phpunit/phpunit": "^9.6" diff --git a/src/SumUp/Application/ApplicationConfiguration.php b/src/SumUp/Application/ApplicationConfiguration.php index 93c0a7c..8c51c03 100644 --- a/src/SumUp/Application/ApplicationConfiguration.php +++ b/src/SumUp/Application/ApplicationConfiguration.php @@ -172,7 +172,7 @@ public function __construct(array $config = []) * * @return string */ - public function getAppId() + public function getAppId(): string { return $this->appId; } @@ -182,7 +182,7 @@ public function getAppId() * * @return string */ - public function getAppSecret() + public function getAppSecret(): string { return $this->appSecret; } @@ -192,7 +192,7 @@ public function getAppSecret() * * @return array */ - public function getScopes() + public function getScopes(): array { return $this->scopes; } @@ -202,7 +202,7 @@ public function getScopes() * * @return string */ - public function getFormattedScopes() + public function getFormattedScopes(): string { return implode(' ', $this->scopes); } @@ -212,7 +212,7 @@ public function getFormattedScopes() * * @return string */ - public function getBaseURL() + public function getBaseURL(): string { return $this->baseURL; } @@ -220,9 +220,9 @@ public function getBaseURL() /** * Returns authorization code. * - * @return null|string + * @return string */ - public function getCode() + public function getCode(): string { return $this->code; } @@ -232,7 +232,7 @@ public function getCode() * * @return string; */ - public function getGrantType() + public function getGrantType(): string { return $this->grantType; } @@ -240,9 +240,9 @@ public function getGrantType() /** * Returns merchant's username. * - * @return null|string + * @return string */ - public function getUsername() + public function getUsername(): string { return $this->username; } @@ -250,9 +250,9 @@ public function getUsername() /** * Returns merchant's password. * - * @return null|string + * @return string */ - public function getPassword() + public function getPassword(): string { return $this->password; } @@ -262,7 +262,7 @@ public function getPassword() * * @return null|string */ - public function getAccessToken() + public function getAccessToken(): ?string { return $this->accessToken; } @@ -272,7 +272,7 @@ public function getAccessToken() * * @return null|string */ - public function getRefreshToken() + public function getRefreshToken(): ?string { return $this->refreshToken; } @@ -282,7 +282,7 @@ public function getRefreshToken() * * @return bool */ - public function getForceGuzzle() + public function getForceGuzzle(): bool { return $this->forceGuzzle; } @@ -292,7 +292,7 @@ public function getForceGuzzle() * * @return array */ - public function getCustomHeaders() + public function getCustomHeaders(): array { return $this->customHeaders; } @@ -302,7 +302,7 @@ public function getCustomHeaders() * * @return string|null */ - public function getCABundlePath() + public function getCABundlePath(): ?string { if (!empty($this->caBundlePath)) { return $this->caBundlePath; @@ -316,7 +316,7 @@ public function getCABundlePath() * * @return string|null */ - public function getApiKey() + public function getApiKey(): ?string { return $this->apiKey; } @@ -324,11 +324,11 @@ public function getApiKey() /** * Set application ID. * - * @param string $appId + * @param ?string $appId * * @throws SumUpConfigurationException */ - protected function setAppId($appId) + protected function setAppId(?string $appId): void { if (empty($appId) && empty($this->apiKey)) { throw new SumUpConfigurationException('Missing mandatory parameter app_id or api_key'); @@ -343,7 +343,7 @@ protected function setAppId($appId) * * @throws SumUpConfigurationException */ - protected function setAppSecret($appSecret) + protected function setAppSecret(?string $appSecret): void { if (empty($appSecret) && empty($this->apiKey)) { throw new SumUpConfigurationException('Missing mandatory parameter app_secret or api_key'); @@ -354,11 +354,11 @@ protected function setAppSecret($appSecret) /** * Set the authorization grant type. * - * @param array $grantType + * @param string $grantType * * @throws SumUpConfigurationException */ - protected function setGrantType($grantType) + protected function setGrantType(string $grantType): void { if (!in_array($grantType, $this::GRANT_TYPES)) { throw new SumUpConfigurationException('Invalid parameter for "grant_type". Allowed values are: ' . implode(' | ', $this::GRANT_TYPES) . '.'); @@ -371,24 +371,18 @@ protected function setGrantType($grantType) * * @param array $scopes */ - protected function setScopes(array $scopes = []) + protected function setScopes(array $scopes = []): void { $this->scopes = array_unique(array_merge($this::DEFAULT_SCOPES, $scopes), SORT_REGULAR); - ; } /** * Set the flag whether to use GuzzleHttp. * * @param bool $forceGuzzle - * - * @throws SumUpConfigurationException */ - protected function setForceGuzzle($forceGuzzle) + protected function setForceGuzzle(bool $forceGuzzle): void { - if (!is_bool($forceGuzzle)) { - throw new SumUpConfigurationException('Invalid value for boolean parameter use_guzzlehttp_over_curl.'); - } $this->forceGuzzle = $forceGuzzle; } @@ -397,12 +391,11 @@ protected function setForceGuzzle($forceGuzzle) * * @param array $customHeaders */ - public function setCustomHeaders($customHeaders) + public function setCustomHeaders(array $customHeaders): void { - $headers = is_array($customHeaders) ? $customHeaders : []; - $headers[self::USER_AGENT_HEADER] = SdkInfo::getUserAgent(); + $customHeaders[self::USER_AGENT_HEADER] = SdkInfo::getUserAgent(); - $this->customHeaders = $headers; + $this->customHeaders = $customHeaders; } /** @@ -412,17 +405,13 @@ public function setCustomHeaders($customHeaders) * * @throws SumUpConfigurationException */ - protected function setCABundlePath($caBundlePath) + protected function setCABundlePath(?string $caBundlePath): void { if ($caBundlePath === null || $caBundlePath === '') { $this->caBundlePath = null; return; } - if (!is_string($caBundlePath)) { - throw new SumUpConfigurationException('Invalid value for "ca_bundle_path". Expected string path or null.'); - } - if (!is_readable($caBundlePath)) { throw new SumUpConfigurationException(sprintf('The provided ca_bundle_path "%s" is not readable.', $caBundlePath)); } @@ -435,7 +424,7 @@ protected function setCABundlePath($caBundlePath) * * @return string|null */ - private function getDefaultCABundlePath() + private function getDefaultCABundlePath(): ?string { $path = realpath(__DIR__ . '/../../../resources/ca-bundle.crt'); if ($path && is_readable($path)) { diff --git a/src/SumUp/Application/ApplicationConfigurationInterface.php b/src/SumUp/Application/ApplicationConfigurationInterface.php index 755d213..a855580 100644 --- a/src/SumUp/Application/ApplicationConfigurationInterface.php +++ b/src/SumUp/Application/ApplicationConfigurationInterface.php @@ -14,96 +14,96 @@ interface ApplicationConfigurationInterface * * @return string */ - public function getAppId(); + public function getAppId(): string; /** * Returns application's secret. * * @return string */ - public function getAppSecret(); + public function getAppSecret(): string; /** * Returns the scopes formatted as they should appear in the request. * - * @return string + * @return array */ - public function getScopes(); + public function getScopes(): array; /** * Returns the base URL of the SumUp API. * * @return string */ - public function getBaseURL(); + public function getBaseURL(): string; /** * Returns authorization code. * * @return string */ - public function getCode(); + public function getCode(): string; /** * Returns grant type. * * @return string */ - public function getGrantType(); + public function getGrantType(): string; /** * Returns merchant's username; * * @return string */ - public function getUsername(); + public function getUsername(): string; /** - * Returns merchant's passowrd; + * Returns merchant's password; * * @return string */ - public function getPassword(); + public function getPassword(): string; /** * Returns access token. * - * @return string + * @return string|null */ - public function getAccessToken(); + public function getAccessToken(): ?string; /** * Returns refresh token. * * @return string */ - public function getRefreshToken(); + public function getRefreshToken(): ?string; /** * Returns a flag whether to use GuzzleHttp over cURL if both are present. * * @return bool */ - public function getForceGuzzle(); + public function getForceGuzzle(): bool; /** * Returns associative array with custom headers. * * @return array */ - public function getCustomHeaders(); + public function getCustomHeaders(): array; /** * Returns the path to the CA bundle used for HTTPS verification. * * @return string|null */ - public function getCABundlePath(); + public function getCABundlePath(): ?string; /** * Returns the API key if set. * * @return string|null */ - public function getApiKey(); + public function getApiKey(): ?string; } diff --git a/src/SumUp/Authentication/AccessToken.php b/src/SumUp/Authentication/AccessToken.php index 413b85b..90dd869 100644 --- a/src/SumUp/Authentication/AccessToken.php +++ b/src/SumUp/Authentication/AccessToken.php @@ -49,11 +49,11 @@ class AccessToken * * @param string $value * @param string $type - * @param int $expiresIn + * @param int|null $expiresIn * @param array $scope - * @param string $refreshToken + * @param string|null $refreshToken */ - public function __construct($value, $type = '', $expiresIn = -1, array $scope = [], $refreshToken = null) + public function __construct(string $value, string $type = '', ?int $expiresIn = -1, array $scope = [], ?string $refreshToken = null) { if ($value) { $this->value = $value; @@ -77,7 +77,7 @@ public function __construct($value, $type = '', $expiresIn = -1, array $scope = * * @return string */ - public function getValue() + public function getValue(): string { return $this->value; } @@ -87,7 +87,7 @@ public function getValue() * * @return string */ - public function getType() + public function getType(): string { return $this->type; } @@ -97,7 +97,7 @@ public function getType() * * @return int */ - public function getExpiresIn() + public function getExpiresIn(): int { return $this->expiresIn; } @@ -107,7 +107,7 @@ public function getExpiresIn() * * @return array */ - public function getScopes() + public function getScopes(): array { return $this->scope; } @@ -117,7 +117,7 @@ public function getScopes() * * @return null|string */ - public function getRefreshToken() + public function getRefreshToken(): ?string { return $this->refreshToken; } diff --git a/src/SumUp/Exceptions/SumUpValidationException.php b/src/SumUp/Exceptions/SumUpValidationException.php index fb99adf..1d12618 100644 --- a/src/SumUp/Exceptions/SumUpValidationException.php +++ b/src/SumUp/Exceptions/SumUpValidationException.php @@ -2,6 +2,8 @@ namespace SumUp\Exceptions; +use Throwable; + /** * Class SumUpValidationException * @@ -22,9 +24,9 @@ class SumUpValidationException extends SumUpSDKException * * @param array $fields * @param int $code - * @param null $previous + * @param Throwable|null $previous */ - public function __construct($fields = [], $code = 0, $previous = null) + public function __construct(array $fields = [], int $code = 0, ?Throwable $previous = null) { $this->fields = $fields; $message = self::VALIDATION_ERROR_BASE . implode(', ', $fields); @@ -36,7 +38,7 @@ public function __construct($fields = [], $code = 0, $previous = null) * * @return array */ - public function getInvalidFields() + public function getInvalidFields(): array { return $this->fields; } diff --git a/src/SumUp/HttpClients/HttpClientsFactory.php b/src/SumUp/HttpClients/HttpClientsFactory.php index 61f1667..63b4893 100644 --- a/src/SumUp/HttpClients/HttpClientsFactory.php +++ b/src/SumUp/HttpClients/HttpClientsFactory.php @@ -27,7 +27,7 @@ private function __construct() * * @throws SumUpConfigurationException */ - public static function createHttpClient(ApplicationConfigurationInterface $appConfig, SumUpHttpClientInterface $customHttpClient = null) + public static function createHttpClient(ApplicationConfigurationInterface $appConfig, ?SumUpHttpClientInterface $customHttpClient = null): SumUpHttpClientInterface { if ($customHttpClient) { return $customHttpClient; @@ -45,12 +45,14 @@ public static function createHttpClient(ApplicationConfigurationInterface $appCo * * @param string $baseURL * @param bool $forceUseGuzzle + * @param array $customHeaders + * @param string|null $caBundlePath * * @return SumUpCUrlClient|SumUpGuzzleHttpClient * * @throws SumUpConfigurationException */ - private static function detectDefaultClient($baseURL, $forceUseGuzzle, $customHeaders, $caBundlePath) + private static function detectDefaultClient(string $baseURL, bool $forceUseGuzzle, array $customHeaders, ?string $caBundlePath): SumUpHttpClientInterface { if (extension_loaded('curl') && !$forceUseGuzzle) { return new SumUpCUrlClient($baseURL, $customHeaders, $caBundlePath); diff --git a/src/SumUp/HttpClients/Response.php b/src/SumUp/HttpClients/Response.php index 61aba4a..1a8cd13 100644 --- a/src/SumUp/HttpClients/Response.php +++ b/src/SumUp/HttpClients/Response.php @@ -4,6 +4,7 @@ use SumUp\Exceptions\SumUpAuthenticationException; use SumUp\Exceptions\SumUpResponseException; +use SumUp\Exceptions\SumUpSDKException; use SumUp\Exceptions\SumUpServerException; use SumUp\Exceptions\SumUpValidationException; @@ -17,7 +18,7 @@ class Response /** * The HTTP response code. * - * @var number + * @var int */ protected $httpResponseCode; @@ -31,17 +32,17 @@ class Response /** * Response constructor. * - * @param number $httpResponseCode - * @param $body + * @param int $httpResponseCode + * @param mixed $body * * @throws SumUpAuthenticationException * @throws SumUpResponseException * @throws SumUpValidationException * @throws SumUpServerException - * @throws \SumUp\Exceptions\SumUpSDKException + * @throws SumUpSDKException * @throws SumUpValidationException */ - public function __construct($httpResponseCode, $body) + public function __construct(int $httpResponseCode, $body) { $this->httpResponseCode = $httpResponseCode; $this->body = $body; @@ -51,9 +52,9 @@ public function __construct($httpResponseCode, $body) /** * Get HTTP response code. * - * @return number + * @return int */ - public function getHttpResponseCode() + public function getHttpResponseCode(): int { return $this->httpResponseCode; } @@ -77,9 +78,9 @@ public function getBody() * @throws SumUpResponseException * @throws SumUpValidationException * @throws SumUpServerException - * @throws \SumUp\Exceptions\SumUpSDKException + * @throws SumUpSDKException */ - protected function parseResponseForErrors() + protected function parseResponseForErrors(): void { if (isset($this->body->error_code) && $this->body->error_code === 'NOT_AUTHORIZED') { throw new SumUpAuthenticationException($this->body->error_message, $this->httpResponseCode); @@ -111,7 +112,7 @@ protected function parseResponseForErrors() * * @return string */ - protected function parseErrorMessage($defaultMessage = '') + protected function parseErrorMessage(string $defaultMessage = ''): string { if (is_null($this->body)) { return $defaultMessage; diff --git a/src/SumUp/HttpClients/SumUpCUrlClient.php b/src/SumUp/HttpClients/SumUpCUrlClient.php index 652c4b7..1241856 100644 --- a/src/SumUp/HttpClients/SumUpCUrlClient.php +++ b/src/SumUp/HttpClients/SumUpCUrlClient.php @@ -2,8 +2,11 @@ namespace SumUp\HttpClients; +use SumUp\Exceptions\SumUpAuthenticationException; use SumUp\Exceptions\SumUpConnectionException; +use SumUp\Exceptions\SumUpResponseException; use SumUp\Exceptions\SumUpSDKException; +use SumUp\Exceptions\SumUpValidationException; /** * Class SumUpCUrlClient @@ -40,7 +43,7 @@ class SumUpCUrlClient implements SumUpHttpClientInterface * @param array $customHeaders * @param string|null $caBundlePath */ - public function __construct($baseUrl, $customHeaders, $caBundlePath = null) + public function __construct(string $baseUrl, array $customHeaders, ?string $caBundlePath = null) { $this->baseUrl = $baseUrl; $this->customHeaders = $customHeaders; @@ -56,12 +59,12 @@ public function __construct($baseUrl, $customHeaders, $caBundlePath = null) * @return Response * * @throws SumUpConnectionException - * @throws \SumUp\Exceptions\SumUpResponseException - * @throws \SumUp\Exceptions\SumUpAuthenticationException - * @throws \SumUp\Exceptions\SumUpValidationException + * @throws SumUpResponseException + * @throws SumUpAuthenticationException + * @throws SumUpValidationException * @throws SumUpSDKException */ - public function send($method, $url, $body, $headers = []) + public function send(string $method, string $url, array $body, array $headers = []): Response { $reqHeaders = array_merge($headers, $this->customHeaders); $ch = curl_init(); @@ -98,7 +101,7 @@ public function send($method, $url, $body, $headers = []) * * @return array */ - private function formatHeaders($headers = null) + private function formatHeaders(?array $headers = null): array { if (count($headers) == 0) { return $headers; @@ -115,9 +118,9 @@ private function formatHeaders($headers = null) /** * Returns JSON encoded the response's body if it is of JSON type. * - * @param $response + * @param bool|string $response * - * @return mixed + * @return bool|string */ private function parseBody($response) { diff --git a/src/SumUp/HttpClients/SumUpGuzzleHttpClient.php b/src/SumUp/HttpClients/SumUpGuzzleHttpClient.php index fe70db1..c5ddd44 100644 --- a/src/SumUp/HttpClients/SumUpGuzzleHttpClient.php +++ b/src/SumUp/HttpClients/SumUpGuzzleHttpClient.php @@ -2,14 +2,19 @@ namespace SumUp\HttpClients; +use Exception; use GuzzleHttp\Client; use GuzzleHttp\Exception\ClientException; use GuzzleHttp\Exception\ConnectException; +use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\Exception\ServerException; use GuzzleHttp\Psr7\Request; +use SumUp\Exceptions\SumUpAuthenticationException; use SumUp\Exceptions\SumUpConnectionException; +use SumUp\Exceptions\SumUpResponseException; use SumUp\Exceptions\SumUpSDKException; use SumUp\Exceptions\SumUpServerException; +use SumUp\Exceptions\SumUpValidationException; /** * Class SumUpGuzzleHttpClient @@ -21,14 +26,14 @@ class SumUpGuzzleHttpClient implements SumUpHttpClientInterface /** * The Guzzle Client instance. * - * @var client + * @var Client $guzzleClient */ private $guzzleClient; /** * Custom headers for every request. * - * @var $customHeaders + * @var array $customHeaders */ private $customHeaders; @@ -39,7 +44,7 @@ class SumUpGuzzleHttpClient implements SumUpHttpClientInterface * @param array $customHeaders * @param string|bool|null $caBundlePath */ - public function __construct($baseUrl, $customHeaders, $caBundlePath = null) + public function __construct(string $baseUrl, array $customHeaders, $caBundlePath = null) { $options = ['base_uri' => $baseUrl]; if ($caBundlePath !== null) { @@ -60,12 +65,12 @@ public function __construct($baseUrl, $customHeaders, $caBundlePath = null) * * @throws SumUpConnectionException * @throws SumUpServerException - * @throws \SumUp\Exceptions\SumUpResponseException - * @throws \SumUp\Exceptions\SumUpAuthenticationException - * @throws \SumUp\Exceptions\SumUpValidationException + * @throws SumUpResponseException + * @throws SumUpAuthenticationException + * @throws SumUpValidationException * @throws SumUpSDKException */ - public function send($method, $url, $body, $headers = []) + public function send(string $method, string $url, array $body, array $headers = []): Response { $options = [ 'headers' => array_merge($headers, $this->customHeaders), @@ -85,15 +90,9 @@ public function send($method, $url, $body, $headers = []) } catch (ServerException $e) { $response = $e->getResponse(); $body = $this->parseBody($response); - if (isset($body) && isset($body->message)) { - $message = $body->message; - } else { - $message = $body; - } + $message = $body->message ?? $body; throw new SumUpServerException($message, $e->getCode(), $e->getPrevious()); - } catch (\GuzzleHttp\Exception\GuzzleException $e) { - throw new SumUpSDKException($e->getMessage(), $e->getCode(), $e->getPrevious()); - } catch (\Exception $e) { + } catch (GuzzleException|Exception $e) { throw new SumUpSDKException($e->getMessage(), $e->getCode(), $e->getPrevious()); } $body = $this->parseBody($response); diff --git a/src/SumUp/HttpClients/SumUpHttpClientInterface.php b/src/SumUp/HttpClients/SumUpHttpClientInterface.php index 8f726d1..072ef25 100644 --- a/src/SumUp/HttpClients/SumUpHttpClientInterface.php +++ b/src/SumUp/HttpClients/SumUpHttpClientInterface.php @@ -17,5 +17,5 @@ interface SumUpHttpClientInterface * * @return Response|mixed */ - public function send($method, $url, $body, $headers); + public function send(string $method, string $url, array $body, array $headers); } diff --git a/src/SumUp/SdkInfo.php b/src/SumUp/SdkInfo.php index 1002a9f..1e67b1f 100644 --- a/src/SumUp/SdkInfo.php +++ b/src/SumUp/SdkInfo.php @@ -14,7 +14,7 @@ class SdkInfo * * @return string */ - public static function getVersion() + public static function getVersion(): string { return Version::CURRENT; } @@ -24,7 +24,7 @@ public static function getVersion() * * @return string */ - public static function getUserAgent() + public static function getUserAgent(): string { return sprintf(self::USER_AGENT_TEMPLATE, self::getVersion()); } diff --git a/src/SumUp/Services/Authorization.php b/src/SumUp/Services/Authorization.php index e6d5053..84c58c8 100644 --- a/src/SumUp/Services/Authorization.php +++ b/src/SumUp/Services/Authorization.php @@ -3,8 +3,12 @@ namespace SumUp\Services; use SumUp\Application\ApplicationConfigurationInterface; +use SumUp\Exceptions\SumUpAuthenticationException; use SumUp\Exceptions\SumUpConfigurationException; use SumUp\Exceptions\SumUpArgumentException; +use SumUp\Exceptions\SumUpConnectionException; +use SumUp\Exceptions\SumUpResponseException; +use SumUp\Exceptions\SumUpSDKException; use SumUp\HttpClients\SumUpHttpClientInterface; use SumUp\Application\ApplicationConfiguration; use SumUp\Authentication\AccessToken; @@ -50,12 +54,12 @@ public function __construct(SumUpHttpClientInterface $client, ApplicationConfigu * @return null|AccessToken * * @throws SumUpConfigurationException - * @throws \SumUp\Exceptions\SumUpAuthenticationException - * @throws \SumUp\Exceptions\SumUpConnectionException - * @throws \SumUp\Exceptions\SumUpResponseException - * @throws \SumUp\Exceptions\SumUpSDKException + * @throws SumUpAuthenticationException + * @throws SumUpConnectionException + * @throws SumUpResponseException + * @throws SumUpSDKException */ - public function getToken() + public function getToken(): ?AccessToken { if (!empty($this->appConfig->getApiKey())) { return new AccessToken( @@ -104,13 +108,8 @@ public function getToken() * Returns an access token for the grant type "authorization_code". * * @return AccessToken - * - * @throws \SumUp\Exceptions\SumUpConnectionException - * @throws \SumUp\Exceptions\SumUpResponseException - * @throws \SumUp\Exceptions\SumUpAuthenticationException - * @throws \SumUp\Exceptions\SumUpSDKException */ - public function getTokenByCode() + public function getTokenByCode(): AccessToken { $payload = [ 'grant_type' => 'authorization_code', @@ -133,13 +132,8 @@ public function getTokenByCode() * Returns an access token for the grant type "client_credentials". * * @return AccessToken - * - * @throws \SumUp\Exceptions\SumUpConnectionException - * @throws \SumUp\Exceptions\SumUpResponseException - * @throws \SumUp\Exceptions\SumUpAuthenticationException - * @throws \SumUp\Exceptions\SumUpSDKException */ - public function getTokenByClientCredentials() + public function getTokenByClientCredentials(): AccessToken { $payload = [ 'grant_type' => 'client_credentials', @@ -159,12 +153,9 @@ public function getTokenByClientCredentials() * @return AccessToken * * @throws SumUpConfigurationException - * @throws \SumUp\Exceptions\SumUpConnectionException - * @throws \SumUp\Exceptions\SumUpResponseException - * @throws \SumUp\Exceptions\SumUpAuthenticationException - * @throws \SumUp\Exceptions\SumUpSDKException + * @throws SumUpSDKException */ - public function getTokenByPassword() + public function getTokenByPassword(): AccessToken { if (empty($this->appConfig->getUsername())) { throw new SumUpConfigurationException(ExceptionMessages::getMissingParamMsg('username')); @@ -198,12 +189,9 @@ public function getTokenByPassword() * @return AccessToken * * @throws SumUpArgumentException - * @throws \SumUp\Exceptions\SumUpConnectionException - * @throws \SumUp\Exceptions\SumUpResponseException - * @throws \SumUp\Exceptions\SumUpAuthenticationException - * @throws \SumUp\Exceptions\SumUpSDKException + * @throws SumUpSDKException */ - public function refreshToken($refreshToken) + public function refreshToken(string $refreshToken): AccessToken { if (empty($refreshToken)) { throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('refresh token')); diff --git a/src/SumUp/Services/Checkouts.php b/src/SumUp/Services/Checkouts.php index 6dc446f..1cb5bbb 100644 --- a/src/SumUp/Services/Checkouts.php +++ b/src/SumUp/Services/Checkouts.php @@ -3,6 +3,8 @@ namespace SumUp\Services; use SumUp\Exceptions\SumUpArgumentException; +use SumUp\Exceptions\SumUpSDKException; +use SumUp\HttpClients\Response; use SumUp\HttpClients\SumUpHttpClientInterface; use SumUp\Authentication\AccessToken; use SumUp\Utils\ExceptionMessages; @@ -49,20 +51,25 @@ public function __construct(SumUpHttpClientInterface $client, AccessToken $acces * @param string $checkoutRef * @param string $merchantCode * @param string $description - * @param null $payFromEmail - * @param null $returnURL - * @param null $redirectURL + * @param null|string $payFromEmail + * @param null|string $returnURL + * @param null|string $redirectURL * - * @return \SumUp\HttpClients\Response + * @return Response * * @throws SumUpArgumentException - * @throws \SumUp\Exceptions\SumUpConnectionException - * @throws \SumUp\Exceptions\SumUpResponseException - * @throws \SumUp\Exceptions\SumUpAuthenticationException - * @throws \SumUp\Exceptions\SumUpSDKException + * @throws SumUpSDKException */ - public function create($amount, $currency, $checkoutRef, $merchantCode, $description = '', $payFromEmail = null, $returnURL = null, $redirectURL = null) - { + public function create( + float $amount, + string $currency, + string $checkoutRef, + string $merchantCode, + string $description = '', + ?string $payFromEmail = null, + ?string $returnURL = null, + ?string $redirectURL = null + ): Response { if (empty($amount) || !is_numeric($amount)) { throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('amount')); } @@ -103,15 +110,12 @@ public function create($amount, $currency, $checkoutRef, $merchantCode, $descrip * * @param string $checkoutId * - * @return \SumUp\HttpClients\Response + * @return Response * * @throws SumUpArgumentException - * @throws \SumUp\Exceptions\SumUpConnectionException - * @throws \SumUp\Exceptions\SumUpResponseException - * @throws \SumUp\Exceptions\SumUpAuthenticationException - * @throws \SumUp\Exceptions\SumUpSDKException + * @throws SumUpSDKException */ - public function findById($checkoutId) + public function findById(string $checkoutId): Response { if (empty($checkoutId)) { throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('checkout id')); @@ -126,15 +130,12 @@ public function findById($checkoutId) * * @param string $referenceId * - * @return \SumUp\HttpClients\Response + * @return Response * * @throws SumUpArgumentException - * @throws \SumUp\Exceptions\SumUpConnectionException - * @throws \SumUp\Exceptions\SumUpResponseException - * @throws \SumUp\Exceptions\SumUpAuthenticationException - * @throws \SumUp\Exceptions\SumUpSDKException + * @throws SumUpSDKException */ - public function findByReferenceId($referenceId) + public function findByReferenceId(string $referenceId): Response { if (empty($referenceId)) { throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('reference id')); @@ -149,15 +150,12 @@ public function findByReferenceId($referenceId) * * @param string $checkoutId * - * @return \SumUp\HttpClients\Response + * @return Response * * @throws SumUpArgumentException - * @throws \SumUp\Exceptions\SumUpConnectionException - * @throws \SumUp\Exceptions\SumUpResponseException - * @throws \SumUp\Exceptions\SumUpAuthenticationException - * @throws \SumUp\Exceptions\SumUpSDKException + * @throws SumUpSDKException */ - public function delete($checkoutId) + public function delete(string $checkoutId): Response { if (empty($checkoutId)) { throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('checkout id')); @@ -175,15 +173,12 @@ public function delete($checkoutId) * @param string $cardToken * @param int $installments * - * @return \SumUp\HttpClients\Response + * @return Response * * @throws SumUpArgumentException - * @throws \SumUp\Exceptions\SumUpConnectionException - * @throws \SumUp\Exceptions\SumUpResponseException - * @throws \SumUp\Exceptions\SumUpAuthenticationException - * @throws \SumUp\Exceptions\SumUpSDKException + * @throws SumUpSDKException */ - public function pay($checkoutId, $customerId, $cardToken, $installments = 1) + public function pay(string $checkoutId, string $customerId, string $cardToken, int $installments = 1): Response { if (empty($checkoutId)) { throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('checkout id')); diff --git a/src/SumUp/Services/Custom.php b/src/SumUp/Services/Custom.php index 356d289..6ea448e 100644 --- a/src/SumUp/Services/Custom.php +++ b/src/SumUp/Services/Custom.php @@ -3,6 +3,8 @@ namespace SumUp\Services; use SumUp\Exceptions\SumUpArgumentException; +use SumUp\Exceptions\SumUpSDKException; +use SumUp\HttpClients\Response; use SumUp\HttpClients\SumUpHttpClientInterface; use SumUp\Authentication\AccessToken; use SumUp\Utils\Headers; @@ -52,15 +54,12 @@ public function __construct(SumUpHttpClientInterface $client, AccessToken $acces * @param string $relativePath * @param array|null $payload * - * @return mixed|\SumUp\HttpClients\Response + * @return mixed|Response * * @throws SumUpArgumentException - * @throws \SumUp\Exceptions\SumUpConnectionException - * @throws \SumUp\Exceptions\SumUpResponseException - * @throws \SumUp\Exceptions\SumUpAuthenticationException - * @throws \SumUp\Exceptions\SumUpSDKException + * @throws SumUpSDKException */ - public function request($method, $relativePath, $payload = null) + public function request(string $method, string $relativePath, ?array $payload = null) { if (!in_array($method, $this::HTTP_METHODS)) { $message = "Not allowed method provided: $method. Allowed values: " . implode(', ', $this::HTTP_METHODS) . '.'; diff --git a/src/SumUp/Services/Customers.php b/src/SumUp/Services/Customers.php index e01b40a..fa2c301 100644 --- a/src/SumUp/Services/Customers.php +++ b/src/SumUp/Services/Customers.php @@ -2,6 +2,8 @@ namespace SumUp\Services; +use SumUp\Exceptions\SumUpSDKException; +use SumUp\HttpClients\Response; use SumUp\HttpClients\SumUpHttpClientInterface; use SumUp\Authentication\AccessToken; use SumUp\Exceptions\SumUpArgumentException; @@ -44,19 +46,16 @@ public function __construct(SumUpHttpClientInterface $client, AccessToken $acces /** * Create new customer. * - * @param $customerId + * @param string $customerId * @param array $customerDetails * @param array $customerAddress * - * @return \SumUp\HttpClients\Response + * @return Response * * @throws SumUpArgumentException - * @throws \SumUp\Exceptions\SumUpConnectionException - * @throws \SumUp\Exceptions\SumUpResponseException - * @throws \SumUp\Exceptions\SumUpAuthenticationException - * @throws \SumUp\Exceptions\SumUpSDKException + * @throws SumUpSDKException */ - public function create($customerId, array $customerDetails = [], array $customerAddress = []) + public function create(string $customerId, array $customerDetails = [], array $customerAddress = []): Response { if (empty($customerId)) { throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('customer id')); @@ -96,19 +95,16 @@ public function create($customerId, array $customerDetails = [], array $customer /** * Update existing customer. * - * @param $customerId + * @param string $customerId * @param array $customerDetails * @param array $customerAddress * - * @return \SumUp\HttpClients\Response + * @return Response * * @throws SumUpArgumentException - * @throws \SumUp\Exceptions\SumUpConnectionException - * @throws \SumUp\Exceptions\SumUpResponseException - * @throws \SumUp\Exceptions\SumUpAuthenticationException - * @throws \SumUp\Exceptions\SumUpSDKException + * @throws SumUpSDKException */ - public function update($customerId, array $customerDetails = [], array $customerAddress = []) + public function update(string $customerId, array $customerDetails = [], array $customerAddress = []): Response { if (empty($customerId)) { throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('customer id')); @@ -147,17 +143,14 @@ public function update($customerId, array $customerDetails = [], array $customer /** * Get customer by ID. * - * @param $customerId + * @param string $customerId * - * @return \SumUp\HttpClients\Response + * @return Response * * @throws SumUpArgumentException - * @throws \SumUp\Exceptions\SumUpConnectionException - * @throws \SumUp\Exceptions\SumUpResponseException - * @throws \SumUp\Exceptions\SumUpAuthenticationException - * @throws \SumUp\Exceptions\SumUpSDKException + * @throws SumUpSDKException */ - public function get($customerId) + public function get(string $customerId): Response { if (empty($customerId)) { throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('customer id')); @@ -170,17 +163,14 @@ public function get($customerId) /** * Get payment instruments for a customer. * - * @param $customerId + * @param string $customerId * - * @return \SumUp\HttpClients\Response + * @return Response * * @throws SumUpArgumentException - * @throws \SumUp\Exceptions\SumUpConnectionException - * @throws \SumUp\Exceptions\SumUpResponseException - * @throws \SumUp\Exceptions\SumUpAuthenticationException - * @throws \SumUp\Exceptions\SumUpSDKException + * @throws SumUpSDKException */ - public function getPaymentInstruments($customerId) + public function getPaymentInstruments(string $customerId): Response { if (empty($customerId)) { throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('customer id')); @@ -193,18 +183,15 @@ public function getPaymentInstruments($customerId) /** * Deactivate payment instrument for a customer. * - * @param $customerId - * @param $cardToken + * @param string $customerId + * @param string $cardToken * - * @return \SumUp\HttpClients\Response + * @return Response * * @throws SumUpArgumentException - * @throws \SumUp\Exceptions\SumUpConnectionException - * @throws \SumUp\Exceptions\SumUpResponseException - * @throws \SumUp\Exceptions\SumUpAuthenticationException - * @throws \SumUp\Exceptions\SumUpSDKException + * @throws SumUpSDKException */ - public function deletePaymentInstruments($customerId, $cardToken) + public function deletePaymentInstruments(string $customerId, string $cardToken): Response { if (empty($customerId)) { throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('customer id')); diff --git a/src/SumUp/Services/Merchant.php b/src/SumUp/Services/Merchant.php index dcf3c36..6a1a547 100644 --- a/src/SumUp/Services/Merchant.php +++ b/src/SumUp/Services/Merchant.php @@ -2,6 +2,8 @@ namespace SumUp\Services; +use SumUp\Exceptions\SumUpSDKException; +use SumUp\HttpClients\Response; use SumUp\HttpClients\SumUpHttpClientInterface; use SumUp\Authentication\AccessToken; use SumUp\Exceptions\SumUpArgumentException; @@ -44,14 +46,9 @@ public function __construct(SumUpHttpClientInterface $client, AccessToken $acces /** * Get merchant's profile. * - * @return \SumUp\HttpClients\Response - * - * @throws \SumUp\Exceptions\SumUpConnectionException - * @throws \SumUp\Exceptions\SumUpResponseException - * @throws \SumUp\Exceptions\SumUpAuthenticationException - * @throws \SumUp\Exceptions\SumUpSDKException + * @return Response */ - public function getProfile() + public function getProfile(): Response { $path = '/v0.1/me/merchant-profile'; $headers = array_merge(Headers::getStandardHeaders(), Headers::getAuth($this->accessToken)); @@ -63,15 +60,12 @@ public function getProfile() * * @param array $data * - * @return \SumUp\HttpClients\Response + * @return Response * * @throws SumUpArgumentException - * @throws \SumUp\Exceptions\SumUpConnectionException - * @throws \SumUp\Exceptions\SumUpResponseException - * @throws \SumUp\Exceptions\SumUpAuthenticationException - * @throws \SumUp\Exceptions\SumUpSDKException + * @throws SumUpSDKException */ - public function updateProfile(array $data) + public function updateProfile(array $data): Response { if (empty($data)) { throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('payload data')); @@ -84,14 +78,9 @@ public function updateProfile(array $data) /** * Get data for doing business as. * - * @return \SumUp\HttpClients\Response - * - * @throws \SumUp\Exceptions\SumUpConnectionException - * @throws \SumUp\Exceptions\SumUpResponseException - * @throws \SumUp\Exceptions\SumUpAuthenticationException - * @throws \SumUp\Exceptions\SumUpSDKException + * @return Response */ - public function getDoingBusinessAs() + public function getDoingBusinessAs(): Response { $path = '/v0.1/me/merchant-profile/doing-business-as'; $headers = array_merge(Headers::getStandardHeaders(), Headers::getAuth($this->accessToken)); @@ -103,15 +92,12 @@ public function getDoingBusinessAs() * * @param array $data * - * @return \SumUp\HttpClients\Response + * @return Response * * @throws SumUpArgumentException - * @throws \SumUp\Exceptions\SumUpConnectionException - * @throws \SumUp\Exceptions\SumUpResponseException - * @throws \SumUp\Exceptions\SumUpAuthenticationException - * @throws \SumUp\Exceptions\SumUpSDKException + * @throws SumUpSDKException */ - public function updateDoingBusinessAs(array $data) + public function updateDoingBusinessAs(array $data): Response { if (empty($data)) { throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('payload data')); diff --git a/src/SumUp/Services/Payouts.php b/src/SumUp/Services/Payouts.php index 2e100a5..df542ec 100644 --- a/src/SumUp/Services/Payouts.php +++ b/src/SumUp/Services/Payouts.php @@ -2,6 +2,8 @@ namespace SumUp\Services; +use SumUp\Exceptions\SumUpSDKException; +use SumUp\HttpClients\Response; use SumUp\HttpClients\SumUpHttpClientInterface; use SumUp\Authentication\AccessToken; use SumUp\Exceptions\SumUpArgumentException; @@ -50,15 +52,12 @@ public function __construct(SumUpHttpClientInterface $client, AccessToken $acces * @param bool $descendingOrder * @param string $format * - * @return \SumUp\HttpClients\Response + * @return Response * * @throws SumUpArgumentException - * @throws \SumUp\Exceptions\SumUpConnectionException - * @throws \SumUp\Exceptions\SumUpResponseException - * @throws \SumUp\Exceptions\SumUpAuthenticationException - * @throws \SumUp\Exceptions\SumUpSDKException + * @throws SumUpSDKException */ - public function getPayouts($startDate, $endDate, $limit = 10, $descendingOrder = true, $format = 'json') + public function getPayouts(string $startDate, string $endDate, int $limit = 10, bool $descendingOrder = true, string $format = 'json'): Response { if (empty($startDate)) { throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('start date')); @@ -69,9 +68,6 @@ public function getPayouts($startDate, $endDate, $limit = 10, $descendingOrder = if (empty($limit) || !is_int($limit)) { throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('limit')); } - if (empty($descendingOrder)) { - throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('order')); - } if (empty($format)) { throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('format')); } @@ -85,11 +81,11 @@ public function getPayouts($startDate, $endDate, $limit = 10, $descendingOrder = $queryParams = http_build_query($filters); $path = '/v0.1/me/financials/payouts?' . $queryParams; $headers = array_merge(Headers::getStandardHeaders(), Headers::getAuth($this->accessToken)); - return $this->client->send('GET', $path, null, $headers); + return $this->client->send('GET', $path, [], $headers); } /** - * Get a list of payed out transactions. + * Get a list of paid out transactions. * * @param string $startDate * @param string $endDate @@ -97,15 +93,12 @@ public function getPayouts($startDate, $endDate, $limit = 10, $descendingOrder = * @param bool $descendingOrder * @param string $format * - * @return \SumUp\HttpClients\Response + * @return Response * * @throws SumUpArgumentException - * @throws \SumUp\Exceptions\SumUpConnectionException - * @throws \SumUp\Exceptions\SumUpResponseException - * @throws \SumUp\Exceptions\SumUpAuthenticationException - * @throws \SumUp\Exceptions\SumUpSDKException + * @throws SumUpSDKException */ - public function getTransactions($startDate, $endDate, $limit = 10, $descendingOrder = true, $format = 'json') + public function getTransactions(string $startDate, string $endDate, int $limit = 10, bool $descendingOrder = true, string $format = 'json'): Response { if (empty($startDate)) { throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('start date')); @@ -116,9 +109,6 @@ public function getTransactions($startDate, $endDate, $limit = 10, $descendingOr if (empty($limit) || !is_int($limit)) { throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('limit')); } - if (empty($descendingOrder)) { - throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('order')); - } if (empty($format)) { throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('format')); } @@ -132,6 +122,6 @@ public function getTransactions($startDate, $endDate, $limit = 10, $descendingOr $queryParams = http_build_query($filters); $path = '/v0.1/me/financials/transactions?' . $queryParams; $headers = array_merge(Headers::getStandardHeaders(), Headers::getAuth($this->accessToken)); - return $this->client->send('GET', $path, null, $headers); + return $this->client->send('GET', $path, [], $headers); } } diff --git a/src/SumUp/Services/Transactions.php b/src/SumUp/Services/Transactions.php index 1356f03..15180d0 100644 --- a/src/SumUp/Services/Transactions.php +++ b/src/SumUp/Services/Transactions.php @@ -2,6 +2,8 @@ namespace SumUp\Services; +use SumUp\Exceptions\SumUpSDKException; +use SumUp\HttpClients\Response; use SumUp\HttpClients\SumUpHttpClientInterface; use SumUp\Authentication\AccessToken; use SumUp\Exceptions\SumUpArgumentException; @@ -44,17 +46,14 @@ public function __construct(SumUpHttpClientInterface $client, AccessToken $acces /** * Get single transaction by transaction ID. * - * @param $transactionId + * @param string $transactionId * - * @return \SumUp\HttpClients\Response + * @return Response * * @throws SumUpArgumentException - * @throws \SumUp\Exceptions\SumUpConnectionException - * @throws \SumUp\Exceptions\SumUpResponseException - * @throws \SumUp\Exceptions\SumUpAuthenticationException - * @throws \SumUp\Exceptions\SumUpSDKException + * @throws SumUpSDKException */ - public function findById($transactionId) + public function findById(string $transactionId): Response { if (empty($transactionId)) { throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('transaction id')); @@ -67,17 +66,14 @@ public function findById($transactionId) /** * Get single transaction by internal ID. * - * @param $internalId + * @param string $internalId * - * @return \SumUp\HttpClients\Response + * @return Response * * @throws SumUpArgumentException - * @throws \SumUp\Exceptions\SumUpConnectionException - * @throws \SumUp\Exceptions\SumUpResponseException - * @throws \SumUp\Exceptions\SumUpAuthenticationException - * @throws \SumUp\Exceptions\SumUpSDKException + * @throws SumUpSDKException */ - public function findByInternalId($internalId) + public function findByInternalId(string $internalId): Response { if (empty($internalId)) { throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('internal id')); @@ -90,17 +86,14 @@ public function findByInternalId($internalId) /** * Get single transaction by foreign transaction id. * - * @param $foreignId + * @param string $foreignId * - * @return \SumUp\HttpClients\Response + * @return Response * * @throws SumUpArgumentException - * @throws \SumUp\Exceptions\SumUpConnectionException - * @throws \SumUp\Exceptions\SumUpResponseException - * @throws \SumUp\Exceptions\SumUpAuthenticationException - * @throws \SumUp\Exceptions\SumUpSDKException + * @throws SumUpSDKException */ - public function findByForeignId($foreignId) + public function findByForeignId(string $foreignId): Response { if (empty($foreignId)) { throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('foreign transaction id')); @@ -113,17 +106,14 @@ public function findByForeignId($foreignId) /** * Get single transaction by transaction code. * - * @param $transactionCode + * @param string $transactionCode * - * @return \SumUp\HttpClients\Response + * @return Response * * @throws SumUpArgumentException - * @throws \SumUp\Exceptions\SumUpConnectionException - * @throws \SumUp\Exceptions\SumUpResponseException - * @throws \SumUp\Exceptions\SumUpAuthenticationException - * @throws \SumUp\Exceptions\SumUpSDKException + * @throws SumUpSDKException */ - public function findByTransactionCode($transactionCode) + public function findByTransactionCode(string $transactionCode): Response { if (empty($transactionCode)) { throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('transaction code')); @@ -138,14 +128,9 @@ public function findByTransactionCode($transactionCode) * * @param array $filters * - * @return \SumUp\HttpClients\Response - * - * @throws \SumUp\Exceptions\SumUpConnectionException - * @throws \SumUp\Exceptions\SumUpResponseException - * @throws \SumUp\Exceptions\SumUpAuthenticationException - * @throws \SumUp\Exceptions\SumUpSDKException + * @return Response */ - public function getTransactionHistory($filters = []) + public function getTransactionHistory(array $filters = []): Response { $filters = array_merge([ 'order' => 'ascending', @@ -176,18 +161,15 @@ public function getTransactionHistory($filters = []) /** * Refund a transaction partially or fully. * - * @param $transactionId - * @param null $amount + * @param string $transactionId + * @param string|null $amount * - * @return \SumUp\HttpClients\Response + * @return Response * * @throws SumUpArgumentException - * @throws \SumUp\Exceptions\SumUpConnectionException - * @throws \SumUp\Exceptions\SumUpResponseException - * @throws \SumUp\Exceptions\SumUpAuthenticationException - * @throws \SumUp\Exceptions\SumUpSDKException + * @throws SumUpSDKException */ - public function refund($transactionId, $amount = null) + public function refund(string $transactionId, ?string $amount = null): Response { if (empty($transactionId)) { throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('transaction id')); @@ -206,18 +188,15 @@ public function refund($transactionId, $amount = null) /** * Get a receipt for a transaction. * - * @param $transactionId - * @param $merchantId + * @param string $transactionId + * @param string $merchantId * - * @return \SumUp\HttpClients\Response + * @return Response * * @throws SumUpArgumentException - * @throws \SumUp\Exceptions\SumUpConnectionException - * @throws \SumUp\Exceptions\SumUpResponseException - * @throws \SumUp\Exceptions\SumUpAuthenticationException - * @throws \SumUp\Exceptions\SumUpSDKException + * @throws SumUpSDKException */ - public function getReceipt($transactionId, $merchantId) + public function getReceipt(string $transactionId, string $merchantId): Response { if (empty($transactionId)) { throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('transaction id')); diff --git a/src/SumUp/SumUp.php b/src/SumUp/SumUp.php index 592c0f2..e18d787 100644 --- a/src/SumUp/SumUp.php +++ b/src/SumUp/SumUp.php @@ -49,7 +49,7 @@ class SumUp * * @throws SumUpSDKException */ - public function __construct(array $config = [], SumUpHttpClientInterface $customHttpClient = null) + public function __construct(array $config = [], ?SumUpHttpClientInterface $customHttpClient = null) { $this->appConfig = new ApplicationConfiguration($config); $this->client = HttpClientsFactory::createHttpClient($this->appConfig, $customHttpClient); @@ -70,17 +70,17 @@ public function getAccessToken() /** * Refresh the access token. * - * @param string $refreshToken + * @param string|null $refreshToken * * @return Authentication\AccessToken * * @throws SumUpSDKException */ - public function refreshToken($refreshToken = null) + public function refreshToken(?string $refreshToken = null): AccessToken { if (isset($refreshToken)) { $rToken = $refreshToken; - } elseif (!isset($refreshToken) && !isset($this->accessToken)) { + } elseif (!isset($this->accessToken)) { throw new SumUpConfigurationException('There is no refresh token'); } else { $rToken = $this->accessToken->getRefreshToken(); @@ -97,7 +97,7 @@ public function refreshToken($refreshToken = null) * * @return Authorization */ - public function getAuthorizationService(ApplicationConfigurationInterface $config = null) + public function getAuthorizationService(?ApplicationConfigurationInterface $config = null): Authorization { if (empty($config)) { $cfg = $this->appConfig; @@ -114,7 +114,7 @@ public function getAuthorizationService(ApplicationConfigurationInterface $confi * * @return Checkouts */ - public function getCheckoutService(AccessToken $accessToken = null) + public function getCheckoutService(?AccessToken $accessToken = null): Checkouts { if (!empty($accessToken)) { $accToken = $accessToken; @@ -131,7 +131,7 @@ public function getCheckoutService(AccessToken $accessToken = null) * * @return Customers */ - public function getCustomerService(AccessToken $accessToken = null) + public function getCustomerService(?AccessToken $accessToken = null): Customers { if (!empty($accessToken)) { $accToken = $accessToken; @@ -148,7 +148,7 @@ public function getCustomerService(AccessToken $accessToken = null) * * @return Transactions */ - public function getTransactionService(AccessToken $accessToken = null) + public function getTransactionService(?AccessToken $accessToken = null): Transactions { if (!empty($accessToken)) { $accToken = $accessToken; @@ -165,7 +165,7 @@ public function getTransactionService(AccessToken $accessToken = null) * * @return Merchant */ - public function getMerchantService(AccessToken $accessToken = null) + public function getMerchantService(?AccessToken $accessToken = null): Merchant { if (!empty($accessToken)) { $accToken = $accessToken; @@ -182,7 +182,7 @@ public function getMerchantService(AccessToken $accessToken = null) * * @return Payouts */ - public function getPayoutService(AccessToken $accessToken = null) + public function getPayoutService(?AccessToken $accessToken = null): Payouts { if (!empty($accessToken)) { $accToken = $accessToken; @@ -197,7 +197,7 @@ public function getPayoutService(AccessToken $accessToken = null) * * @return Custom */ - public function getCustomService(AccessToken $accessToken = null) + public function getCustomService(?AccessToken $accessToken = null): Custom { if (!empty($accessToken)) { $accToken = $accessToken; diff --git a/src/SumUp/Utils/ExceptionMessages.php b/src/SumUp/Utils/ExceptionMessages.php index ac7e951..749d025 100644 --- a/src/SumUp/Utils/ExceptionMessages.php +++ b/src/SumUp/Utils/ExceptionMessages.php @@ -12,11 +12,11 @@ class ExceptionMessages /** * Get formatted message for missing parameter. * - * @param $missingParamName + * @param string $missingParamName * * @return string */ - public static function getMissingParamMsg($missingParamName) + public static function getMissingParamMsg(string $missingParamName): string { return 'Missing parameter: "' . $missingParamName . '".'; } diff --git a/src/SumUp/Utils/Headers.php b/src/SumUp/Utils/Headers.php index e687a1a..f22baa3 100644 --- a/src/SumUp/Utils/Headers.php +++ b/src/SumUp/Utils/Headers.php @@ -17,7 +17,7 @@ class Headers * * @return array */ - public static function getCTJson() + public static function getCTJson(): array { return ['Content-Type' => 'application/json']; } @@ -27,7 +27,7 @@ public static function getCTJson() * * @return array */ - public static function getCTForm() + public static function getCTForm(): array { return ['Content-Type' => 'application/x-www-form-urlencoded']; } @@ -39,7 +39,7 @@ public static function getCTForm() * * @return array */ - public static function getAuth(AccessToken $accessToken) + public static function getAuth(AccessToken $accessToken): array { return ['Authorization' => 'Bearer ' . $accessToken->getValue()]; } @@ -49,7 +49,7 @@ public static function getAuth(AccessToken $accessToken) * * @return array */ - public static function getStandardHeaders() + public static function getStandardHeaders(): array { $headers = self::getCTJson(); $headers['User-Agent'] = SdkInfo::getUserAgent();