🎨 Fix Psalm errors

This commit is contained in:
Daniel Dudzic 2025-06-26 13:21:49 +02:00
parent 2b025aa690
commit ba7b01dfd6
No known key found for this signature in database
GPG key ID: 31B40D33E3465483
3 changed files with 31 additions and 2 deletions

View file

@ -153,3 +153,26 @@ class WP_HTML_Tag_Processor {
return ''; return '';
} }
} }
/**
* WooCommerce Session stubs for Psalm
*/
class WC_Session {
/**
* Get session cookie.
*
* @return string|false
*/
public function get_session_cookie() {
return '';
}
/**
* Set customer session cookie.
*
* @param bool $set Whether to set the cookie.
* @return void
*/
public function set_customer_session_cookie( $set ) {
}
}

View file

@ -185,6 +185,11 @@ class Order {
return $this->payment_source; return $this->payment_source;
} }
/**
* Returns the links.
*
* @return mixed|null
*/
public function links() { public function links() {
return $this->links; return $this->links;
} }

View file

@ -83,7 +83,8 @@ class ReturnUrlEndpoint {
WC()->initialize_session(); WC()->initialize_session();
} }
if ( ! WC()->session->get_session_cookie() ) { // Set customer session cookie if not already set.
if ( WC()->session && ! WC()->session->get_session_cookie() ) {
WC()->session->set_customer_session_cookie( true ); WC()->session->set_customer_session_cookie( true );
} }
@ -98,7 +99,7 @@ class ReturnUrlEndpoint {
$wc_order_id = (int) $order->purchase_units()[0]->custom_id(); $wc_order_id = (int) $order->purchase_units()[0]->custom_id();
$wc_order = wc_get_order( $wc_order_id ); $wc_order = wc_get_order( $wc_order_id );
if ( ! $wc_order ) { if ( ! $wc_order || ! is_a( $wc_order, \WC_Order::class ) ) {
wc_add_notice( __( 'Order information is missing. Please try placing your order again.', 'woocommerce-paypal-payments' ), 'error' ); wc_add_notice( __( 'Order information is missing. Please try placing your order again.', 'woocommerce-paypal-payments' ), 'error' );
wp_safe_redirect( wc_get_checkout_url() ); wp_safe_redirect( wc_get_checkout_url() );
exit(); exit();