Skip to content

Commit bfb4ba4

Browse files
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 <[email protected]>
1 parent ce17377 commit bfb4ba4

7 files changed

+17
-22
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"wp-cli/wp-cli": "^2.5"
1111
},
1212
"require-dev": {
13-
"wp-cli/wp-cli-tests": "^3.1"
13+
"wp-cli/wp-cli-tests": "^4"
1414
},
1515
"config": {
1616
"process-timeout": 7200,

phpcs.xml.dist

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
See: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#naming-conventions-prefix-everything-in-the-global-namespace -->
4545
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
4646
<properties>
47-
<property name="strict_class_file_names" value="false"/>
4847
<property name="prefixes" type="array">
4948
<element value="WP_CLI\Profile"/><!-- Namespaces. -->
5049
<element value="wpcli_profile"/><!-- Global variables and such. -->

profile-command.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
return;
55
}
66

7-
$wpcli_profile_autoloader = dirname( __FILE__ ) . '/vendor/autoload.php';
7+
$wpcli_profile_autoloader = __DIR__ . '/vendor/autoload.php';
88
if ( file_exists( $wpcli_profile_autoloader ) ) {
99
require_once $wpcli_profile_autoloader;
1010
}

src/Command.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ public function eval_( $args, $assoc_args ) {
324324

325325
self::profile_eval_ish(
326326
$assoc_args,
327-
function() use ( $statement ) {
327+
function () use ( $statement ) {
328328
eval( $statement ); // phpcs:ignore Squiz.PHP.Eval.Discouraged -- no other way oround here
329329
},
330330
$order,
@@ -388,7 +388,7 @@ public function eval_file( $args, $assoc_args ) {
388388

389389
self::profile_eval_ish(
390390
$assoc_args,
391-
function() use ( $file ) {
391+
function () use ( $file ) {
392392
self::include_file( $file );
393393
},
394394
$order,
@@ -493,5 +493,4 @@ private static function shine_spotlight( $loggers, $metrics ) {
493493

494494
return $loggers;
495495
}
496-
497496
}

src/Formatter.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private function show_table( $order, $orderby, $items, $fields, $include_total )
9292
if ( $orderby ) {
9393
usort(
9494
$items,
95-
function( $a, $b ) use ( $order, $orderby ) {
95+
function ( $a, $b ) use ( $order, $orderby ) {
9696

9797
$orderby_array = 'ASC' === $order ? array( $a, $b ) : array( $b, $a );
9898
list( $first, $second ) = $orderby_array;
@@ -149,7 +149,7 @@ function( $a, $b ) use ( $order, $orderby ) {
149149
}
150150
if ( is_array( $value ) ) {
151151
if ( ! empty( $value ) ) {
152-
$totals[ $i ] = round( ( array_sum( $value ) / count( $value ) ), 2 ) . '%';
152+
$totals[ $i ] = round( ( array_sum( array_map( 'floatval', $value ) ) / count( $value ) ), 2 ) . '%';
153153
} else {
154154
$totals[ $i ] = null;
155155
}

src/Logger.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function stop() {
7070

7171
for ( $i = $this->query_offset; $i < $query_total_count; $i++ ) {
7272
$this->query_time += $wpdb->queries[ $i ][1];
73-
$this->query_count++;
73+
++$this->query_count;
7474
}
7575
}
7676

@@ -101,10 +101,10 @@ public function stop() {
101101
* Start this logger's hook timer
102102
*/
103103
public function start_hook_timer() {
104-
$this->hook_count++;
104+
++$this->hook_count;
105105
// Timer already running means a subhook has been called
106106
if ( ! is_null( $this->hook_start_time ) ) {
107-
$this->hook_depth++;
107+
++$this->hook_depth;
108108
} else {
109109
$this->hook_start_time = microtime( true );
110110
}
@@ -115,7 +115,7 @@ public function start_hook_timer() {
115115
*/
116116
public function stop_hook_timer() {
117117
if ( $this->hook_depth ) {
118-
$this->hook_depth--;
118+
--$this->hook_depth;
119119
} else {
120120
if ( ! is_null( $this->hook_start_time ) ) {
121121
$this->hook_time += microtime( true ) - $this->hook_start_time;
@@ -128,7 +128,7 @@ public function stop_hook_timer() {
128128
* Start this logger's request timer
129129
*/
130130
public function start_request_timer() {
131-
$this->request_count++;
131+
++$this->request_count;
132132
$this->request_start_time = microtime( true );
133133
}
134134

@@ -141,5 +141,4 @@ public function stop_request_timer() {
141141
}
142142
$this->request_start_time = null;
143143
}
144-
145144
}

src/Profiler.php

+6-8
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function get_loggers() {
7979
public function run() {
8080
WP_CLI::add_wp_hook(
8181
'muplugins_loaded',
82-
function() {
82+
function () {
8383
$url = WP_CLI::get_runner()->config['url'];
8484
if ( ! empty( $url ) ) {
8585
WP_CLI::set_url( trailingslashit( $url ) );
@@ -90,7 +90,7 @@ function() {
9090
);
9191
WP_CLI::add_hook(
9292
'after_wp_config_load',
93-
function() {
93+
function () {
9494
if ( defined( 'SAVEQUERIES' ) && ! SAVEQUERIES ) {
9595
WP_CLI::error( "'SAVEQUERIES' is defined as false, and must be true. Please check your wp-config.php" );
9696
}
@@ -215,7 +215,7 @@ public function wp_hook_begin() {
215215
$this->wrap_current_filter_callbacks( $current_filter );
216216
}
217217

218-
$this->filter_depth++;
218+
++$this->filter_depth;
219219

220220
WP_CLI::add_wp_hook( $current_filter, array( $this, 'wp_hook_end' ), 9999 );
221221
}
@@ -235,7 +235,7 @@ private function wrap_current_filter_callbacks( $current_filter ) {
235235
foreach ( $callbacks as $priority => $priority_callbacks ) {
236236
foreach ( $priority_callbacks as $i => $the_ ) {
237237
$callbacks[ $priority ][ $i ] = array(
238-
'function' => function() use ( $the_, $i ) {
238+
'function' => function () use ( $the_, $i ) {
239239
if ( ! isset( $this->loggers[ $i ] ) ) {
240240
$this->loggers[ $i ] = new Logger(
241241
array(
@@ -281,7 +281,7 @@ public function wp_hook_end( $filter_value = null ) {
281281
}
282282
}
283283

284-
$this->filter_depth--;
284+
--$this->filter_depth;
285285

286286
return $filter_value;
287287
}
@@ -315,7 +315,7 @@ public function handle_function_tick() {
315315
$total_queries = count( $wpdb->queries );
316316
for ( $i = $this->tick_query_offset; $i < $total_queries; $i++ ) {
317317
$this->loggers[ $callback_hash ]['query_time'] += $wpdb->queries[ $i ][1];
318-
$this->loggers[ $callback_hash ]['query_count']++;
318+
++$this->loggers[ $callback_hash ]['query_count'];
319319
}
320320
}
321321

@@ -484,7 +484,6 @@ private function load_wordpress_with_template() {
484484
$logger->stop();
485485
$this->loggers[] = $logger;
486486
}
487-
488487
}
489488

490489
/**
@@ -588,5 +587,4 @@ private static function set_filter_callbacks( $filter, $callbacks ) {
588587
$wp_filter[ $filter ] = $callbacks; // phpcs:ignore
589588
}
590589
}
591-
592590
}

0 commit comments

Comments
 (0)