From 069e7efbf859452de3cfebe2fc7eacf840ddd72c Mon Sep 17 00:00:00 2001 From: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> Date: Mon, 24 Jul 2023 15:57:02 +1000 Subject: [PATCH 01/14] Fix auto-fixable coding standard errors and warnings. --- gateway-payfast.php | 12 +- ...lass-wc-gateway-payfast-blocks-support.php | 14 +- includes/class-wc-gateway-payfast-privacy.php | 38 ++-- includes/class-wc-gateway-payfast.php | 189 +++++++++--------- 4 files changed, 132 insertions(+), 121 deletions(-) diff --git a/gateway-payfast.php b/gateway-payfast.php index 5e1d281..a681bfb 100644 --- a/gateway-payfast.php +++ b/gateway-payfast.php @@ -22,6 +22,7 @@ /** * Initialize the gateway. + * * @since 1.0.0 */ function woocommerce_payfast_init() { @@ -29,8 +30,8 @@ function woocommerce_payfast_init() { return; } - require_once( plugin_basename( 'includes/class-wc-gateway-payfast.php' ) ); - require_once( plugin_basename( 'includes/class-wc-gateway-payfast-privacy.php' ) ); + require_once plugin_basename( 'includes/class-wc-gateway-payfast.php' ); + require_once plugin_basename( 'includes/class-wc-gateway-payfast-privacy.php' ); load_plugin_textdomain( 'woocommerce-gateway-payfast', false, trailingslashit( dirname( plugin_basename( __FILE__ ) ) ) ); add_filter( 'woocommerce_payment_gateways', 'woocommerce_payfast_add_gateway' ); } @@ -39,8 +40,8 @@ function woocommerce_payfast_init() { function woocommerce_payfast_plugin_links( $links ) { $settings_url = add_query_arg( array( - 'page' => 'wc-settings', - 'tab' => 'checkout', + 'page' => 'wc-settings', + 'tab' => 'checkout', 'section' => 'wc_gateway_payfast', ), admin_url( 'admin.php' ) @@ -59,6 +60,7 @@ function woocommerce_payfast_plugin_links( $links ) { /** * Add the gateway to WooCommerce + * * @since 1.0.0 */ function woocommerce_payfast_add_gateway( $methods ) { @@ -74,7 +76,7 @@ function woocommerce_payfast_woocommerce_blocks_support() { add_action( 'woocommerce_blocks_payment_method_type_registration', function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) { - $payment_method_registry->register( new WC_PayFast_Blocks_Support ); + $payment_method_registry->register( new WC_PayFast_Blocks_Support() ); } ); } diff --git a/includes/class-wc-gateway-payfast-blocks-support.php b/includes/class-wc-gateway-payfast-blocks-support.php index 6469d32..eb84349 100644 --- a/includes/class-wc-gateway-payfast-blocks-support.php +++ b/includes/class-wc-gateway-payfast-blocks-support.php @@ -18,7 +18,7 @@ final class WC_PayFast_Blocks_Support extends AbstractPaymentMethodType { * Initializes the payment method type. */ public function initialize() { - $this->settings = get_option( 'woocommerce_payfast_settings', [] ); + $this->settings = get_option( 'woocommerce_payfast_settings', array() ); } /** @@ -27,8 +27,8 @@ public function initialize() { * @return boolean */ public function is_active() { - $payment_gateways_class = WC()->payment_gateways(); - $payment_gateways = $payment_gateways_class->payment_gateways(); + $payment_gateways_class = WC()->payment_gateways(); + $payment_gateways = $payment_gateways_class->payment_gateways(); return $payment_gateways['payfast']->is_available(); } @@ -41,7 +41,7 @@ public function is_active() { public function get_payment_method_script_handles() { $asset_path = WC_GATEWAY_PAYFAST_PATH . '/build/index.asset.php'; $version = WC_GATEWAY_PAYFAST_VERSION; - $dependencies = []; + $dependencies = array(); if ( file_exists( $asset_path ) ) { $asset = require $asset_path; $version = is_array( $asset ) && isset( $asset['version'] ) @@ -62,7 +62,7 @@ public function get_payment_method_script_handles() { 'wc-payfast-blocks-integration', 'woocommerce-gateway-payfast' ); - return [ 'wc-payfast-blocks-integration' ]; + return array( 'wc-payfast-blocks-integration' ); } /** @@ -71,12 +71,12 @@ public function get_payment_method_script_handles() { * @return array */ public function get_payment_method_data() { - return [ + return array( 'title' => $this->get_setting( 'title' ), 'description' => $this->get_setting( 'description' ), 'supports' => $this->get_supported_features(), 'logo_url' => WC_GATEWAY_PAYFAST_URL . '/assets/images/icon.png', - ]; + ); } /** diff --git a/includes/class-wc-gateway-payfast-privacy.php b/includes/class-wc-gateway-payfast-privacy.php index 67c76c4..6ff5d22 100644 --- a/includes/class-wc-gateway-payfast-privacy.php +++ b/includes/class-wc-gateway-payfast-privacy.php @@ -6,7 +6,6 @@ class WC_Gateway_PayFast_Privacy extends WC_Abstract_Privacy { /** * Constructor - * */ public function __construct() { parent::__construct( __( 'Payfast', 'woocommerce-gateway-payfast' ) ); @@ -23,15 +22,15 @@ public function __construct() { /** * Returns a list of orders that are using one of Payfast's payment methods. * - * @param string $email_address - * @param int $page + * @param string $email_address + * @param int $page * * @return array WP_Post */ protected function get_payfast_orders( $email_address, $page ) { $user = get_user_by( 'email', $email_address ); // Check if user has an ID in the DB to load stored personal data. - $order_query = array( + $order_query = array( 'payment_method' => 'payfast', 'limit' => 10, 'page' => $page, @@ -48,15 +47,16 @@ protected function get_payfast_orders( $email_address, $page ) { /** * Gets the message of the privacy to display. - * */ public function get_privacy_message() { - return wpautop( sprintf( + return wpautop( + sprintf( /* translators: 1: anchor tag 2: closing anchor tag */ - esc_html__( 'By using this extension, you may be storing personal data or sharing data with an external service. %1$sLearn more about how this works, including what you may want to include in your privacy policy.%2$s', 'woocommerce-gateway-payfast' ), + esc_html__( 'By using this extension, you may be storing personal data or sharing data with an external service. %1$sLearn more about how this works, including what you may want to include in your privacy policy.%2$s', 'woocommerce-gateway-payfast' ), '', '' - ) ); + ) + ); } /** @@ -113,7 +113,7 @@ public function subscriptions_data_exporter( $email_address, $page = 1 ) { $data_to_export = array(); $meta_query = array( - 'relation' => 'AND', + 'relation' => 'AND', array( 'key' => '_payment_method', 'value' => 'payfast', @@ -126,10 +126,10 @@ public function subscriptions_data_exporter( $email_address, $page = 1 ) { ), ); - $subscription_query = array( - 'posts_per_page' => 10, - 'page' => $page, - 'meta_query' => $meta_query, + $subscription_query = array( + 'posts_per_page' => 10, + 'page' => $page, + 'meta_query' => $meta_query, ); $subscriptions = wcs_get_subscriptions( $subscription_query ); @@ -179,14 +179,14 @@ public function order_data_eraser( $email_address, $page ) { $order = wc_get_order( $order->get_id() ); list( $removed, $retained, $msgs ) = $this->maybe_handle_order( $order ); - $items_removed |= $removed; - $items_retained |= $retained; - $messages = array_merge( $messages, $msgs ); + $items_removed |= $removed; + $items_retained |= $retained; + $messages = array_merge( $messages, $msgs ); list( $removed, $retained, $msgs ) = $this->maybe_handle_subscription( $order ); - $items_removed |= $removed; - $items_retained |= $retained; - $messages = array_merge( $messages, $msgs ); + $items_removed |= $removed; + $items_retained |= $retained; + $messages = array_merge( $messages, $msgs ); } // Tell core if we have more orders to work on still diff --git a/includes/class-wc-gateway-payfast.php b/includes/class-wc-gateway-payfast.php index 3903f69..8e0b24a 100644 --- a/includes/class-wc-gateway-payfast.php +++ b/includes/class-wc-gateway-payfast.php @@ -30,15 +30,15 @@ class WC_Gateway_PayFast extends WC_Payment_Gateway { * Constructor */ public function __construct() { - $this->version = WC_GATEWAY_PAYFAST_VERSION; - $this->id = 'payfast'; - $this->method_title = __( 'Payfast', 'woocommerce-gateway-payfast' ); + $this->version = WC_GATEWAY_PAYFAST_VERSION; + $this->id = 'payfast'; + $this->method_title = __( 'Payfast', 'woocommerce-gateway-payfast' ); /* translators: 1: a href link 2: closing href */ - $this->method_description = sprintf( __( 'Payfast works by sending the user to %1$sPayfast%2$s to enter their payment information.', 'woocommerce-gateway-payfast' ), '', '' ); - $this->icon = WP_PLUGIN_URL . '/' . plugin_basename( dirname( dirname( __FILE__ ) ) ) . '/assets/images/icon.png'; - $this->debug_email = get_option( 'admin_email' ); + $this->method_description = sprintf( __( 'Payfast works by sending the user to %1$sPayfast%2$s to enter their payment information.', 'woocommerce-gateway-payfast' ), '', '' ); + $this->icon = WP_PLUGIN_URL . '/' . plugin_basename( dirname( dirname( __FILE__ ) ) ) . '/assets/images/icon.png'; + $this->debug_email = get_option( 'admin_email' ); $this->available_countries = array( 'ZA' ); - $this->available_currencies = (array)apply_filters('woocommerce_gateway_payfast_available_currencies', array( 'ZAR' ) ); + $this->available_currencies = (array) apply_filters( 'woocommerce_gateway_payfast_available_currencies', array( 'ZAR' ) ); // Supported functionality $this->supports = array( @@ -68,7 +68,7 @@ public function __construct() { $this->url = 'https://www.payfast.co.za/eng/process?aff=woo-free'; $this->validate_url = 'https://www.payfast.co.za/eng/query/validate'; $this->title = $this->get_option( 'title' ); - $this->response_url = add_query_arg( 'wc-api', 'WC_Gateway_PayFast', home_url( '/' ) ); + $this->response_url = add_query_arg( 'wc-api', 'WC_Gateway_PayFast', home_url( '/' ) ); $this->send_debug_email = 'yes' === $this->get_option( 'send_debug_email' ); $this->description = $this->get_option( 'description' ); $this->enabled = 'yes' === $this->get_option( 'enabled' ) ? 'yes' : 'no'; @@ -92,8 +92,8 @@ public function __construct() { add_action( 'admin_notices', array( $this, 'admin_notices' ) ); // Add fees to order. - add_action( 'woocommerce_admin_order_totals_after_total', array( $this, 'display_order_fee') ); - add_action( 'woocommerce_admin_order_totals_after_total', array( $this, 'display_order_net'), 20 ); + add_action( 'woocommerce_admin_order_totals_after_total', array( $this, 'display_order_fee' ) ); + add_action( 'woocommerce_admin_order_totals_after_total', array( $this, 'display_order_net' ), 20 ); // Change Payment Method actions. add_action( 'woocommerce_subscription_payment_method_updated_from_' . $this->id, array( $this, 'maybe_cancel_subscription_token' ), 10, 2 ); @@ -106,47 +106,47 @@ public function __construct() { */ public function init_form_fields() { $this->form_fields = array( - 'enabled' => array( + 'enabled' => array( 'title' => __( 'Enable/Disable', 'woocommerce-gateway-payfast' ), 'label' => __( 'Enable Payfast', 'woocommerce-gateway-payfast' ), 'type' => 'checkbox', 'description' => __( 'This controls whether or not this gateway is enabled within WooCommerce.', 'woocommerce-gateway-payfast' ), - 'default' => 'no', // User should enter the required information before enabling the gateway. + 'default' => 'no', // User should enter the required information before enabling the gateway. 'desc_tip' => true, ), - 'title' => array( + 'title' => array( 'title' => __( 'Title', 'woocommerce-gateway-payfast' ), 'type' => 'text', 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-payfast' ), 'default' => __( 'Payfast', 'woocommerce-gateway-payfast' ), 'desc_tip' => true, ), - 'description' => array( + 'description' => array( 'title' => __( 'Description', 'woocommerce-gateway-payfast' ), 'type' => 'text', 'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-payfast' ), 'default' => '', 'desc_tip' => true, ), - 'testmode' => array( + 'testmode' => array( 'title' => __( 'Payfast Sandbox', 'woocommerce-gateway-payfast' ), 'type' => 'checkbox', 'description' => __( 'Place the payment gateway in development mode.', 'woocommerce-gateway-payfast' ), 'default' => 'yes', ), - 'merchant_id' => array( + 'merchant_id' => array( 'title' => __( 'Merchant ID', 'woocommerce-gateway-payfast' ), 'type' => 'text', 'description' => __( 'This is the merchant ID, received from Payfast.', 'woocommerce-gateway-payfast' ), 'default' => '', ), - 'merchant_key' => array( + 'merchant_key' => array( 'title' => __( 'Merchant Key', 'woocommerce-gateway-payfast' ), 'type' => 'text', 'description' => __( 'This is the merchant key, received from Payfast.', 'woocommerce-gateway-payfast' ), 'default' => '', ), - 'pass_phrase' => array( + 'pass_phrase' => array( 'title' => __( 'Passphrase', 'woocommerce-gateway-payfast' ), 'type' => 'text', 'description' => __( '* Required. Needed to ensure the data passed through is secure.', 'woocommerce-gateway-payfast' ), @@ -158,13 +158,13 @@ public function init_form_fields() { 'label' => __( 'Send debug e-mails for transactions through the Payfast gateway (sends on successful transaction as well).', 'woocommerce-gateway-payfast' ), 'default' => 'yes', ), - 'debug_email' => array( + 'debug_email' => array( 'title' => __( 'Who Receives Debug E-mails?', 'woocommerce-gateway-payfast' ), 'type' => 'text', 'description' => __( 'The e-mail address to which debugging error e-mails are sent when in test mode.', 'woocommerce-gateway-payfast' ), 'default' => get_option( 'admin_email' ), ), - 'enable_logging' => array( + 'enable_logging' => array( 'title' => __( 'Enable Logging', 'woocommerce-gateway-payfast' ), 'type' => 'checkbox', 'label' => __( 'Enable transaction logging for gateway.', 'woocommerce-gateway-payfast' ), @@ -182,7 +182,7 @@ public function get_required_settings_keys() { return array( 'merchant_id', 'merchant_key', - 'pass_phrase' + 'pass_phrase', ); } @@ -216,16 +216,16 @@ public function add_testmode_admin_settings_notice() { */ public function check_requirements() { - $errors = [ + $errors = array( // Check if the store currency is supported by Payfast ! in_array( get_woocommerce_currency(), $this->available_currencies ) ? 'wc-gateway-payfast-error-invalid-currency' : null, // Check if user entered the merchant ID - 'yes' !== $this->get_option( 'testmode' ) && empty( $this->get_option( 'merchant_id' ) ) ? 'wc-gateway-payfast-error-missing-merchant-id' : null, + 'yes' !== $this->get_option( 'testmode' ) && empty( $this->get_option( 'merchant_id' ) ) ? 'wc-gateway-payfast-error-missing-merchant-id' : null, // Check if user entered the merchant key 'yes' !== $this->get_option( 'testmode' ) && empty( $this->get_option( 'merchant_key' ) ) ? 'wc-gateway-payfast-error-missing-merchant-key' : null, // Check if user entered a pass phrase - 'yes' !== $this->get_option( 'testmode' ) && empty( $this->get_option( 'pass_phrase' ) ) ? 'wc-gateway-payfast-error-missing-pass-phrase' : null - ]; + 'yes' !== $this->get_option( 'testmode' ) && empty( $this->get_option( 'pass_phrase' ) ) ? 'wc-gateway-payfast-error-missing-pass-phrase' : null, + ); return array_filter( $errors ); } @@ -276,7 +276,7 @@ public function admin_options() { * @since 1.0.0 */ public function generate_payfast_form( $order_id ) { - $order = wc_get_order( $order_id ); + $order = wc_get_order( $order_id ); // Construct variables for post $this->data_to_send = array( // Merchant details @@ -353,33 +353,33 @@ public function generate_payfast_form( $order_id ) { $this->data_to_send = apply_filters( 'woocommerce_gateway_payfast_payment_data_to_send', $this->data_to_send, $order_id ); $payfast_args_array = array(); - $sign_strings = []; + $sign_strings = array(); foreach ( $this->data_to_send as $key => $value ) { - if ($key !== 'source') { - $sign_strings[] = esc_attr( $key ) . '=' . urlencode(str_replace('&', '&', trim( $value ))); + if ( $key !== 'source' ) { + $sign_strings[] = esc_attr( $key ) . '=' . urlencode( str_replace( '&', '&', trim( $value ) ) ); } $payfast_args_array[] = ''; } - if (!empty($this->pass_phrase)) { - $payfast_args_array[] = ''; + if ( ! empty( $this->pass_phrase ) ) { + $payfast_args_array[] = ''; } else { - $payfast_args_array[] = ''; + $payfast_args_array[] = ''; } echo '