From 6c15ef21fad40121de01a1f2a3435c650b671d4d Mon Sep 17 00:00:00 2001 From: costdev Date: Mon, 4 Nov 2024 23:34:26 +0000 Subject: [PATCH] Coding Standards: Apply PHPCBF to codebase. --- includes/autoload.php | 2 +- includes/class-admin-settings.php | 126 +++++++++--------- includes/class-api-rewrite.php | 6 +- includes/class-controller.php | 3 +- includes/class-debug.php | 6 +- includes/class-plugins-screens.php | 6 +- includes/class-themes-screens.php | 14 +- .../AdminSettings_GetSettingTest.php | 4 +- tests/bootstrap.php | 2 +- 9 files changed, 84 insertions(+), 85 deletions(-) diff --git a/includes/autoload.php b/includes/autoload.php index ffbf35e..8cc0a3b 100644 --- a/includes/autoload.php +++ b/includes/autoload.php @@ -15,7 +15,7 @@ */ function aspire_update_autoloader( $class_name ) { if ( false !== strpos( $class_name, 'AspireUpdate\\' ) ) { - $class_name = strtolower( str_replace( array( 'AspireUpdate\\', '_' ), array( '', '-' ), $class_name ) ); + $class_name = strtolower( str_replace( [ 'AspireUpdate\\', '_' ], [ '', '-' ], $class_name ) ); $file = __DIR__ . DIRECTORY_SEPARATOR . 'class-' . $class_name . '.php'; if ( file_exists( $file ) ) { diff --git a/includes/class-admin-settings.php b/includes/class-admin-settings.php index 86c0a95..b472e71 100644 --- a/includes/class-admin-settings.php +++ b/includes/class-admin-settings.php @@ -44,14 +44,14 @@ class Admin_Settings { * The Constructor. */ public function __construct() { - add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', array( $this, 'register_admin_menu' ) ); - add_action( 'admin_init', array( $this, 'reset_settings' ) ); - add_action( 'admin_init', array( $this, 'register_settings' ) ); - add_action( 'admin_notices', array( $this, 'reset_admin_notice' ) ); - add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); - - add_action( 'admin_init', array( $this, 'update_settings' ) ); - add_action( 'network_admin_edit_aspireupdate-settings', array( $this, 'update_settings' ) ); + add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', [ $this, 'register_admin_menu' ] ); + add_action( 'admin_init', [ $this, 'reset_settings' ] ); + add_action( 'admin_init', [ $this, 'register_settings' ] ); + add_action( 'admin_notices', [ $this, 'reset_admin_notice' ] ); + add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ] ); + + add_action( 'admin_init', [ $this, 'update_settings' ] ); + add_action( 'network_admin_edit_aspireupdate-settings', [ $this, 'update_settings' ] ); } /** @@ -72,7 +72,7 @@ public static function get_instance() { * @return array The default values. */ private function get_default_settings() { - $options = array(); + $options = []; $options['api_host'] = 'api.aspirecloud.org'; return $options; } @@ -95,10 +95,10 @@ public function reset_settings() { wp_safe_redirect( add_query_arg( - array( + [ 'reset-success' => 'success', 'reset-success-nonce' => wp_create_nonce( 'aspireupdate-reset-success-nonce' ), - ), + ], network_admin_url( 'index.php?page=aspireupdate-settings' ) ) ); @@ -161,7 +161,7 @@ public function get_setting( $setting_name, $default_value = false ) { } if ( isset( $options['enable_debug_type'] ) && is_array( $options['enable_debug_type'] ) ) { - $debug_types = array(); + $debug_types = []; foreach ( $options['enable_debug_type'] as $debug_type_name => $debug_type_enabled ) { if ( $debug_type_enabled ) { $debug_types[] = $debug_type_name; @@ -181,7 +181,7 @@ public function get_setting( $setting_name, $default_value = false ) { * @return array An array of values as defined in the Config File. */ private function get_settings_from_config_file() { - $options = array(); + $options = []; if ( ! defined( 'AP_ENABLE' ) ) { define( 'AP_ENABLE', false ); @@ -208,7 +208,7 @@ private function get_settings_from_config_file() { } if ( ! defined( 'AP_DEBUG_TYPES' ) ) { - define( 'AP_DEBUG_TYPES', array() ); + define( 'AP_DEBUG_TYPES', [] ); } elseif ( is_array( AP_DEBUG_TYPES ) ) { $options['enable_debug_type'] = AP_DEBUG_TYPES; } @@ -241,7 +241,7 @@ public function update_settings() { update_site_option( $this->option_name, $this->sanitize_settings( wp_unslash( $_POST['aspireupdate_settings'] ) ) ); wp_safe_redirect( - add_query_arg( array( network_admin_url( 'index.php?page=aspireupdate-settings' ) ) ) + add_query_arg( [ network_admin_url( 'index.php?page=aspireupdate-settings' ) ] ) ); exit; } @@ -263,7 +263,7 @@ public function register_admin_menu() { 'AspireUpdate', is_multisite() ? 'manage_network_options' : 'manage_options', 'aspireupdate-settings', - array( $this, 'the_settings_page' ) + [ $this, 'the_settings_page' ] ); } } @@ -275,19 +275,19 @@ public function register_admin_menu() { * @return void */ public function admin_enqueue_scripts( $hook ) { - if ( ! in_array( $hook, array( 'dashboard_page_aspireupdate-settings','index_page_aspireupdate-settings' ) ) ) { + if ( ! in_array( $hook, [ 'dashboard_page_aspireupdate-settings', 'index_page_aspireupdate-settings' ], true ) ) { return; } - wp_enqueue_style( 'aspire_update_settings_css', plugin_dir_url( __DIR__ ) . 'assets/css/aspire-update.css', array(), AP_VERSION ); - wp_enqueue_script( 'aspire_update_settings_js', plugin_dir_url( __DIR__ ) . 'assets/js/aspire-update.js', array( 'jquery' ), AP_VERSION, true ); + wp_enqueue_style( 'aspire_update_settings_css', plugin_dir_url( __DIR__ ) . 'assets/css/aspire-update.css', [], AP_VERSION ); + wp_enqueue_script( 'aspire_update_settings_js', plugin_dir_url( __DIR__ ) . 'assets/js/aspire-update.js', [ 'jquery' ], AP_VERSION, true ); wp_localize_script( 'aspire_update_settings_js', 'aspireupdate', - array( + [ 'ajax_url' => network_admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'aspireupdate-ajax' ), 'domain' => Utilities::get_top_level_domain(), - ) + ] ); } @@ -298,10 +298,10 @@ public function admin_enqueue_scripts( $hook ) { */ public function the_settings_page() { $reset_url = add_query_arg( - array( + [ 'reset' => 'reset', 'reset-nonce' => wp_create_nonce( 'aspireupdate-reset-nonce' ), - ), + ], network_admin_url( 'index.php?page=aspireupdate-settings' ) ); ?> @@ -408,9 +408,9 @@ public function register_settings() { register_setting( $this->option_group, $this->option_name, - array( - 'sanitize_callback' => array( $this, 'sanitize_settings' ), - ) + [ + 'sanitize_callback' => [ $this, 'sanitize_settings' ], + ] ); add_settings_section( @@ -418,64 +418,64 @@ public function register_settings() { esc_html__( 'API Configuration', 'AspireUpdate' ), null, 'aspireupdate-settings', - array( + [ 'before_section' => '
', 'after_section' => '
', - ) + ] ); add_settings_field( 'enable', esc_html__( 'Enable AspireUpdate API Rewrites', 'AspireUpdate' ), - array( $this, 'add_settings_field_callback' ), + [ $this, 'add_settings_field_callback' ], 'aspireupdate-settings', 'aspireupdate_settings_section', - array( + [ 'id' => 'enable', 'type' => 'checkbox', 'data' => $options, - ) + ] ); add_settings_field( 'api_host', esc_html__( 'API Host', 'AspireUpdate' ), - array( $this, 'add_settings_field_callback' ), + [ $this, 'add_settings_field_callback' ], 'aspireupdate-settings', 'aspireupdate_settings_section', - array( + [ 'id' => 'api_host', 'type' => 'hosts', 'data' => $options, 'description' => esc_html__( 'Your new API Host.', 'AspireUpdate' ), - 'options' => array( - array( + 'options' => [ + [ 'value' => 'api.aspirecloud.org', 'label' => 'AspireCloud (api.aspirecloud.org)', 'require-api-key' => 'false', 'api-key-url' => 'api.aspirecloud.org/v1/apitoken', - ), - array( + ], + [ 'value' => 'other', 'label' => esc_html__( 'Other', 'AspireUpdate' ), 'require-api-key' => 'false', - ), - ), - ) + ], + ], + ] ); add_settings_field( 'api_key', esc_html__( 'API Key', 'AspireUpdate' ), - array( $this, 'add_settings_field_callback' ), + [ $this, 'add_settings_field_callback' ], 'aspireupdate-settings', 'aspireupdate_settings_section', - array( + [ 'id' => 'api_key', 'type' => 'api-key', 'data' => $options, 'description' => esc_html__( 'Provides an API key for repositories that may require authentication.', 'AspireUpdate' ), - ) + ] ); add_settings_section( @@ -483,58 +483,58 @@ public function register_settings() { esc_html__( 'API Debug Configuration', 'AspireUpdate' ), null, 'aspireupdate-settings', - array( + [ 'before_section' => '
', 'after_section' => '
', - ) + ] ); add_settings_field( 'enable_debug', esc_html__( 'Enable Debug Mode', 'AspireUpdate' ), - array( $this, 'add_settings_field_callback' ), + [ $this, 'add_settings_field_callback' ], 'aspireupdate-settings', 'aspireupdate_debug_settings_section', - array( + [ 'id' => 'enable_debug', 'type' => 'checkbox', 'data' => $options, 'description' => esc_html__( 'Enables debug mode for the plugin.', 'AspireUpdate' ), - ) + ] ); add_settings_field( 'enable_debug_type', esc_html__( 'Enable Debug Type', 'AspireUpdate' ), - array( $this, 'add_settings_field_callback' ), + [ $this, 'add_settings_field_callback' ], 'aspireupdate-settings', 'aspireupdate_debug_settings_section', - array( + [ 'id' => 'enable_debug_type', 'type' => 'checkbox-group', 'data' => $options, - 'options' => array( + 'options' => [ 'request' => esc_html__( 'Request', 'AspireUpdate' ), 'response' => esc_html__( 'Response', 'AspireUpdate' ), 'string' => esc_html__( 'String', 'AspireUpdate' ), - ), + ], 'description' => esc_html__( 'Outputs the request URL and headers / response headers and body / string that is being rewritten.', 'AspireUpdate' ), - ) + ] ); add_settings_field( 'disable_ssl_verification', esc_html__( 'Disable SSL Verification', 'AspireUpdate' ), - array( $this, 'add_settings_field_callback' ), + [ $this, 'add_settings_field_callback' ], 'aspireupdate-settings', 'aspireupdate_debug_settings_section', - array( + [ 'id' => 'disable_ssl_verification', 'type' => 'checkbox', 'data' => $options, 'class' => 'advanced-setting', 'description' => esc_html__( 'Disables the verification of SSL to allow local testing.', 'AspireUpdate' ), - ) + ] ); } @@ -545,15 +545,15 @@ public function register_settings() { * * @return void Echos the Field HTML. */ - public function add_settings_field_callback( $args = array() ) { + public function add_settings_field_callback( $args = [] ) { - $defaults = array( + $defaults = [ 'id' => '', 'type' => 'text', 'description' => '', - 'data' => array(), - 'options' => array(), - ); + 'data' => [], + 'options' => [], + ]; $args = wp_parse_args( $args, $defaults ); $id = $args['id']; $type = $args['type']; @@ -642,7 +642,7 @@ class="regular-text" * @return array The processed Input. */ public function sanitize_settings( $input ) { - $sanitized_input = array(); + $sanitized_input = []; $sanitized_input['enable'] = (int) ! empty( $input['enable'] ); $sanitized_input['api_key'] = sanitize_text_field( $input['api_key'] ?? '' ); @@ -653,7 +653,7 @@ public function sanitize_settings( $input ) { if ( isset( $input['enable_debug_type'] ) && is_array( $input['enable_debug_type'] ) ) { $sanitized_input['enable_debug_type'] = array_map( 'sanitize_text_field', $input['enable_debug_type'] ); } else { - $sanitized_input['enable_debug_type'] = array(); + $sanitized_input['enable_debug_type'] = []; } $sanitized_input['disable_ssl_verification'] = (int) ! empty( $input['disable_ssl_verification'] ); diff --git a/includes/class-api-rewrite.php b/includes/class-api-rewrite.php index 86836f5..9002907 100644 --- a/includes/class-api-rewrite.php +++ b/includes/class-api-rewrite.php @@ -45,7 +45,7 @@ public function __construct( $redirected_host, $disable_ssl ) { $this->redirected_host = strtolower( $redirected_host ); } $this->disable_ssl = $disable_ssl; - add_filter( 'pre_http_request', array( $this, 'pre_http_request' ), 10, 3 ); + add_filter( 'pre_http_request', [ $this, 'pre_http_request' ], 10, 3 ); } /** @@ -80,9 +80,9 @@ public function pre_http_request( $response, $parsed_args, $url ) { /** * Temporarily Unhook Filter to prevent recursion. */ - remove_filter( 'pre_http_request', array( $this, 'pre_http_request' ) ); + remove_filter( 'pre_http_request', [ $this, 'pre_http_request' ] ); $response = wp_remote_request( $updated_url, $parsed_args ); - add_filter( 'pre_http_request', array( $this, 'pre_http_request' ), 10, 3 ); + add_filter( 'pre_http_request', [ $this, 'pre_http_request' ], 10, 3 ); Debug::log_response( $response ); diff --git a/includes/class-controller.php b/includes/class-controller.php index faf5d42..632c8ec 100644 --- a/includes/class-controller.php +++ b/includes/class-controller.php @@ -21,7 +21,7 @@ public function __construct() { $this->api_rewrite(); - add_action( 'init', array( $this, 'load_textdomain' ) ); + add_action( 'init', [ $this, 'load_textdomain' ] ); } /** @@ -56,5 +56,4 @@ private function api_rewrite() { public function load_textdomain() { \load_plugin_textdomain( 'AspireUpdate', false, AP_PATH . '/languages/' ); } - } diff --git a/includes/class-debug.php b/includes/class-debug.php index 21e07f5..5a64b24 100644 --- a/includes/class-debug.php +++ b/includes/class-debug.php @@ -109,7 +109,7 @@ private static function format_message( $message ) { public static function log_string( $message ) { $admin_settings = Admin_Settings::get_instance(); $debug_mode = $admin_settings->get_setting( 'enable_debug', false ); - $debug_types = $admin_settings->get_setting( 'enable_debug_type', array() ); + $debug_types = $admin_settings->get_setting( 'enable_debug_type', [] ); if ( $debug_mode && is_array( $debug_types ) && in_array( 'string', $debug_types, true ) ) { self::log( $message, 'string' ); } @@ -123,7 +123,7 @@ public static function log_string( $message ) { public static function log_request( $message ) { $admin_settings = Admin_Settings::get_instance(); $debug_mode = $admin_settings->get_setting( 'enable_debug', false ); - $debug_types = $admin_settings->get_setting( 'enable_debug_type', array() ); + $debug_types = $admin_settings->get_setting( 'enable_debug_type', [] ); if ( $debug_mode && is_array( $debug_types ) && in_array( 'request', $debug_types, true ) ) { self::log( $message, 'request' ); } @@ -137,7 +137,7 @@ public static function log_request( $message ) { public static function log_response( $message ) { $admin_settings = Admin_Settings::get_instance(); $debug_mode = $admin_settings->get_setting( 'enable_debug', false ); - $debug_types = $admin_settings->get_setting( 'enable_debug_type', array() ); + $debug_types = $admin_settings->get_setting( 'enable_debug_type', [] ); if ( $debug_mode && is_array( $debug_types ) && in_array( 'response', $debug_types, true ) ) { self::log( $message, 'response' ); } diff --git a/includes/class-plugins-screens.php b/includes/class-plugins-screens.php index b69e40e..732c6eb 100644 --- a/includes/class-plugins-screens.php +++ b/includes/class-plugins-screens.php @@ -23,10 +23,10 @@ class Plugins_Screens { * * @var array */ - protected $unsupported_filters = array( + protected $unsupported_filters = [ 'featured', 'favorites', - ); + ]; /** * The Constructor. @@ -34,7 +34,7 @@ class Plugins_Screens { public function __construct() { $admin_settings = Admin_Settings::get_instance(); if ( $admin_settings->get_setting( 'enable', false ) ) { - add_filter( 'install_plugins_tabs', array( $this, 'remove_unused_filter_tabs' ) ); + add_filter( 'install_plugins_tabs', [ $this, 'remove_unused_filter_tabs' ] ); } } diff --git a/includes/class-themes-screens.php b/includes/class-themes-screens.php index 207fecb..423fc9a 100644 --- a/includes/class-themes-screens.php +++ b/includes/class-themes-screens.php @@ -23,9 +23,9 @@ class Themes_Screens { * * @var array */ - protected $unsupported_filters = array( + protected $unsupported_filters = [ 'favorites', - ); + ]; /** * The Constructor. @@ -33,8 +33,8 @@ class Themes_Screens { public function __construct() { $admin_settings = Admin_Settings::get_instance(); if ( $admin_settings->get_setting( 'enable', false ) ) { - add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); - add_action( 'load-theme-install.php', array( $this, 'redirect_to_theme_install' ) ); + add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ] ); + add_action( 'load-theme-install.php', [ $this, 'redirect_to_theme_install' ] ); } } @@ -65,13 +65,13 @@ public function admin_enqueue_scripts( $hook ) { wp_register_style( 'aspire_update_themes_screens_css', false, - array(), + [], AP_VERSION ); wp_enqueue_style( 'aspire_update_themes_screens_css' ); - $css_selectors = array(); + $css_selectors = []; foreach ( $this->unsupported_filters as $filter ) { $css_selectors[] = '.wp-filter .filter-links a[data-sort="' . $filter . '"]'; } @@ -94,7 +94,7 @@ public function redirect_to_theme_install() { if ( $nonce && ! wp_verify_nonce( $nonce, 'query-themes' ) ) { return; } - + $browse = isset( $_GET['browse'] ) ? sanitize_text_field( wp_unslash( $_GET['browse'] ) ) : ''; if ( ! in_array( $browse, $this->unsupported_filters, true ) ) { return; diff --git a/tests/AdminSettings/AdminSettings_GetSettingTest.php b/tests/AdminSettings/AdminSettings_GetSettingTest.php index d54aed0..9516f90 100644 --- a/tests/AdminSettings/AdminSettings_GetSettingTest.php +++ b/tests/AdminSettings/AdminSettings_GetSettingTest.php @@ -7,13 +7,13 @@ /** * Tests for Admin_Settings::get_setting() - * + * * @covers \AspireUpdate\Admin_Settings::get_setting */ class AdminSettings_GetSettingTest extends WP_UnitTestCase { /** * Test that the default 'api_host' value is retrieved. - * + * * @covers \AspireUpdate\Admin_Settings::get_default_settings */ public function test_should_get_default_api_host() { diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 6daa840..1f8efc6 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -31,7 +31,7 @@ * Manually load the plugin being tested. */ function _manually_load_plugin() { - require dirname( dirname( __FILE__ ) ) . '/aspire-update.php'; + require dirname( __DIR__ ) . '/aspire-update.php'; } tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );