Merge pull request #938 from woocommerce/PCP-946-multiple-php-warnings-php-8

Multiple PHP warnings (PHP8)
This commit is contained in:
Emili Castells 2022-11-02 16:44:36 +01:00 committed by GitHub
commit 0c756c0667
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 19 deletions

View file

@ -9,6 +9,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
use stdClass;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
/**
@ -43,11 +44,11 @@ class PaymentToken {
* PaymentToken constructor.
*
* @param string $id The Id.
* @param stdClass $source The source.
* @param string $type The type.
* @param \stdClass $source The source.
* @throws RuntimeException When the type is not valid.
*/
public function __construct( string $id, string $type = self::TYPE_PAYMENT_METHOD_TOKEN, \stdClass $source ) {
public function __construct( string $id, stdClass $source, string $type = self::TYPE_PAYMENT_METHOD_TOKEN ) {
if ( ! in_array( $type, self::get_valid_types(), true ) ) {
throw new RuntimeException(
__( 'Not a valid payment source type.', 'woocommerce-paypal-payments' )

View file

@ -9,6 +9,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient\Factory;
use stdClass;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentToken;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
@ -25,7 +26,7 @@ class PaymentTokenFactory {
* @return PaymentToken
* @throws RuntimeException When JSON object is malformed.
*/
public function from_paypal_response( \stdClass $data ): PaymentToken {
public function from_paypal_response( stdClass $data ): PaymentToken {
if ( ! isset( $data->id ) ) {
throw new RuntimeException(
__( 'No id for payment token given', 'woocommerce-paypal-payments' )
@ -34,8 +35,8 @@ class PaymentTokenFactory {
return new PaymentToken(
$data->id,
( isset( $data->type ) ) ? $data->type : PaymentToken::TYPE_PAYMENT_METHOD_TOKEN,
$data->source
$data->source,
( isset( $data->type ) ) ? $data->type : PaymentToken::TYPE_PAYMENT_METHOD_TOKEN
);
}

View file

@ -9,6 +9,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\Compat\PPEC;
use stdClass;
use WooCommerce\PayPalCommerce\Subscription\RenewalHandler;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentToken;
@ -125,7 +126,7 @@ class SubscriptionsHandler {
$billing_agreement_id = $order->get_meta( '_ppec_billing_agreement_id', true );
if ( $billing_agreement_id ) {
$token = new PaymentToken( $billing_agreement_id, 'BILLING_AGREEMENT', new \stdClass() );
$token = new PaymentToken( $billing_agreement_id, new stdClass(), 'BILLING_AGREEMENT' );
}
}

View file

@ -251,6 +251,13 @@ class PayUponInvoice {
$order = $this->pui_order_endpoint->order( $order_id );
if (
property_exists( $order, 'payment_source' )
&& property_exists( $order->payment_source, 'pay_upon_invoice' )
&& property_exists( $order->payment_source->pay_upon_invoice, 'payment_reference' )
&& property_exists( $order->payment_source->pay_upon_invoice, 'deposit_bank_details' )
) {
$payment_instructions = array(
$order->payment_source->pay_upon_invoice->payment_reference,
$order->payment_source->pay_upon_invoice->deposit_bank_details,
@ -261,6 +268,7 @@ class PayUponInvoice {
);
$wc_order->save_meta_data();
$this->logger->info( "Ratepay payment instructions added to order #{$wc_order->get_id()}." );
}
$capture = $this->capture_factory->from_paypal_response( $order->purchase_units[0]->payments->captures[0] );
$breakdown = $capture->seller_receivable_breakdown();

View file

@ -52,7 +52,7 @@ class PaymentTokenRepositoryTest extends TestCase
{
$id = 1;
$source = new \stdClass();
$paymentToken = new PaymentToken('foo', 'PAYMENT_METHOD_TOKEN', $source);
$paymentToken = new PaymentToken('foo', $source, 'PAYMENT_METHOD_TOKEN');
when('get_user_meta')->justReturn([]);
$this->endpoint->shouldReceive('for_user')