-
Notifications
You must be signed in to change notification settings - Fork 107
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
Improve static analysis in Performance Lab plugin files #1188
Changes from all commits
468c49f
51d1894
a147009
2cb9ab0
612c3bc
828c87f
58fda47
5e4cb3b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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' ); | ||
|
||
|
@@ -61,7 +65,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 { | ||
?> | ||
<div class="wrap"> | ||
<?php perflab_render_plugins_ui(); ?> | ||
|
@@ -79,7 +83,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; | ||
|
@@ -117,11 +121,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' ); | ||
} | ||
|
@@ -207,7 +211,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; | ||
|
@@ -222,7 +226,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' ); | ||
|
@@ -237,7 +241,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'; | ||
|
@@ -279,9 +283,9 @@ function perflab_install_activate_plugin_callback() { | |
* | ||
* @since 3.0.0 | ||
*/ | ||
function perflab_print_features_page_style() { | ||
function perflab_print_features_page_style(): void { | ||
?> | ||
<style type="text/css"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
<style> | ||
.plugin-card .name, | ||
.plugin-card .desc, /* For WP <6.5 versions */ | ||
.plugin-card .desc > p { | ||
|
@@ -303,7 +307,7 @@ function perflab_print_features_page_style() { | |
* | ||
* @since 2.8.0 | ||
*/ | ||
function perflab_plugin_admin_notices() { | ||
function perflab_plugin_admin_notices(): void { | ||
if ( ! current_user_can( 'install_plugins' ) ) { | ||
$are_all_plugins_installed = true; | ||
$installed_plugin_slugs = array_map( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,8 @@ | |
* Adds the Server-Timing page to the Tools menu. | ||
* | ||
* @since 2.6.0 | ||
* | ||
* @return string|false Hook suffix. | ||
*/ | ||
function perflab_add_server_timing_page() { | ||
$hook_suffix = add_management_page( | ||
|
@@ -35,14 +37,16 @@ function perflab_add_server_timing_page() { | |
|
||
return $hook_suffix; | ||
} | ||
|
||
// @phpstan-ignore-next-line | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because PHPStan identifies correctly that this function is used as an action, and not a filter. So it shouldn't return anything. |
||
add_action( 'admin_menu', 'perflab_add_server_timing_page' ); | ||
|
||
/** | ||
* Initializes settings sections and fields for the Server-Timing page. | ||
* | ||
* @since 2.6.0 | ||
*/ | ||
function perflab_load_server_timing_page() { | ||
function perflab_load_server_timing_page(): void { | ||
/* | ||
* This settings section technically includes a field, however it is directly rendered as part of the section | ||
* callback due to requiring custom markup. | ||
|
@@ -149,7 +153,7 @@ static function () { | |
* | ||
* @since 2.6.0 | ||
*/ | ||
function perflab_render_server_timing_page() { | ||
function perflab_render_server_timing_page(): void { | ||
?> | ||
<div class="wrap"> | ||
<?php settings_errors(); ?> | ||
|
@@ -173,7 +177,7 @@ function perflab_render_server_timing_page() { | |
* | ||
* @param string $slug Slug of the field and sub-key in the Server-Timing option. | ||
*/ | ||
function perflab_render_server_timing_page_hooks_field( $slug ) { | ||
function perflab_render_server_timing_page_hooks_field( string $slug ): void { | ||
$options = (array) get_option( PERFLAB_SERVER_TIMING_SETTING, array() ); | ||
|
||
// Value for the sub-key is an array of hook names. | ||
|
@@ -205,7 +209,7 @@ class="large-text code" | |
* | ||
* @since 2.6.0 | ||
*/ | ||
function perflab_render_server_timing_page_output_buffering_section() { | ||
function perflab_render_server_timing_page_output_buffering_section(): void { | ||
$slug = 'output_buffering'; | ||
$field_id = "server_timing_{$slug}"; | ||
$field_name = PERFLAB_SERVER_TIMING_SETTING . '[' . $slug . ']'; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because PHPStan identifies correctly that this function is used as an action, and not a filter. So it shouldn't return anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The returned value is used in testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally the tests could be updated to not rely on this, but I think that is out of scope for this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow-up: https://github.com/WordPress/performance/pull/1198/files#r1589800613