Fix Psalm error

This commit is contained in:
Daniel Dudzic 2025-03-07 14:10:02 +01:00
parent 55f3ff9d3b
commit e84bc21044
No known key found for this signature in database
GPG key ID: 31B40D33E3465483

View file

@ -85,9 +85,9 @@ class GatewayRedirectService {
// Get current URL parameters.
// phpcs:disable WordPress.Security.NonceVerification.Recommended
$page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
$tab = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : '';
$section = isset( $_GET['section'] ) ? sanitize_text_field( wp_unslash( $_GET['section'] ) ) : '';
$page = isset( $_GET['page'] ) ? $this->sanitize_get_param( $_GET['page'] ) : '';
$tab = isset( $_GET['tab'] ) ? $this->sanitize_get_param( $_GET['tab'] ) : '';
$section = isset( $_GET['section'] ) ? $this->sanitize_get_param( $_GET['section'] ) : '';
// phpcs:enable WordPress.Security.NonceVerification.Recommended
// Check if we're on a WooCommerce settings page and checkout tab.
@ -108,4 +108,17 @@ class GatewayRedirectService {
exit;
}
}
/**
* Sanitizes a GET parameter that could be string or array.
*
* @param mixed $param The parameter to sanitize.
* @return string The sanitized parameter.
*/
private function sanitize_get_param( $param ): string {
if ( is_array( $param ) ) {
return '';
}
return sanitize_text_field( wp_unslash( $param ) );
}
}