From e3351b8822dee53bd5726b37bbd83e32d51b51a8 Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Thu, 27 Apr 2023 09:50:41 +0200 Subject: [PATCH] Fix psalm --- .../src/Endpoint/BillingSubscriptions.php | 17 +++++++++++++++-- .../src/Endpoint/CatalogProducts.php | 15 ++++++++++++++- .../ppcp-api-client/src/Entity/BillingCycle.php | 7 ++++++- .../ppcp-api-client/src/Factory/PlanFactory.php | 2 +- .../src/SubscriptionModule.php | 4 ++-- 5 files changed, 38 insertions(+), 7 deletions(-) diff --git a/modules/ppcp-api-client/src/Endpoint/BillingSubscriptions.php b/modules/ppcp-api-client/src/Endpoint/BillingSubscriptions.php index c9244e2dd..164055065 100644 --- a/modules/ppcp-api-client/src/Endpoint/BillingSubscriptions.php +++ b/modules/ppcp-api-client/src/Endpoint/BillingSubscriptions.php @@ -10,6 +10,7 @@ declare(strict_types=1); namespace WooCommerce\PayPalCommerce\ApiClient\Endpoint; use Psr\Log\LoggerInterface; +use stdClass; use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer; use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException; use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException; @@ -135,7 +136,13 @@ class BillingSubscriptions { } } - public function cancel( string $id ) { + /** + * Cancels a Subscription. + * + * @param string $id Subscription ID. + * @return void + */ + public function cancel( string $id ): void { $data = array( 'reason' => 'Cancelled by customer', ); @@ -166,7 +173,13 @@ class BillingSubscriptions { } } - public function subscription(string $id) { + /** + * Returns a Subscription object from the given ID. + * + * @param string $id Subscription ID. + * @return stdClass + */ + public function subscription(string $id): stdClass { $bearer = $this->bearer->bearer(); $url = trailingslashit( $this->host ) . 'v1/billing/subscriptions/' . $id; $args = array( diff --git a/modules/ppcp-api-client/src/Endpoint/CatalogProducts.php b/modules/ppcp-api-client/src/Endpoint/CatalogProducts.php index 8bbc22436..2a4c8a003 100644 --- a/modules/ppcp-api-client/src/Endpoint/CatalogProducts.php +++ b/modules/ppcp-api-client/src/Endpoint/CatalogProducts.php @@ -116,7 +116,14 @@ class CatalogProducts { return $this->product_factory->from_paypal_response($json); } - public function update(string $id, array $data) { + /** + * Updates a Product. + * + * @param string $id Product ID. + * @param array $data Data to update. + * @return void + */ + public function update(string $id, array $data): void { $bearer = $this->bearer->bearer(); $url = trailingslashit( $this->host ) . 'v1/catalogs/products/' . $id; $args = array( @@ -144,6 +151,12 @@ class CatalogProducts { } } + /** + * Return a Product from the given ID. + * + * @param string $id Product ID. + * @return Product + */ public function product(string $id): Product { $bearer = $this->bearer->bearer(); $url = trailingslashit( $this->host ) . 'v1/catalogs/products/' . $id; diff --git a/modules/ppcp-api-client/src/Entity/BillingCycle.php b/modules/ppcp-api-client/src/Entity/BillingCycle.php index 138b6b3ec..01a275114 100644 --- a/modules/ppcp-api-client/src/Entity/BillingCycle.php +++ b/modules/ppcp-api-client/src/Entity/BillingCycle.php @@ -85,7 +85,12 @@ class BillingCycle { return $this->total_cycles; } - public function to_array() { + /** + * Returns Billing Cycle as array. + * + * @return array + */ + public function to_array(): array { return array( 'frequency' => $this->frequency(), 'sequence' => $this->sequence(), diff --git a/modules/ppcp-api-client/src/Factory/PlanFactory.php b/modules/ppcp-api-client/src/Factory/PlanFactory.php index 7b129ecb4..6c0097b18 100644 --- a/modules/ppcp-api-client/src/Factory/PlanFactory.php +++ b/modules/ppcp-api-client/src/Factory/PlanFactory.php @@ -52,7 +52,7 @@ class PlanFactory $billing_cycles[] = $this->billing_cycle_factory->from_paypal_response($billing_cycle); } - $payment_preferences = $this->payment_preferences_factory->from_paypal_response($data->payment_preferences) ?? array(); + $payment_preferences = $this->payment_preferences_factory->from_paypal_response($data->payment_preferences); return new Plan( $data->id, diff --git a/modules/ppcp-subscription/src/SubscriptionModule.php b/modules/ppcp-subscription/src/SubscriptionModule.php index 3d978f1af..5287f9375 100644 --- a/modules/ppcp-subscription/src/SubscriptionModule.php +++ b/modules/ppcp-subscription/src/SubscriptionModule.php @@ -152,10 +152,10 @@ class SubscriptionModule implements ModuleInterface { return; } + $nonce = wc_clean(wp_unslash($_POST['_wcsnonce'])) ?? ''; if ( $subscriptions_mode !== 'subscriptions_api' - || empty( $_POST['_wcsnonce'] ) - || ! wp_verify_nonce( wc_clean( wp_unslash( $_POST['_wcsnonce'] ) ), 'wcs_subscription_meta' ) ) { + || ! wp_verify_nonce( $nonce, 'wcs_subscription_meta' ) ) { return; }