From 0284fa2eb5bd6d3975c53074dafdc6e9c3479829 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Thu, 31 Aug 2023 13:46:35 +0200 Subject: [PATCH 1/4] Update `wp-cli/wp-cli-tests` --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 0f1d6bb5..e092d9af 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ "wp-cli/wp-cli": "^2.5" }, "require-dev": { - "wp-cli/wp-cli-tests": "^3.1" + "wp-cli/wp-cli-tests": "^4" }, "config": { "process-timeout": 7200, From 6feb7ab32f7dd4335f89e0b3690d50e6bc2cd6f2 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Thu, 31 Aug 2023 13:46:39 +0200 Subject: [PATCH 2/4] Remove invalid config --- phpcs.xml.dist | 1 - 1 file changed, 1 deletion(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 589c5679..961b6a37 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -44,7 +44,6 @@ See: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#naming-conventions-prefix-everything-in-the-global-namespace --> - From 4e9543642daf279c6e80281966cc214b26d5985a Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Thu, 31 Aug 2023 13:46:55 +0200 Subject: [PATCH 3/4] Fix all auto-fixable issues --- profile-command.php | 2 +- src/Command.php | 5 ++--- src/Formatter.php | 2 +- src/Logger.php | 11 +++++------ src/Profiler.php | 14 ++++++-------- 5 files changed, 15 insertions(+), 19 deletions(-) diff --git a/profile-command.php b/profile-command.php index 300d3a02..bb6fec37 100644 --- a/profile-command.php +++ b/profile-command.php @@ -4,7 +4,7 @@ return; } -$wpcli_profile_autoloader = dirname( __FILE__ ) . '/vendor/autoload.php'; +$wpcli_profile_autoloader = __DIR__ . '/vendor/autoload.php'; if ( file_exists( $wpcli_profile_autoloader ) ) { require_once $wpcli_profile_autoloader; } diff --git a/src/Command.php b/src/Command.php index 4971678c..0952e9cb 100644 --- a/src/Command.php +++ b/src/Command.php @@ -324,7 +324,7 @@ public function eval_( $args, $assoc_args ) { self::profile_eval_ish( $assoc_args, - function() use ( $statement ) { + function () use ( $statement ) { eval( $statement ); // phpcs:ignore Squiz.PHP.Eval.Discouraged -- no other way oround here }, $order, @@ -388,7 +388,7 @@ public function eval_file( $args, $assoc_args ) { self::profile_eval_ish( $assoc_args, - function() use ( $file ) { + function () use ( $file ) { self::include_file( $file ); }, $order, @@ -493,5 +493,4 @@ private static function shine_spotlight( $loggers, $metrics ) { return $loggers; } - } diff --git a/src/Formatter.php b/src/Formatter.php index a9693477..c91c1111 100644 --- a/src/Formatter.php +++ b/src/Formatter.php @@ -92,7 +92,7 @@ private function show_table( $order, $orderby, $items, $fields, $include_total ) if ( $orderby ) { usort( $items, - function( $a, $b ) use ( $order, $orderby ) { + function ( $a, $b ) use ( $order, $orderby ) { $orderby_array = 'ASC' === $order ? array( $a, $b ) : array( $b, $a ); list( $first, $second ) = $orderby_array; diff --git a/src/Logger.php b/src/Logger.php index c2018758..b59e30a7 100644 --- a/src/Logger.php +++ b/src/Logger.php @@ -70,7 +70,7 @@ public function stop() { for ( $i = $this->query_offset; $i < $query_total_count; $i++ ) { $this->query_time += $wpdb->queries[ $i ][1]; - $this->query_count++; + ++$this->query_count; } } @@ -101,10 +101,10 @@ public function stop() { * Start this logger's hook timer */ public function start_hook_timer() { - $this->hook_count++; + ++$this->hook_count; // Timer already running means a subhook has been called if ( ! is_null( $this->hook_start_time ) ) { - $this->hook_depth++; + ++$this->hook_depth; } else { $this->hook_start_time = microtime( true ); } @@ -115,7 +115,7 @@ public function start_hook_timer() { */ public function stop_hook_timer() { if ( $this->hook_depth ) { - $this->hook_depth--; + --$this->hook_depth; } else { if ( ! is_null( $this->hook_start_time ) ) { $this->hook_time += microtime( true ) - $this->hook_start_time; @@ -128,7 +128,7 @@ public function stop_hook_timer() { * Start this logger's request timer */ public function start_request_timer() { - $this->request_count++; + ++$this->request_count; $this->request_start_time = microtime( true ); } @@ -141,5 +141,4 @@ public function stop_request_timer() { } $this->request_start_time = null; } - } diff --git a/src/Profiler.php b/src/Profiler.php index 3b98e725..5c8e5acb 100644 --- a/src/Profiler.php +++ b/src/Profiler.php @@ -79,7 +79,7 @@ public function get_loggers() { public function run() { WP_CLI::add_wp_hook( 'muplugins_loaded', - function() { + function () { $url = WP_CLI::get_runner()->config['url']; if ( ! empty( $url ) ) { WP_CLI::set_url( trailingslashit( $url ) ); @@ -90,7 +90,7 @@ function() { ); WP_CLI::add_hook( 'after_wp_config_load', - function() { + function () { if ( defined( 'SAVEQUERIES' ) && ! SAVEQUERIES ) { WP_CLI::error( "'SAVEQUERIES' is defined as false, and must be true. Please check your wp-config.php" ); } @@ -215,7 +215,7 @@ public function wp_hook_begin() { $this->wrap_current_filter_callbacks( $current_filter ); } - $this->filter_depth++; + ++$this->filter_depth; WP_CLI::add_wp_hook( $current_filter, array( $this, 'wp_hook_end' ), 9999 ); } @@ -235,7 +235,7 @@ private function wrap_current_filter_callbacks( $current_filter ) { foreach ( $callbacks as $priority => $priority_callbacks ) { foreach ( $priority_callbacks as $i => $the_ ) { $callbacks[ $priority ][ $i ] = array( - 'function' => function() use ( $the_, $i ) { + 'function' => function () use ( $the_, $i ) { if ( ! isset( $this->loggers[ $i ] ) ) { $this->loggers[ $i ] = new Logger( array( @@ -281,7 +281,7 @@ public function wp_hook_end( $filter_value = null ) { } } - $this->filter_depth--; + --$this->filter_depth; return $filter_value; } @@ -315,7 +315,7 @@ public function handle_function_tick() { $total_queries = count( $wpdb->queries ); for ( $i = $this->tick_query_offset; $i < $total_queries; $i++ ) { $this->loggers[ $callback_hash ]['query_time'] += $wpdb->queries[ $i ][1]; - $this->loggers[ $callback_hash ]['query_count']++; + ++$this->loggers[ $callback_hash ]['query_count']; } } @@ -484,7 +484,6 @@ private function load_wordpress_with_template() { $logger->stop(); $this->loggers[] = $logger; } - } /** @@ -588,5 +587,4 @@ private static function set_filter_callbacks( $filter, $callbacks ) { $wp_filter[ $filter ] = $callbacks; // phpcs:ignore } } - } From 14da856324bbd96bf265e3bcc2b9e4593ee5f1df Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Fri, 1 Sep 2023 06:28:27 -0700 Subject: [PATCH 4/4] Need to make sure these are always floats --- src/Formatter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Formatter.php b/src/Formatter.php index c91c1111..d09101e4 100644 --- a/src/Formatter.php +++ b/src/Formatter.php @@ -149,7 +149,7 @@ function ( $a, $b ) use ( $order, $orderby ) { } if ( is_array( $value ) ) { if ( ! empty( $value ) ) { - $totals[ $i ] = round( ( array_sum( $value ) / count( $value ) ), 2 ) . '%'; + $totals[ $i ] = round( ( array_sum( array_map( 'floatval', $value ) ) / count( $value ) ), 2 ) . '%'; } else { $totals[ $i ] = null; }