Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix errors detected by Plugin Checker #788

Merged
merged 1 commit into from Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Empty file removed modules/.gitkeep
Empty file.
1 change: 1 addition & 0 deletions phpcs.xml.dist
Expand Up @@ -18,6 +18,7 @@
<file>./admin</file>
<file>./load.php</file>
<file>./modules</file>
<file>./server-timing</file>
<file>./tests</file>

<!-- Do not require file headers on generated files -->
Expand Down
6 changes: 3 additions & 3 deletions server-timing/class-perflab-server-timing-metric.php
Expand Up @@ -74,7 +74,7 @@ public function set_value( $value ) {
_doing_it_wrong(
__METHOD__,
/* translators: %s: PHP parameter name */
sprintf( __( 'The %s parameter must be an integer, float, or numeric string.', 'performance-lab' ), '$value' ),
sprintf( esc_html__( 'The %s parameter must be an integer, float, or numeric string.', 'performance-lab' ), '$value' ),
''
);
return;
Expand All @@ -84,7 +84,7 @@ public function set_value( $value ) {
_doing_it_wrong(
__METHOD__,
/* translators: %s: WordPress action name */
sprintf( __( 'The method must be called before or during the %s action.', 'performance-lab' ), 'perflab_server_timing_send_header' ),
sprintf( esc_html__( 'The method must be called before or during the %s action.', 'performance-lab' ), 'perflab_server_timing_send_header' ),
''
);
return;
Expand Down Expand Up @@ -134,7 +134,7 @@ public function measure_after() {
_doing_it_wrong(
__METHOD__,
/* translators: %s: PHP method name */
sprintf( __( 'The %s method must be called before.', 'performance-lab' ), __CLASS__ . '::measure_before()' ),
sprintf( esc_html__( 'The %s method must be called before.', 'performance-lab' ), __CLASS__ . '::measure_before()' ),
''
);
return;
Expand Down
12 changes: 6 additions & 6 deletions server-timing/class-perflab-server-timing.php
Expand Up @@ -53,7 +53,7 @@ public function register_metric( $metric_slug, array $args ) {
_doing_it_wrong(
__METHOD__,
/* translators: %s: metric slug */
sprintf( __( 'A metric with the slug %s is already registered.', 'performance-lab' ), $metric_slug ),
sprintf( esc_html__( 'A metric with the slug %s is already registered.', 'performance-lab' ), esc_attr( $metric_slug ) ),
''
);
return;
Expand All @@ -63,7 +63,7 @@ public function register_metric( $metric_slug, array $args ) {
_doing_it_wrong(
__METHOD__,
/* translators: %s: WordPress action name */
sprintf( __( 'The method must be called before or during the %s action.', 'performance-lab' ), 'perflab_server_timing_send_header' ),
sprintf( esc_html__( 'The method must be called before or during the %s action.', 'performance-lab' ), 'perflab_server_timing_send_header' ),
''
);
return;
Expand All @@ -80,7 +80,7 @@ public function register_metric( $metric_slug, array $args ) {
_doing_it_wrong(
__METHOD__,
/* translators: %s: PHP parameter name */
sprintf( __( 'The %s argument is required and must be a callable.', 'performance-lab' ), '$args["measure_callback"]' ),
sprintf( esc_html__( 'The %s argument is required and must be a callable.', 'performance-lab' ), esc_attr( $args['measure_callback'] ) ),
''
);
return;
Expand All @@ -89,7 +89,7 @@ public function register_metric( $metric_slug, array $args ) {
_doing_it_wrong(
__METHOD__,
/* translators: %s: PHP parameter name */
sprintf( __( 'The %s argument is required and must be a string.', 'performance-lab' ), '$args["access_cap"]' ),
sprintf( esc_html__( 'The %s argument is required and must be a string.', 'performance-lab' ), esc_attr( $args['access_cap'] ) ),
''
);
return;
Expand Down Expand Up @@ -131,7 +131,7 @@ public function send_header() {
if ( headers_sent() ) {
_doing_it_wrong(
__METHOD__,
__( 'The method must be called before headers have been sent.', 'performance-lab' ),
esc_html__( 'The method must be called before headers have been sent.', 'performance-lab' ),
''
);
return;
Expand Down Expand Up @@ -175,7 +175,7 @@ function( Perflab_Server_Timing_Metric $metric ) {
},
$this->registered_metrics
),
function( $value ) {
static function( $value ) {
return null !== $value;
}
);
Expand Down
32 changes: 16 additions & 16 deletions server-timing/defaults.php
Expand Up @@ -14,12 +14,12 @@
* @since 1.8.0
*/
function perflab_register_default_server_timing_before_template_metrics() {
$calculate_before_template_metrics = function() {
$calculate_before_template_metrics = static function() {
// WordPress execution prior to serving the template.
perflab_server_timing_register_metric(
'before-template',
array(
'measure_callback' => function( $metric ) {
'measure_callback' => static function( $metric ) {
// The 'timestart' global is set right at the beginning of WordPress execution.
$metric->set_value( ( microtime( true ) - $GLOBALS['timestart'] ) * 1000.0 );
},
Expand All @@ -33,7 +33,7 @@ function perflab_register_default_server_timing_before_template_metrics() {
perflab_server_timing_register_metric(
'before-template-db-queries',
array(
'measure_callback' => function( $metric ) {
'measure_callback' => static function( $metric ) {
// This should never happen, but some odd database implementations may be doing it wrong.
if ( ! isset( $GLOBALS['wpdb']->queries ) || ! is_array( $GLOBALS['wpdb']->queries ) ) {
return;
Expand All @@ -42,7 +42,7 @@ function perflab_register_default_server_timing_before_template_metrics() {
// Store this value in a global to later subtract it from total query time after template.
$GLOBALS['perflab_query_time_before_template'] = array_reduce(
$GLOBALS['wpdb']->queries,
function( $acc, $query ) {
static function( $acc, $query ) {
return $acc + $query[1];
},
0.0
Expand All @@ -61,7 +61,7 @@ function( $acc, $query ) {
// modify the value prior to the check.
add_filter(
'template_include',
function( $passthrough ) use ( $calculate_before_template_metrics ) {
static function( $passthrough ) use ( $calculate_before_template_metrics ) {
if ( perflab_server_timing_use_output_buffer() ) {
$calculate_before_template_metrics();
}
Expand All @@ -71,7 +71,7 @@ function( $passthrough ) use ( $calculate_before_template_metrics ) {
);
add_action(
'perflab_server_timing_send_header',
function() use ( $calculate_before_template_metrics ) {
static function() use ( $calculate_before_template_metrics ) {
if ( ! perflab_server_timing_use_output_buffer() ) {
$calculate_before_template_metrics();
}
Expand All @@ -85,7 +85,7 @@ function() use ( $calculate_before_template_metrics ) {
if ( PERFLAB_OBJECT_CACHE_DROPIN_VERSION ) {
add_filter(
'query',
function( $query ) {
static function( $query ) {
global $wpdb;
if ( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'" !== $query ) {
return $query;
Expand All @@ -97,11 +97,11 @@ function( $query ) {
perflab_server_timing_register_metric(
'load-alloptions-query',
array(
'measure_callback' => function( $metric ) {
'measure_callback' => static function( $metric ) {
$metric->measure_before();
add_filter(
'pre_cache_alloptions',
function( $passthrough ) use ( $metric ) {
static function( $passthrough ) use ( $metric ) {
$metric->measure_after();
return $passthrough;
}
Expand Down Expand Up @@ -134,12 +134,12 @@ function perflab_register_default_server_timing_template_metrics() {

add_filter(
'template_include',
function( $passthrough = null ) {
static function( $passthrough = null ) {
// WordPress execution while serving the template.
perflab_server_timing_register_metric(
'template',
array(
'measure_callback' => function( $metric ) {
'measure_callback' => static function( $metric ) {
$metric->measure_before();
add_action( 'perflab_server_timing_send_header', array( $metric, 'measure_after' ), PHP_INT_MAX );
},
Expand All @@ -154,12 +154,12 @@ function( $passthrough = null ) {

add_action(
'perflab_server_timing_send_header',
function() {
static function() {
// WordPress total load time.
perflab_server_timing_register_metric(
'total',
array(
'measure_callback' => function( $metric ) {
'measure_callback' => static function( $metric ) {
// The 'timestart' global is set right at the beginning of WordPress execution.
$metric->set_value( ( microtime( true ) - $GLOBALS['timestart'] ) * 1000.0 );
},
Expand All @@ -173,12 +173,12 @@ function() {
if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) {
add_action(
'perflab_server_timing_send_header',
function() {
static function() {
// WordPress database query time within template.
perflab_server_timing_register_metric(
'template-db-queries',
array(
'measure_callback' => function( $metric ) {
'measure_callback' => static function( $metric ) {
// This global should typically be set when this is called, but check just in case.
if ( ! isset( $GLOBALS['perflab_query_time_before_template'] ) ) {
return;
Expand All @@ -191,7 +191,7 @@ function() {

$total_query_time = array_reduce(
$GLOBALS['wpdb']->queries,
function( $acc, $query ) {
static function( $acc, $query ) {
return $acc + $query[1];
},
0.0
Expand Down
4 changes: 2 additions & 2 deletions server-timing/load.php
Expand Up @@ -73,7 +73,7 @@ function perflab_server_timing_use_output_buffer() {
* @return callable Callback function that will run $callback and measure its execution time once called.
*/
function perflab_wrap_server_timing( $callback, $metric_slug, $access_cap ) {
return function( ...$callback_args ) use ( $callback, $metric_slug, $access_cap ) {
return static function( ...$callback_args ) use ( $callback, $metric_slug, $access_cap ) {
// Gain access to Perflab_Server_Timing_Metric instance.
$server_timing_metric = null;

Expand All @@ -83,7 +83,7 @@ function perflab_wrap_server_timing( $callback, $metric_slug, $access_cap ) {
perflab_server_timing_register_metric(
$metric_slug,
array(
'measure_callback' => function( $metric ) use ( &$server_timing_metric ) {
'measure_callback' => static function( $metric ) use ( &$server_timing_metric ) {
$server_timing_metric = $metric;
},
'access_cap' => $access_cap,
Expand Down