From 290aed8ad832cff3fa48abc85405a5a9341a591f Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Thu, 21 Nov 2024 16:37:24 +0100
Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Minor=20code=20formatting?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/Authentication/PayPalBearer.php | 26 +++++++++----------
.../Endpoint/ConnectManualRestEndpoint.php | 14 +++++-----
2 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/modules/ppcp-api-client/src/Authentication/PayPalBearer.php b/modules/ppcp-api-client/src/Authentication/PayPalBearer.php
index f5cab579b..3d5773ea3 100644
--- a/modules/ppcp-api-client/src/Authentication/PayPalBearer.php
+++ b/modules/ppcp-api-client/src/Authentication/PayPalBearer.php
@@ -5,7 +5,7 @@
* @package WooCommerce\PayPalCommerce\ApiClient\Authentication
*/
-declare(strict_types=1);
+declare( strict_types = 1 );
namespace WooCommerce\PayPalCommerce\ApiClient\Authentication;
@@ -70,12 +70,11 @@ class PayPalBearer implements Bearer {
/**
* PayPalBearer constructor.
*
- * @param Cache $cache The cache.
- * @param string $host The host.
- * @param string $key The key.
- * @param string $secret The secret.
- * @param LoggerInterface $logger The logger.
- * @param ContainerInterface $settings The settings.
+ * @param Cache $cache The cache.
+ * @param string $host The host.
+ * @param string $key The key.
+ * @param string $secret The secret.
+ * @param LoggerInterface $logger The logger.
*/
public function __construct(
Cache $cache,
@@ -97,12 +96,13 @@ class PayPalBearer implements Bearer {
/**
* Returns a bearer token.
*
- * @return Token
* @throws RuntimeException When request fails.
+ * @return Token
*/
- public function bearer(): Token {
+ public function bearer() : Token {
try {
$bearer = Token::from_json( (string) $this->cache->get( self::CACHE_KEY ) );
+
return ( $bearer->is_valid() ) ? $bearer : $this->newBearer();
} catch ( RuntimeException $error ) {
return $this->newBearer();
@@ -112,8 +112,8 @@ class PayPalBearer implements Bearer {
/**
* Creates a new bearer token.
*
- * @return Token
* @throws RuntimeException When request fails.
+ * @return Token
*/
private function newBearer(): Token {
$key = $this->settings->has( 'client_id' ) && $this->settings->get( 'client_id' ) ? $this->settings->get( 'client_id' ) : $this->key;
@@ -127,10 +127,7 @@ class PayPalBearer implements Bearer {
'Authorization' => 'Basic ' . base64_encode( $key . ':' . $secret ),
),
);
- $response = $this->request(
- $url,
- $args
- );
+ $response = $this->request( $url, $args );
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200 ) {
$error = new RuntimeException(
@@ -148,6 +145,7 @@ class PayPalBearer implements Bearer {
$token = Token::from_json( $response['body'] );
$this->cache->set( self::CACHE_KEY, $token->as_json() );
+
return $token;
}
}
diff --git a/modules/ppcp-settings/src/Endpoint/ConnectManualRestEndpoint.php b/modules/ppcp-settings/src/Endpoint/ConnectManualRestEndpoint.php
index af81b90ca..f39b5431e 100644
--- a/modules/ppcp-settings/src/Endpoint/ConnectManualRestEndpoint.php
+++ b/modules/ppcp-settings/src/Endpoint/ConnectManualRestEndpoint.php
@@ -78,9 +78,9 @@ class ConnectManualRestEndpoint extends RestEndpoint {
/**
* ConnectManualRestEndpoint constructor.
*
- * @param string $live_host The API host for the live mode.
+ * @param string $live_host The API host for the live mode.
* @param string $sandbox_host The API host for the sandbox mode.
- * @param LoggerInterface $logger The logger.
+ * @param LoggerInterface $logger The logger.
*/
public function __construct(
string $live_host,
@@ -159,14 +159,16 @@ class ConnectManualRestEndpoint extends RestEndpoint {
* Retrieves the payee object with the merchant data
* by creating a minimal PayPal order.
*
- * @param string $client_id The client ID.
- * @param string $client_secret The client secret.
- * @param bool $use_sandbox Whether to use the sandbox mode.
- * @return stdClass The payee object.
* @throws Exception When failed to retrieve payee.
*
* phpcs:disable Squiz.Commenting
* phpcs:disable Generic.Commenting
+ *
+ * @param string $client_secret The client secret.
+ * @param bool $use_sandbox Whether to use the sandbox mode.
+ * @param string $client_id The client ID.
+ *
+ * @return stdClass The payee object.
*/
private function request_payee(
string $client_id,