From 468c49f91bc3c2d0680d56b99042b18f81c9e829 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 29 Apr 2024 14:48:56 -0700 Subject: [PATCH 1/5] Improve static analysis in Performance Lab plugin files --- includes/admin/load.php | 30 +++--- includes/admin/plugins.php | 4 +- includes/admin/server-timing.php | 12 ++- .../class-perflab-server-timing-metric.php | 14 +-- .../class-perflab-server-timing.php | 26 ++--- includes/server-timing/defaults.php | 6 +- includes/server-timing/load.php | 63 ++++++----- includes/server-timing/object-cache.copy.php | 2 +- .../audit-autoloaded-options/helper.php | 20 ++-- .../audit-autoloaded-options/hooks.php | 14 +-- .../audit-enqueued-assets/helper.php | 24 +++-- .../audit-enqueued-assets/hooks.php | 14 +-- includes/site-health/avif-support/helper.php | 4 +- includes/site-health/avif-support/hooks.php | 6 +- includes/site-health/webp-support/helper.php | 4 +- includes/site-health/webp-support/hooks.php | 6 +- load.php | 16 +-- tests/includes/server-timing/load-tests.php | 100 +++++++++++++----- .../audit-enqueued-assets-test.php | 4 +- 19 files changed, 219 insertions(+), 150 deletions(-) diff --git a/includes/admin/load.php b/includes/admin/load.php index 5d48d9c8b8..0a3e04d218 100644 --- a/includes/admin/load.php +++ b/includes/admin/load.php @@ -14,6 +14,8 @@ * * @since 1.0.0 * @since 3.0.0 Renamed to perflab_add_features_page(). + * + * @return string|false Hook suffix. */ function perflab_add_features_page() { $hook_suffix = add_options_page( @@ -32,6 +34,8 @@ function perflab_add_features_page() { return $hook_suffix; } + +// @phpstan-ignore-next-line add_action( 'admin_menu', 'perflab_add_features_page' ); /** @@ -41,7 +45,7 @@ function perflab_add_features_page() { * @since 3.0.0 Renamed to perflab_load_features_page(), and the * $module and $hook_suffix parameters were removed. */ -function perflab_load_features_page() { +function perflab_load_features_page(): void { // Handle script enqueuing for settings page. add_action( 'admin_enqueue_scripts', 'perflab_enqueue_features_page_scripts' ); @@ -58,7 +62,7 @@ function perflab_load_features_page() { * @since 1.0.0 * @since 3.0.0 Renamed to perflab_render_settings_page(). */ -function perflab_render_settings_page() { +function perflab_render_settings_page(): void { ?>
@@ -76,7 +80,7 @@ function perflab_render_settings_page() { * * @param string $hook_suffix The current admin page. */ -function perflab_admin_pointer( $hook_suffix ) { +function perflab_admin_pointer( string $hook_suffix ): void { // Do not show admin pointer in multisite Network admin or User admin UI. if ( is_network_admin() || is_user_admin() ) { return; @@ -114,11 +118,11 @@ function perflab_admin_pointer( $hook_suffix ) { * @since 1.0.0 * @since 2.4.0 Optional arguments were added to make the function reusable for different pointers. * - * @param string $pointer_id Optional. ID of the pointer. Default 'perflab-admin-pointer'. - * @param array $args Optional. Pointer arguments. Supports 'heading' and 'content' entries. - * Defaults are the heading and content for the 'perflab-admin-pointer'. + * @param string $pointer_id Optional. ID of the pointer. Default 'perflab-admin-pointer'. + * @param array{heading?: string, content?: string} $args Optional. Pointer arguments. Supports 'heading' and 'content' entries. + * Defaults are the heading and content for the 'perflab-admin-pointer'. */ -function perflab_render_pointer( $pointer_id = 'perflab-admin-pointer', $args = array() ) { +function perflab_render_pointer( string $pointer_id = 'perflab-admin-pointer', array $args = array() ): void { if ( ! isset( $args['heading'] ) ) { $args['heading'] = __( 'Performance Lab', 'performance-lab' ); } @@ -204,7 +208,7 @@ function perflab_plugin_action_links_add_settings( $links ) { * * @since 2.3.0 */ -function perflab_dismiss_wp_pointer_wrapper() { +function perflab_dismiss_wp_pointer_wrapper(): void { if ( isset( $_POST['pointer'] ) && 'perflab-admin-pointer' !== $_POST['pointer'] ) { // Another plugin's pointer, do nothing. return; @@ -219,7 +223,7 @@ function perflab_dismiss_wp_pointer_wrapper() { * @since 2.8.0 * @since 3.0.0 Renamed to perflab_enqueue_features_page_scripts(). */ -function perflab_enqueue_features_page_scripts() { +function perflab_enqueue_features_page_scripts(): void { // These assets are needed for the "Learn more" popover. wp_enqueue_script( 'thickbox' ); wp_enqueue_style( 'thickbox' ); @@ -231,7 +235,7 @@ function perflab_enqueue_features_page_scripts() { * * @since 3.0.0 */ -function perflab_install_activate_plugin_callback() { +function perflab_install_activate_plugin_callback(): void { check_admin_referer( 'perflab_install_activate_plugin' ); require_once ABSPATH . 'wp-admin/includes/plugin.php'; @@ -273,9 +277,9 @@ function perflab_install_activate_plugin_callback() { * * @since 3.0.0 */ -function perflab_print_features_page_style() { +function perflab_print_features_page_style(): void { ?> -