Skip to content

Commit 8d75d2f

Browse files
#156 Fix PHPCS errors/warnings
1 parent d101e43 commit 8d75d2f

File tree

4 files changed

+45
-24
lines changed

4 files changed

+45
-24
lines changed

inc/class-command.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,8 @@ function() use ( $file ) {
368368
*/
369369
private static function profile_eval_ish( $assoc_args, $profile_callback, $order = 'ASC', $orderby = null ) {
370370
$hook = Utils\get_flag_value( $assoc_args, 'hook' );
371-
$type = $focus = false;
371+
$focus = false;
372+
$type = false;
372373
$fields = array();
373374
if ( $hook ) {
374375
$type = 'hook';

inc/class-formatter.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ private function show_table( $order, $orderby, $items, $fields, $include_total )
9393
usort(
9494
$items,
9595
function( $a, $b ) use ( $order, $orderby ) {
96-
list( $first, $second ) = 'ASC' === $order ? array( $a, $b ) : array( $b, $a );
96+
97+
$orderby_array = 'ASC' === $order ? array( $a, $b ) : array( $b, $a );
98+
list( $first, $second ) = $orderby_array;
9799

98100
if ( is_numeric( $first->$orderby ) && is_numeric( $second->$orderby ) ) {
99101
return $this->compare_float( $first->$orderby, $second->$orderby );

inc/class-profiler.php

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ class Profiler {
88

99
private $type;
1010
private $focus;
11-
private $loggers = array();
12-
private $stage_hooks = array(
11+
private $loggers = array();
12+
private $stage_hooks = array(
1313
'bootstrap' => array(
1414
'muplugins_loaded',
1515
'plugins_loaded',
@@ -34,6 +34,7 @@ class Profiler {
3434
'wp_footer',
3535
),
3636
);
37+
3738
private $current_stage_hooks = array();
3839
private $running_hook = null;
3940
private $previous_filter = null;
@@ -55,7 +56,8 @@ public function __construct( $type, $focus ) {
5556
public function get_loggers() {
5657
foreach ( $this->loggers as $i => $logger ) {
5758
if ( is_array( $logger ) ) {
58-
$this->loggers[ $i ] = $logger = new Logger( $logger );
59+
$logger = new Logger( $logger );
60+
$this->loggers[ $i ] = $logger;
5961
}
6062
if ( ! isset( $logger->callback ) ) {
6163
continue;
@@ -78,7 +80,8 @@ public function run() {
7880
WP_CLI::add_wp_hook(
7981
'muplugins_loaded',
8082
function() {
81-
if ( $url = WP_CLI::get_runner()->config['url'] ) {
83+
$url = WP_CLI::get_runner()->config['url'];
84+
if ( ! empty( $url ) ) {
8285
WP_CLI::set_url( trailingslashit( $url ) );
8386
} else {
8487
WP_CLI::set_url( home_url( '/' ) );
@@ -103,7 +106,7 @@ function() {
103106
$stage_hooks = array_merge( $stage_hooks, $hooks );
104107
}
105108
$end_hook = substr( $this->focus, 0, -7 );
106-
$key = array_search( $end_hook, $stage_hooks );
109+
$key = array_search( $end_hook, $stage_hooks, true );
107110
if ( isset( $stage_hooks[ $key - 1 ] ) ) {
108111
$start_hook = $stage_hooks[ $key - 1 ];
109112
WP_CLI::add_wp_hook( $start_hook, array( $this, 'wp_tick_profile_begin' ), 9999 );
@@ -136,17 +139,22 @@ public function wp_tick_profile_begin( $value = null ) {
136139
// and hide calls from the tick handler and backtraces.
137140
// Copied from P3 Profiler
138141
if ( extension_loaded( 'xcache' ) ) {
139-
@ini_set( 'xcache.optimizer', false ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- ini_set can be disabled on server.
142+
@ini_set( 'xcache.optimizer', false ); // phpcs:ignore
143+
// WordPress.PHP.NoSilencedErrors.Discouraged -- ini_set can be disabled on server.
140144
} elseif ( extension_loaded( 'apc' ) ) {
141-
@ini_set( 'apc.optimization', 0 ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- ini_set can be disabled on server.
145+
@ini_set( 'apc.optimization', 0 ); // phpcs:ignore
146+
// WordPress.PHP.NoSilencedErrors.Discouraged -- ini_set can be disabled on server.
142147
apc_clear_cache();
143148
} elseif ( extension_loaded( 'eaccelerator' ) ) {
144-
@ini_set( 'eaccelerator.optimizer', 0 ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- ini_set can be disabled on server.
149+
@ini_set( 'eaccelerator.optimizer', 0 ); // phpcs:ignore
150+
// WordPress.PHP.NoSilencedErrors.Discouraged -- ini_set can be disabled on server.
145151
if ( function_exists( 'eaccelerator_optimizer' ) ) {
146-
@eaccelerator_optimizer( false ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- disabling eaccelerator on runtime can faild
152+
@eaccelerator_optimizer( false ); // phpcs:ignore
153+
// WordPress.PHP.NoSilencedErrors.Discouraged -- disabling eaccelerator on runtime can faild
147154
}
148155
} elseif ( extension_loaded( 'Zend Optimizer+' ) ) {
149-
@ini_set( 'zend_optimizerplus.optimization_level', 0 ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- ini_set can be disabled on server.
156+
@ini_set( 'zend_optimizerplus.optimization_level', 0 ); // phpcs:ignore
157+
// WordPress.PHP.NoSilencedErrors.Discouraged -- ini_set can be disabled on server.
150158
}
151159

152160
register_tick_function( array( $this, 'handle_function_tick' ) );
@@ -173,7 +181,7 @@ public function wp_hook_begin() {
173181
}
174182

175183
$current_filter = current_filter();
176-
if ( ( 'stage' === $this->type && in_array( $current_filter, $this->current_stage_hooks ) )
184+
if ( ( 'stage' === $this->type && in_array( $current_filter, $this->current_stage_hooks, true ) )
177185
|| ( 'hook' === $this->type && ! $this->focus ) ) {
178186
$pseudo_hook = "{$current_filter}:before";
179187
if ( isset( $this->loggers[ $pseudo_hook ] ) ) {
@@ -257,11 +265,11 @@ public function wp_hook_end( $filter_value = null ) {
257265
}
258266

259267
$current_filter = current_filter();
260-
if ( ( 'stage' === $this->type && in_array( $current_filter, $this->current_stage_hooks ) )
268+
if ( ( 'stage' === $this->type && in_array( $current_filter, $this->current_stage_hooks, true ) )
261269
|| ( 'hook' === $this->type && ! $this->focus ) ) {
262270
$this->loggers[ $current_filter ]->stop();
263271
if ( 'stage' === $this->type ) {
264-
$key = array_search( $current_filter, $this->current_stage_hooks );
272+
$key = array_search( $current_filter, $this->current_stage_hooks, true );
265273
if ( false !== $key && isset( $this->current_stage_hooks[ $key + 1 ] ) ) {
266274
$pseudo_hook = "{$this->current_stage_hooks[$key+1]}:before";
267275
} else {
@@ -287,7 +295,7 @@ public function handle_function_tick() {
287295
if ( ! is_null( $this->tick_callback ) ) {
288296
$time = microtime( true ) - $this->tick_start_time;
289297

290-
$callback_hash = md5( serialize( $this->tick_callback . $this->tick_location ) );
298+
$callback_hash = md5( serialize( $this->tick_callback . $this->tick_location ) ); // phpcs:ignore
291299
if ( ! isset( $this->loggers[ $callback_hash ] ) ) {
292300
$this->loggers[ $callback_hash ] = array(
293301
'callback' => $this->tick_callback,
@@ -304,7 +312,8 @@ public function handle_function_tick() {
304312
$this->loggers[ $callback_hash ]['time'] += $time;
305313

306314
if ( isset( $wpdb ) ) {
307-
for ( $i = $this->tick_query_offset; $i < count( $wpdb->queries ); $i++ ) {
315+
$total_queries = count( $wpdb->queries );
316+
for ( $i = $this->tick_query_offset; $i < $total_queries; $i++ ) {
308317
$this->loggers[ $callback_hash ]['query_time'] += $wpdb->queries[ $i ][1];
309318
$this->loggers[ $callback_hash ]['query_count']++;
310319
}
@@ -329,16 +338,17 @@ public function handle_function_tick() {
329338
$frame = $bt[1];
330339
}
331340

332-
$callback = $location = '';
333-
if ( in_array( strtolower( $frame['function'] ), array( 'include', 'require', 'include_once', 'require_once' ) ) ) {
341+
$location = '';
342+
$callback = '';
343+
if ( in_array( strtolower( $frame['function'] ), array( 'include', 'require', 'include_once', 'require_once' ), true ) ) {
334344
$callback = $frame['function'] . " '" . $frame['args'][0] . "'";
335345
} elseif ( isset( $frame['object'] ) && method_exists( $frame['object'], $frame['function'] ) ) {
336346
$callback = get_class( $frame['object'] ) . '->' . $frame['function'] . '()';
337347
} elseif ( isset( $frame['class'] ) && method_exists( $frame['class'], $frame['function'] ) ) {
338348
$callback = $frame['class'] . '::' . $frame['function'] . '()';
339349
} elseif ( ! empty( $frame['function'] ) && function_exists( $frame['function'] ) ) {
340350
$callback = $frame['function'] . '()';
341-
} elseif ( '__lambda_func' == $frame['function'] || '{closure}' == $frame['function'] ) {
351+
} elseif ( '__lambda_func' === $frame['function'] || '{closure}' === $frame['function'] ) {
342352
$callback = 'function(){}';
343353
}
344354

@@ -447,7 +457,8 @@ private function load_wordpress_with_template() {
447457

448458
// Template is normally loaded in global scope, so we need to replicate
449459
foreach ( $GLOBALS as $key => $value ) {
450-
global ${$key}; // phpcs:ignore PHPCompatibility.PHP.ForbiddenGlobalVariableVariable.NonBareVariableFound -- Syntax is updated to compatible with php 5 and 7.
460+
global ${$key}; // phpcs:ignore
461+
// PHPCompatibility.PHP.ForbiddenGlobalVariableVariable.NonBareVariableFound -- Syntax is updated to compatible with php 5 and 7.
451462
}
452463

453464
// Load the theme template.
@@ -480,7 +491,8 @@ private function load_wordpress_with_template() {
480491
* Get a human-readable name from a callback
481492
*/
482493
private static function get_name_location_from_callback( $callback ) {
483-
$name = $location = '';
494+
$location = '';
495+
$name = '';
484496
$reflection = false;
485497
if ( is_array( $callback ) && is_object( $callback[0] ) ) {
486498
$reflection = new \ReflectionMethod( $callback[0], $callback[1] );
@@ -567,13 +579,13 @@ private static function set_filter_callbacks( $filter, $callbacks ) {
567579
global $wp_filter;
568580

569581
if ( ! isset( $wp_filter[ $filter ] ) && class_exists( 'WP_Hook' ) ) {
570-
$wp_filter[ $filter ] = new \WP_Hook();
582+
$wp_filter[ $filter ] = new \WP_Hook(); // phpcs:ignore
571583
}
572584

573585
if ( is_a( $wp_filter[ $filter ], 'WP_Hook' ) ) {
574586
$wp_filter[ $filter ]->callbacks = $callbacks;
575587
} else {
576-
$wp_filter[ $filter ] = $callbacks;
588+
$wp_filter[ $filter ] = $callbacks; // phpcs:ignore
577589
}
578590
}
579591

phpcs.xml.dist

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,11 @@
5151
</property>
5252
</properties>
5353
<exclude name="WordPress.Files.FileName.NotHyphenatedLowercase" />
54+
<exclude-pattern>*/inc/*.php$</exclude-pattern>
5455
</rule>
56+
57+
<rule ref="WordPress.PHP.NoSilencedErrors.Discouraged">
58+
<exclude-pattern>*/inc/class-profiler.php$</exclude-pattern>
59+
</rule>
60+
5561
</ruleset>

0 commit comments

Comments
 (0)