🎨 Minor code formatting

This commit is contained in:
Philipp Stracker 2024-11-21 16:37:24 +01:00
parent faff0baa43
commit 290aed8ad8
No known key found for this signature in database
2 changed files with 20 additions and 20 deletions

View file

@ -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;
}
}

View file

@ -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,