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

Update PHPStan level to 7 #1205

Merged
merged 20 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
28a920d
Update PHPStan level to 7
westonruter May 7, 2024
dad9fd6
Address majority of non-test PHPStan issues in optimization-detective
westonruter May 7, 2024
7d6c0f7
Fix embed-optimizer issues
westonruter May 7, 2024
33ef660
Fix speculation-rules issues
westonruter May 7, 2024
956b2ef
Fix issues in webp-uploads
westonruter May 7, 2024
616b781
Fix issues in includes
westonruter May 7, 2024
544f09f
Increase specificity of registered_metrics_data typing
westonruter May 7, 2024
7adcfd3
Fix issues in plugins/dominant-color-images/helper.php
westonruter May 7, 2024
68a62ef
Merge branch 'trunk' of https://github.com/WordPress/performance into…
westonruter May 9, 2024
44a389a
Fix typing for measure_callback to Perflab_Server_Timing
westonruter May 9, 2024
9a71312
Run composer update
westonruter May 9, 2024
1b26a2d
Fix Generic.Commenting.DocComment.SpacingAfterTagGroup
westonruter May 9, 2024
f491f0b
Ignore strict errors in tests
westonruter May 9, 2024
2d4fae6
Fix issues in optimization-detective
westonruter May 9, 2024
25eb73a
Fix issues in dominant-color-images
westonruter May 9, 2024
ac7d1b1
Fix off-by-one validation for minimum breakpoint
westonruter May 9, 2024
3f28af5
Add more type checks
westonruter May 9, 2024
d8f886b
Fix it_should_create_an_image_with_filter_webp_uploads_pre_generate_a…
westonruter May 9, 2024
64458ab
Add reusable MetricArguments phpstan-type
westonruter May 10, 2024
2dfc76f
Remove unneeded wp_check_filetype() stub
westonruter May 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions bin/phpstan/filtered-functions.stub
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,57 @@
* }|null Attachment metadata. Null on failure.
*/
function wp_get_attachment_metadata( int $attachment_id = 0, bool $unfiltered = false ): ?array {}
swissspidy marked this conversation as resolved.
Show resolved Hide resolved

/**
* Retrieves the file type from the file name.
*
* You can optionally define the mime array, if needed.
*
* @since 2.0.4
*
* @param string $filename File name or path.
* @param array<string, string>|null $mimes Optional. Array of allowed mime types keyed by their file extension regex.
* Defaults to the result of get_allowed_mime_types().
* @return array{ ext: string|false, type: string|false }
*/
function wp_check_filetype( $filename, $mimes = null ) {}

/**
* Updates the attached file and image meta data when the original image was edited.
*
* @since 5.3.0
* @since 6.0.0 The `$filesize` value was added to the returned array.
* @access private
*
* @phpstan-param array{
* width: int,
* height: int,
* path: string
* } $saved_data
* @phpstan-param array{
* width: int,
* height: int,
* file: string,
* sizes: array<string, array{ file: string, width: int, height: int, 'mime-type': string }>,
* image_meta: array<string, mixed>,
* filesize: int
* } $image_meta
* @phpstan-return array{
* width: int,
* height: int,
* file: string,
* sizes: array<string, array{ file: string, width: int, height: int, 'mime-type': string, sources?: array<string, array{ file: string, filesize: int }> }>,
* image_meta: array<string, mixed>,
* filesize: int,
* sources?: array<string, array{ file: string, filesize: int }>,
* has_transparency?: bool,
* dominant_color?: string
* }
*
* @param array $saved_data The data returned from WP_Image_Editor after successfully saving an image.
* @param string $original_file Path to the original file.
* @param array $image_meta The image meta data.
* @param int $attachment_id The attachment post ID.
* @return array The updated image meta data.
*/
function _wp_image_meta_replace_original( $saved_data, $original_file, $image_meta, $attachment_id ): array {}
68 changes: 32 additions & 36 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions includes/admin/plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ function perflab_query_plugin_info( string $plugin_slug ) {

set_transient( 'perflab_plugin_info_' . $plugin_slug, $plugin, HOUR_IN_SECONDS );

/**
* Validated (mostly) plugin data.
*
* @var array{name: string, slug: string, short_description: string, requires: string|false, requires_php: string|false, requires_plugins: string[], download_link: string, version: string} $plugin
*/
return $plugin;
}

Expand Down
19 changes: 16 additions & 3 deletions includes/server-timing/class-perflab-server-timing.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ class Perflab_Server_Timing {
* Map of registered metric slugs and their registered data.
*
* @since 1.8.0
* @var array<string, array{measure_callback: callable, access_cap: string}>
* @var array<string, array{
swissspidy marked this conversation as resolved.
Show resolved Hide resolved
* measure_callback: callable( Perflab_Server_Timing_Metric ): void,
* access_cap: string
* }>
*/
private $registered_metrics_data = array();

Expand All @@ -36,8 +39,13 @@ class Perflab_Server_Timing {
*
* @since 1.8.0
*
* @param string $metric_slug The metric slug.
* @param array{measure_callback: callable, access_cap: string} $args {
* @phpstan-param array{
* measure_callback: callable( Perflab_Server_Timing_Metric ): void,
* access_cap: string
* } $args
*
* @param string $metric_slug The metric slug.
* @param array<string, callable|string> $args {
* Arguments for the metric.
*
* @type callable $measure_callback The callback that initiates calculating the metric value. It will receive
Expand Down Expand Up @@ -94,6 +102,11 @@ public function register_metric( string $metric_slug, array $args ): void {
);
return;
}
/**
* Validated args.
*
* @var array{measure_callback: callable( Perflab_Server_Timing_Metric ): void, access_cap: string} $args
*/

$this->registered_metrics[ $metric_slug ] = new Perflab_Server_Timing_Metric( $metric_slug );
$this->registered_metrics_data[ $metric_slug ] = $args;
Expand Down
2 changes: 1 addition & 1 deletion includes/server-timing/defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ static function ( $passthrough = null ) {
perflab_server_timing_register_metric(
'template',
array(
'measure_callback' => static function ( $metric ): void {
'measure_callback' => static function ( Perflab_Server_Timing_Metric $metric ): void {
$metric->measure_before();
add_action( 'perflab_server_timing_send_header', array( $metric, 'measure_after' ), PHP_INT_MAX );
},
Expand Down
7 changes: 6 additions & 1 deletion includes/server-timing/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ function perflab_sanitize_server_timing_setting( $value ): array {
array_unique(
array_filter(
array_map(
static function ( $hook_name ) {
static function ( string $hook_name ): string {
/*
* Allow any characters except whitespace.
* While most hooks use a limited set of characters, hook names in plugins are not
Expand All @@ -227,5 +227,10 @@ static function ( $hook_name ) {

$value['output_buffering'] = (bool) $value['output_buffering'];

/**
* Validated value.
*
* @var array{benchmarking_actions: string[], benchmarking_filters: string[], output_buffering: bool} $value
*/
return $value;
}
Loading
Loading