Fix phpcs (WIP)

This commit is contained in:
Emili Castells Guasch 2023-05-02 14:28:36 +02:00
parent eca8a3b09c
commit 48db0851ce
13 changed files with 227 additions and 19 deletions

View file

@ -40,16 +40,22 @@ class BillingPlans {
private $bearer;
/**
* Billing cycle factory
*
* @var BillingCycleFactory
*/
private $billing_cycle_factory;
/**
* Plan factory
*
* @var PlanFactory
*/
private $plan_factory;
/**
* The logger.
*
* The logger.
*
* @var LoggerInterface
@ -59,9 +65,11 @@ class BillingPlans {
/**
* BillingPlans constructor.
*
* @param string $host The host.
* @param Bearer $bearer The bearer.
* @param LoggerInterface $logger The logger.
* @param string $host The host.
* @param Bearer $bearer The bearer.
* @param BillingCycleFactory $billing_cycle_factory Billing cycle factory.
* @param PlanFactory $plan_factory Plan factory.
* @param LoggerInterface $logger The logger.
*/
public function __construct(
string $host,
@ -80,7 +88,10 @@ class BillingPlans {
/**
* Creates a subscription plan.
*
* @param string $product_id The product id.
* @param string $name Product name.
* @param string $product_id Product ID.
* @param array $billing_cycles Billing cycles.
* @param array $payment_preferences Payment preferences.
*
* @return Plan
*
@ -131,6 +142,16 @@ class BillingPlans {
return $this->plan_factory->from_paypal_response( $json );
}
/**
* Returns a plan,
*
* @param string $id Plan ID.
*
* @return Plan
*
* @throws RuntimeException If the request fails.
* @throws PayPalApiException If the request fails.
*/
public function plan( string $id ): Plan {
$bearer = $this->bearer->bearer();
$url = trailingslashit( $this->host ) . 'v1/billing/plans/' . $id;
@ -159,6 +180,17 @@ class BillingPlans {
return $this->plan_factory->from_paypal_response( $json );
}
/**
* Updates pricing.
*
* @param string $id Plan ID.
* @param BillingCycle $billing_cycle Billing cycle.
*
* @return void
*
* @throws RuntimeException If the request fails.
* @throws PayPalApiException If the request fails.
*/
public function update_pricing( string $id, BillingCycle $billing_cycle ): void {
$data = array(
'pricing_schemes' => array(

View file

@ -140,7 +140,11 @@ class BillingSubscriptions {
* Cancels a Subscription.
*
* @param string $id Subscription ID.
*
* @return void
*
* @throws RuntimeException If the request fails.
* @throws PayPalApiException If the request fails.
*/
public function cancel( string $id ): void {
$data = array(
@ -177,7 +181,11 @@ class BillingSubscriptions {
* Returns a Subscription object from the given ID.
*
* @param string $id Subscription ID.
*
* @return stdClass
*
* @throws RuntimeException If the request fails.
* @throws PayPalApiException If the request fails.
*/
public function subscription( string $id ): stdClass {
$bearer = $this->bearer->bearer();

View file

@ -42,7 +42,10 @@ class CatalogProducts {
* @var LoggerInterface
*/
private $logger;
/**
* Product factory.
*
* @var ProductFactory
*/
private $product_factory;
@ -52,6 +55,7 @@ class CatalogProducts {
*
* @param string $host The host.
* @param Bearer $bearer The bearer.
* @param ProductFactory $product_factory Product factory.
* @param LoggerInterface $logger The logger.
*/
public function __construct(
@ -121,7 +125,11 @@ class CatalogProducts {
*
* @param string $id Product ID.
* @param array $data Data to update.
*
* @return void
*
* @throws RuntimeException If the request fails.
* @throws PayPalApiException If the request fails.
*/
public function update( string $id, array $data ): void {
$bearer = $this->bearer->bearer();
@ -155,7 +163,11 @@ class CatalogProducts {
* Return a Product from the given ID.
*
* @param string $id Product ID.
*
* @return Product
*
* @throws RuntimeException If the request fails.
* @throws PayPalApiException If the request fails.
*/
public function product( string $id ): Product {
$bearer = $this->bearer->bearer();

View file

@ -9,33 +9,55 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
/**
* Class BillingCycle
*/
class BillingCycle {
/**
* Frequency.
*
* @var array
*/
private $frequency;
/**
* Sequence.
*
* @var int
*/
private $sequence;
/**
* Tenure Type.
*
* @var string
*/
private $tenure_type;
/**
* Pricing scheme.
*
* @var array
*/
private $pricing_scheme;
/**
* Total cycles.
*
* @var int
*/
private $total_cycles;
/**
* BillingCycle constructor.
*
* @param array $frequency Frequency.
* @param int $sequence Sequence.
* @param string $tenure_type Tenure type.
* @param array $pricing_scheme Pricing scheme.
* @param int $total_cycles Total cycles.
*/
public function __construct(
array $frequency,
int $sequence,
@ -51,6 +73,8 @@ class BillingCycle {
}
/**
* Returns frequency.
*
* @return array
*/
public function frequency(): array {
@ -58,6 +82,8 @@ class BillingCycle {
}
/**
* Returns sequence.
*
* @return int
*/
public function sequence(): int {
@ -65,6 +91,8 @@ class BillingCycle {
}
/**
* Returns tenure type.
*
* @return string
*/
public function tenure_type(): string {
@ -72,6 +100,8 @@ class BillingCycle {
}
/**
* Returns pricing scheme.
*
* @return array
*/
public function pricing_scheme(): array {
@ -79,6 +109,8 @@ class BillingCycle {
}
/**
* Return total cycles.
*
* @return int
*/
public function total_cycles(): int {

View file

@ -9,27 +9,47 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
/**
* Class PaymentPreferences
*/
class PaymentPreferences {
/**
* Setup fee.
*
* @var array
*/
private $setup_fee;
/**
* Auto bill outstanding.
*
* @var bool
*/
private $auto_bill_outstanding;
/**
* Setup fee failure action.
*
* @var string
*/
private $setup_fee_failure_action;
/**
* Payment failure threshold.
*
* @var int
*/
private $payment_failure_threshold;
/**
* PaymentPreferences constructor.
*
* @param array $setup_fee Setup fee.
* @param bool $auto_bill_outstanding Auto bill outstanding.
* @param string $setup_fee_failure_action Setup fee failure action.
* @param int $payment_failure_threshold payment failure threshold.
*/
public function __construct(
array $setup_fee,
bool $auto_bill_outstanding = true,
@ -44,6 +64,8 @@ class PaymentPreferences {
}
/**
* Setup fee.
*
* @return array
*/
public function setup_fee(): array {
@ -51,6 +73,8 @@ class PaymentPreferences {
}
/**
* Auto bill outstanding.
*
* @return bool
*/
public function auto_bill_outstanding(): bool {
@ -58,6 +82,8 @@ class PaymentPreferences {
}
/**
* Setup fee failure action.
*
* @return string
*/
public function setup_fee_failure_action(): string {
@ -65,12 +91,19 @@ class PaymentPreferences {
}
/**
* Payment failure threshold.
*
* @return int
*/
public function payment_failure_threshold(): int {
return $this->payment_failure_threshold;
}
/**
* Returns Payment Preferences as array.
*
* @return array
*/
public function to_array():array {
return array(
'setup_fee' => $this->setup_fee(),

View file

@ -9,38 +9,63 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
/**
* Class Plan
*/
class Plan {
/**
* Plan ID.
*
* @var string
*/
private $id;
/**
* Plan name.
*
* @var string
*/
private $name;
/**
* Product ID.
*
* @var string
*/
private $product_id;
/**
* Billing cycles.
*
* @var array
*/
private $billing_cycles;
/**
* Payment preferences.
*
* @var PaymentPreferences
*/
private $payment_preferences;
/**
* Plan status.
*
* @var string
*/
private $status;
/**
* Plan constructor.
*
* @param string $id Plan ID.
* @param string $name Plan name.
* @param string $product_id Product ID.
* @param array $billing_cycles Billing cycles.
* @param PaymentPreferences $payment_preferences Payment preferences.
* @param string $status Plan status.
*/
public function __construct(
string $id,
string $name,
@ -58,6 +83,8 @@ class Plan {
}
/**
* Returns Plan ID.
*
* @return string
*/
public function id(): string {
@ -65,6 +92,8 @@ class Plan {
}
/**
* Returns Plan name.
*
* @return string
*/
public function name(): string {
@ -72,6 +101,8 @@ class Plan {
}
/**
* Returns Product ID.
*
* @return string
*/
public function product_id(): string {
@ -79,6 +110,8 @@ class Plan {
}
/**
* Returns Billing cycles.
*
* @return array
*/
public function billing_cycles(): array {
@ -86,6 +119,8 @@ class Plan {
}
/**
* Returns Payment preferences.
*
* @return PaymentPreferences
*/
public function payment_preferences(): PaymentPreferences {
@ -93,12 +128,19 @@ class Plan {
}
/**
* Returns Plan status.
*
* @return string
*/
public function status(): string {
return $this->status;
}
/**
* Returns Plan as array.
*
* @return array
*/
public function to_array():array {
return array(
'id' => $this->id(),

View file

@ -9,6 +9,9 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
/**
* Class Product
*/
class Product {
/**
@ -33,6 +36,8 @@ class Product {
private $description;
/**
* Product constructor.
*
* @param string $id Product ID.
* @param string $name Product name.
* @param string $description Product description.

View file

@ -13,6 +13,9 @@ use stdClass;
use WC_Product;
use WooCommerce\PayPalCommerce\ApiClient\Entity\BillingCycle;
/**
* Class BillingCycleFactory
*/
class BillingCycleFactory {
/**
@ -23,9 +26,9 @@ class BillingCycleFactory {
private $currency;
/**
* The currency.
* BillingCycleFactory constructor.
*
* @param string $currency
* @param string $currency The currency.
*/
public function __construct( string $currency ) {
$this->currency = $currency;

View file

@ -13,6 +13,9 @@ use stdClass;
use WC_Product;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentPreferences;
/**
* Class PaymentPreferencesFactory
*/
class PaymentPreferencesFactory {
/**

View file

@ -1,4 +1,11 @@
<?php
/**
* Plan Factory.
*
* @package WooCommerce\PayPalCommerce\Webhooks\Handler
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient\Factory;
@ -6,17 +13,31 @@ use stdClass;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Plan;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
/**
* Class PlanFactory
*/
class PlanFactory {
/**
* Billing cycle factory.
*
* @var BillingCycleFactory
*/
private $billing_cycle_factory;
/**
* Payment preferences factory.
*
* @var PaymentPreferencesFactory
*/
private $payment_preferences_factory;
/**
* PlanFactory constructor.
*
* @param BillingCycleFactory $billing_cycle_factory Billing cycle factory.
* @param PaymentPreferencesFactory $payment_preferences_factory Payment preferences factory.
*/
public function __construct(
BillingCycleFactory $billing_cycle_factory,
PaymentPreferencesFactory $payment_preferences_factory
@ -25,6 +46,15 @@ class PlanFactory {
$this->payment_preferences_factory = $payment_preferences_factory;
}
/**
* Returns a Plan from PayPal response.
*
* @param stdClass $data The data.
*
* @return Plan
*
* @throws RuntimeException If it could not create Plan.
*/
public function from_paypal_response( stdClass $data ): Plan {
if ( ! isset( $data->id ) ) {
throw new RuntimeException(

View file

@ -13,6 +13,9 @@ use stdClass;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Product;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
/**
* Class ProductFactory
*/
class ProductFactory {
/**