Fix psalm

This commit is contained in:
Emili Castells Guasch 2023-05-02 12:35:46 +02:00
parent e1d84af7f0
commit eca8a3b09c
21 changed files with 357 additions and 203 deletions

View file

@ -120,8 +120,8 @@ class BillingAgreementsEndpoint {
*/
public function reference_transaction_enabled(): bool {
try {
$reference_transaction_enabled = get_transient('ppcp_reference_transaction_enabled') ?? '';
if($reference_transaction_enabled === true) {
$reference_transaction_enabled = get_transient( 'ppcp_reference_transaction_enabled' ) ?? '';
if ( $reference_transaction_enabled === true ) {
return true;
}
@ -135,12 +135,12 @@ class BillingAgreementsEndpoint {
);
} finally {
$this->is_request_logging_enabled = true;
set_transient('ppcp_reference_transaction_enabled', true, 3 * MONTH_IN_SECONDS);
set_transient( 'ppcp_reference_transaction_enabled', true, 3 * MONTH_IN_SECONDS );
}
return true;
} catch ( PayPalApiException $exception ) {
delete_transient('ppcp_reference_transaction_enabled');
delete_transient( 'ppcp_reference_transaction_enabled' );
return false;
}
}

View file

@ -70,11 +70,11 @@ class BillingPlans {
PlanFactory $plan_factory,
LoggerInterface $logger
) {
$this->host = $host;
$this->bearer = $bearer;
$this->host = $host;
$this->bearer = $bearer;
$this->billing_cycle_factory = $billing_cycle_factory;
$this->plan_factory = $plan_factory;
$this->logger = $logger;
$this->plan_factory = $plan_factory;
$this->logger = $logger;
}
/**
@ -95,10 +95,10 @@ class BillingPlans {
): Plan {
$data = array(
'name' => $name,
'product_id' => $product_id,
'billing_cycles' => $billing_cycles,
'payment_preferences' => $payment_preferences
'name' => $name,
'product_id' => $product_id,
'billing_cycles' => $billing_cycles,
'payment_preferences' => $payment_preferences,
);
$bearer = $this->bearer->bearer();
@ -108,7 +108,7 @@ class BillingPlans {
'headers' => array(
'Authorization' => 'Bearer ' . $bearer->token(),
'Content-Type' => 'application/json',
'Prefer' => 'return=representation'
'Prefer' => 'return=representation',
),
'body' => wp_json_encode( $data ),
);
@ -128,17 +128,17 @@ class BillingPlans {
);
}
return $this->plan_factory->from_paypal_response($json);
return $this->plan_factory->from_paypal_response( $json );
}
public function plan(string $id): Plan {
public function plan( string $id ): Plan {
$bearer = $this->bearer->bearer();
$url = trailingslashit( $this->host ) . 'v1/billing/plans/' . $id;
$args = array(
'headers' => array(
'Authorization' => 'Bearer ' . $bearer->token(),
'Content-Type' => 'application/json',
'Prefer' => 'return=representation'
'Prefer' => 'return=representation',
),
);
@ -156,15 +156,15 @@ class BillingPlans {
);
}
return $this->plan_factory->from_paypal_response($json);
return $this->plan_factory->from_paypal_response( $json );
}
public function update_pricing(string $id, BillingCycle $billing_cycle): void {
public function update_pricing( string $id, BillingCycle $billing_cycle ): void {
$data = array(
"pricing_schemes" => array(
(object)array(
"billing_cycle_sequence" => 1,
"pricing_scheme" => $billing_cycle->pricing_scheme(),
'pricing_schemes' => array(
(object) array(
'billing_cycle_sequence' => 1,
'pricing_scheme' => $billing_cycle->pricing_scheme(),
),
),
);

View file

@ -179,14 +179,14 @@ class BillingSubscriptions {
* @param string $id Subscription ID.
* @return stdClass
*/
public function subscription(string $id): stdClass {
public function subscription( string $id ): stdClass {
$bearer = $this->bearer->bearer();
$url = trailingslashit( $this->host ) . 'v1/billing/subscriptions/' . $id;
$args = array(
'headers' => array(
'Authorization' => 'Bearer ' . $bearer->token(),
'Content-Type' => 'application/json',
'Prefer' => 'return=representation'
'Prefer' => 'return=representation',
),
);

View file

@ -60,10 +60,10 @@ class CatalogProducts {
ProductFactory $product_factory,
LoggerInterface $logger
) {
$this->host = $host;
$this->bearer = $bearer;
$this->host = $host;
$this->bearer = $bearer;
$this->product_factory = $product_factory;
$this->logger = $logger;
$this->logger = $logger;
}
/**
@ -77,12 +77,12 @@ class CatalogProducts {
* @throws RuntimeException If the request fails.
* @throws PayPalApiException If the request fails.
*/
public function create(string $name, string $description): Product {
public function create( string $name, string $description ): Product {
$data = array(
'name' => $name,
);
if($description) {
if ( $description ) {
$data['description'] = $description;
}
@ -93,7 +93,7 @@ class CatalogProducts {
'headers' => array(
'Authorization' => 'Bearer ' . $bearer->token(),
'Content-Type' => 'application/json',
'Prefer' => 'return=representation'
'Prefer' => 'return=representation',
),
'body' => wp_json_encode( $data ),
);
@ -113,17 +113,17 @@ class CatalogProducts {
);
}
return $this->product_factory->from_paypal_response($json);
return $this->product_factory->from_paypal_response( $json );
}
/**
* Updates a Product.
*
* @param string $id Product ID.
* @param array $data Data to update.
* @param array $data Data to update.
* @return void
*/
public function update(string $id, array $data): void {
public function update( string $id, array $data ): void {
$bearer = $this->bearer->bearer();
$url = trailingslashit( $this->host ) . 'v1/catalogs/products/' . $id;
$args = array(
@ -131,7 +131,7 @@ class CatalogProducts {
'headers' => array(
'Authorization' => 'Bearer ' . $bearer->token(),
'Content-Type' => 'application/json',
'Prefer' => 'return=representation'
'Prefer' => 'return=representation',
),
'body' => wp_json_encode( $data ),
);
@ -157,14 +157,14 @@ class CatalogProducts {
* @param string $id Product ID.
* @return Product
*/
public function product(string $id): Product {
public function product( string $id ): Product {
$bearer = $this->bearer->bearer();
$url = trailingslashit( $this->host ) . 'v1/catalogs/products/' . $id;
$args = array(
'headers' => array(
'Authorization' => 'Bearer ' . $bearer->token(),
'Content-Type' => 'application/json',
'Prefer' => 'return=representation'
'Prefer' => 'return=representation',
),
);
@ -182,6 +182,6 @@ class CatalogProducts {
);
}
return $this->product_factory->from_paypal_response($json);
return $this->product_factory->from_paypal_response( $json );
}
}

View file

@ -92,11 +92,11 @@ class BillingCycle {
*/
public function to_array(): array {
return array(
'frequency' => $this->frequency(),
'sequence' => $this->sequence(),
'tenure_type' => $this->tenure_type(),
'frequency' => $this->frequency(),
'sequence' => $this->sequence(),
'tenure_type' => $this->tenure_type(),
'pricing_scheme' => $this->pricing_scheme(),
'total_cycles' => $this->total_cycles(),
'total_cycles' => $this->total_cycles(),
);
}
}

View file

@ -101,12 +101,12 @@ class Plan {
public function to_array():array {
return array(
'id' => $this->id(),
'name' => $this->name(),
'product_id' => $this->product_id(),
'billing_cycles' => $this->billing_cycles(),
'id' => $this->id(),
'name' => $this->name(),
'product_id' => $this->product_id(),
'billing_cycles' => $this->billing_cycles(),
'payment_preferences' => $this->payment_preferences(),
'status' => $this->status(),
'status' => $this->status(),
);
}
}

View file

@ -6,8 +6,8 @@ use stdClass;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Plan;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
class PlanFactory
{
class PlanFactory {
/**
* @var BillingCycleFactory
*/
@ -20,12 +20,12 @@ class PlanFactory
public function __construct(
BillingCycleFactory $billing_cycle_factory,
PaymentPreferencesFactory $payment_preferences_factory
){
$this->billing_cycle_factory = $billing_cycle_factory;
) {
$this->billing_cycle_factory = $billing_cycle_factory;
$this->payment_preferences_factory = $payment_preferences_factory;
}
public function from_paypal_response(stdClass $data): Plan {
public function from_paypal_response( stdClass $data ): Plan {
if ( ! isset( $data->id ) ) {
throw new RuntimeException(
__( 'No id for given plan', 'woocommerce-paypal-payments' )
@ -48,11 +48,11 @@ class PlanFactory
}
$billing_cycles = array();
foreach ($data->billing_cycles as $billing_cycle) {
$billing_cycles[] = $this->billing_cycle_factory->from_paypal_response($billing_cycle);
foreach ( $data->billing_cycles as $billing_cycle ) {
$billing_cycles[] = $this->billing_cycle_factory->from_paypal_response( $billing_cycle );
}
$payment_preferences = $this->payment_preferences_factory->from_paypal_response($data->payment_preferences);
$payment_preferences = $this->payment_preferences_factory->from_paypal_response( $data->payment_preferences );
return new Plan(
$data->id,

View file

@ -23,7 +23,7 @@ class ProductFactory {
* @return Product
* @throws RuntimeException When JSON object is malformed.
*/
public function from_paypal_response(stdClass $data): Product {
public function from_paypal_response( stdClass $data ): Product {
if ( ! isset( $data->id ) ) {
throw new RuntimeException(
__( 'No id for product given', 'woocommerce-paypal-payments' )