Skip to content

Commit

Permalink
Update WPCS to v3 (#183)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
swissspidy and danielbachhuber authored Sep 1, 2023
1 parent ce17377 commit bfb4ba4
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 22 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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. -->
Expand Down
2 changes: 1 addition & 1 deletion profile-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 2 additions & 3 deletions src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -493,5 +493,4 @@ private static function shine_spotlight( $loggers, $metrics ) {

return $loggers;
}

}
4 changes: 2 additions & 2 deletions src/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
11 changes: 5 additions & 6 deletions src/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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 );
}
Expand All @@ -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;
Expand All @@ -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 );
}

Expand All @@ -141,5 +141,4 @@ public function stop_request_timer() {
}
$this->request_start_time = null;
}

}
14 changes: 6 additions & 8 deletions src/Profiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
Expand All @@ -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" );
}
Expand Down Expand Up @@ -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 );
}
Expand All @@ -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(
Expand Down Expand Up @@ -281,7 +281,7 @@ public function wp_hook_end( $filter_value = null ) {
}
}

$this->filter_depth--;
--$this->filter_depth;

return $filter_value;
}
Expand Down Expand Up @@ -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'];
}
}

Expand Down Expand Up @@ -484,7 +484,6 @@ private function load_wordpress_with_template() {
$logger->stop();
$this->loggers[] = $logger;
}

}

/**
Expand Down Expand Up @@ -588,5 +587,4 @@ private static function set_filter_callbacks( $filter, $callbacks ) {
$wp_filter[ $filter ] = $callbacks; // phpcs:ignore
}
}

}

0 comments on commit bfb4ba4

Please sign in to comment.