Skip to content

Commit

Permalink
Add more type checks
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed May 9, 2024
1 parent ac7d1b1 commit 3f28af5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 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 Down
25 changes: 13 additions & 12 deletions plugins/webp-uploads/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,21 @@ function webp_uploads_generate_additional_image_source( int $attachment_id, stri
if ( is_wp_error( $image ) ) {
return $image;
}

if (
is_array( $image ) &&
array_key_exists( 'file', $image ) &&
is_string( $image['file'] )
) {
if ( array_key_exists( 'filesize', $image ) && is_int( $image['filesize'] ) ) {
if ( is_array( $image ) && array_key_exists( 'file', $image ) && is_string( $image['file'] ) ) {
// The filtered image provided all we need to short-circuit here.
if ( array_key_exists( 'filesize', $image ) && is_int( $image['filesize'] ) && $image['filesize'] > 0 ) {
return $image;
}
if ( array_key_exists( 'path', $image ) ) {
return array(
'file' => $image['file'],
'filesize' => wp_filesize( $image['path'] ),
);

// Supply the filesize based on the filter-provided path.
if ( array_key_exists( 'path', $image ) && is_int( $image['path'] ) ) {
$filesize = wp_filesize( $image['path'] );
if ( $filesize > 0 ) {
return array(
'file' => $image['file'],
'filesize' => $filesize,
);
}
}
}

Expand Down
1 change: 0 additions & 1 deletion plugins/webp-uploads/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ function webp_uploads_create_sources_property( array $metadata, int $attachment_
* @param array|mixed $missing_sizes Associative array of arrays of image sub-sizes.
* @param array<string, mixed> $image_meta The metadata from the image.
* @param int $attachment_id The ID of the attachment.
*
* @return array<string, array{ width: int, height: int, crop: bool }> Associative array of arrays of image sub-sizes.
*/
function webp_uploads_wp_get_missing_image_subsizes( $missing_sizes, array $image_meta, int $attachment_id ): array {
Expand Down

0 comments on commit 3f28af5

Please sign in to comment.