mirror of
https://hk.gh-proxy.com/https://github.com/wp-cli/profile-command.git
synced 2025-08-18 06:01:38 +08:00
Update WPCS to v3 (#183)
* Update `wp-cli/wp-cli-tests` * Remove invalid config * Fix all auto-fixable issues * Need to make sure these are always floats --------- Co-authored-by: Daniel Bachhuber <daniel.bachhuber@automattic.com>
This commit is contained in:
parent
ce1737747d
commit
bfb4ba48b1
7 changed files with 17 additions and 22 deletions
|
@ -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,
|
||||
|
|
|
@ -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 -->
|
||||
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
|
||||
<properties>
|
||||
<property name="strict_class_file_names" value="false"/>
|
||||
<property name="prefixes" type="array">
|
||||
<element value="WP_CLI\Profile"/><!-- Namespaces. -->
|
||||
<element value="wpcli_profile"/><!-- Global variables and such. -->
|
||||
|
|
|
@ -4,7 +4,7 @@ if ( ! class_exists( 'WP_CLI' ) ) {
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -324,7 +324,7 @@ class Command {
|
|||
|
||||
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 @@ class Command {
|
|||
|
||||
self::profile_eval_ish(
|
||||
$assoc_args,
|
||||
function() use ( $file ) {
|
||||
function () use ( $file ) {
|
||||
self::include_file( $file );
|
||||
},
|
||||
$order,
|
||||
|
@ -493,5 +493,4 @@ class Command {
|
|||
|
||||
return $loggers;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ class Formatter {
|
|||
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;
|
||||
|
@ -149,7 +149,7 @@ class Formatter {
|
|||
}
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ class Logger {
|
|||
|
||||
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 @@ class Logger {
|
|||
* 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 @@ class Logger {
|
|||
*/
|
||||
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 @@ class Logger {
|
|||
* 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 @@ class Logger {
|
|||
}
|
||||
$this->request_start_time = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ class Profiler {
|
|||
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 @@ class Profiler {
|
|||
);
|
||||
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 @@ class Profiler {
|
|||
$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 @@ class Profiler {
|
|||
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 @@ class Profiler {
|
|||
}
|
||||
}
|
||||
|
||||
$this->filter_depth--;
|
||||
--$this->filter_depth;
|
||||
|
||||
return $filter_value;
|
||||
}
|
||||
|
@ -315,7 +315,7 @@ class Profiler {
|
|||
$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 @@ class Profiler {
|
|||
$logger->stop();
|
||||
$this->loggers[] = $logger;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -588,5 +587,4 @@ class Profiler {
|
|||
$wp_filter[ $filter ] = $callbacks; // phpcs:ignore
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue