-
Notifications
You must be signed in to change notification settings - Fork 109
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 1 #1198
Changes from all commits
1f5a1b0
7c37d41
2d3aa93
8314dd9
3b37419
70cfa17
09d742d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,10 +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() { | ||
function perflab_add_features_page(): void { | ||
$hook_suffix = add_options_page( | ||
__( 'Performance Features', 'performance-lab' ), | ||
__( 'Performance', 'performance-lab' ), | ||
|
@@ -31,11 +29,8 @@ function perflab_add_features_page() { | |
add_action( "load-{$hook_suffix}", 'perflab_load_features_page', 10, 0 ); | ||
add_filter( 'plugin_action_links_' . plugin_basename( PERFLAB_MAIN_FILE ), 'perflab_plugin_action_links_add_settings' ); | ||
} | ||
|
||
return $hook_suffix; | ||
} | ||
|
||
// @phpstan-ignore-next-line | ||
Comment on lines
-34
to
-38
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. As noted in #1188 (comment) this returning of the |
||
add_action( 'admin_menu', 'perflab_add_features_page' ); | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,11 +142,11 @@ function dominant_color_img_tag_add_dominant_color( $filtered_image, $context, $ | |
$extra_class = $image_meta['has_transparency'] ? 'has-transparency' : 'not-transparent'; | ||
} | ||
|
||
if ( ! empty( $data ) ) { | ||
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. PHPStan was complaining here:
For some reason switching to a simple boolean check fixed the issue. In any case, using Same goes for the change to |
||
if ( $data ) { | ||
$filtered_image = str_replace( '<img ', '<img ' . $data, $filtered_image ); | ||
} | ||
|
||
if ( ! empty( $extra_class ) ) { | ||
if ( $extra_class ) { | ||
$filtered_image = str_replace( ' class="', ' class="' . $extra_class . ' ', $filtered_image ); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,13 +71,13 @@ function webp_uploads_get_upload_image_mime_transforms() { | |
* @since 1.0.0 | ||
* @access private | ||
* | ||
* @param int $attachment_id The ID of the attachment from where this image would be created. | ||
* @param string $image_size The size name that would be used to create the image source, out of the registered subsizes. | ||
* @param array $size_data An array with the dimensions of the image: height, width and crop. | ||
* @param string $mime The target mime in which the image should be created. | ||
* @param string|null $destination_file_name The path where the file would be stored, including the extension. If null, `generate_filename` is used to create the destination file name. | ||
* @param int $attachment_id The ID of the attachment from where this image would be created. | ||
* @param string $image_size The size name that would be used to create the image source, out of the registered subsizes. | ||
* @param array{ width: int, height: int, crop: bool } $size_data An array with the dimensions of the image: height, width and crop. | ||
* @param string $mime The target mime in which the image should be created. | ||
* @param string|null $destination_file_name The path where the file would be stored, including the extension. If null, `generate_filename` is used to create the destination file name. | ||
* | ||
* @return array|WP_Error An array with the file and filesize if the image was created correctly, otherwise a WP_Error. | ||
* @return array{ file: string, filesize: int }|WP_Error An array with the file and filesize if the image was created correctly, otherwise a WP_Error. | ||
*/ | ||
function webp_uploads_generate_additional_image_source( $attachment_id, $image_size, array $size_data, $mime, $destination_file_name = null ) { | ||
/** | ||
|
@@ -88,11 +88,19 @@ function webp_uploads_generate_additional_image_source( $attachment_id, $image_s | |
* | ||
* @since 1.1.0 | ||
* | ||
* @param array|null|WP_Error $image Image data {'path'=>string, 'file'=>string, 'width'=>int, 'height'=>int, 'mime-type'=>string} or null or WP_Error. | ||
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. Note that |
||
* @param int $attachment_id The ID of the attachment from where this image would be created. | ||
* @param string $image_size The size name that would be used to create this image, out of the registered subsizes. | ||
* @param array $size_data An array with the dimensions of the image: height, width and crop {'height'=>int, 'width'=>int, 'crop'}. | ||
* @param string $mime The target mime in which the image should be created. | ||
* @param array{ | ||
* file: string, | ||
* path?: string, | ||
* filesize?: int | ||
* }|null|WP_Error $image Image data, null, or WP_Error. | ||
* @param int $attachment_id The ID of the attachment from where this image would be created. | ||
* @param string $image_size The size name that would be used to create this image, out of the registered subsizes. | ||
* @param array{ | ||
* width: int, | ||
* height: int, | ||
* crop: bool | ||
* } $size_data An array with the dimensions of the image. | ||
* @param string $mime The target mime in which the image should be created. | ||
*/ | ||
$image = apply_filters( 'webp_uploads_pre_generate_additional_image_source', null, $attachment_id, $image_size, $size_data, $mime ); | ||
if ( is_wp_error( $image ) ) { | ||
|
@@ -157,7 +165,7 @@ function webp_uploads_generate_additional_image_source( $attachment_id, $image_s | |
$destination_file_name = $editor->generate_filename( $suffix, null, $extension[0] ); | ||
} | ||
|
||
remove_filter( 'image_editor_output_format', 'webp_uploads_filter_image_editor_output_format', 10, 3 ); | ||
remove_filter( 'image_editor_output_format', 'webp_uploads_filter_image_editor_output_format', 10 ); | ||
$image = $editor->save( $destination_file_name, $mime ); | ||
add_filter( 'image_editor_output_format', 'webp_uploads_filter_image_editor_output_format', 10, 3 ); | ||
|
||
|
@@ -188,7 +196,7 @@ function webp_uploads_generate_additional_image_source( $attachment_id, $image_s | |
* @param string $size The size name that would be used to create this image, out of the registered subsizes. | ||
* @param string $mime A mime type we are looking to use to create this image. | ||
* | ||
* @return array|WP_Error | ||
* @return array{ file: string, filesize: int }|WP_Error | ||
*/ | ||
function webp_uploads_generate_image_size( $attachment_id, $size, $mime ) { | ||
$sizes = wp_get_registered_image_subsizes(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,18 @@ | |
* | ||
* @param array $metadata An array with the metadata from this attachment. | ||
* @param int $attachment_id The ID of the attachment where the hook was dispatched. | ||
* @return array An array with the updated structure for the metadata before is stored in the database. | ||
* @return array{ | ||
* width: int, | ||
* height: int, | ||
* file: non-falsy-string, | ||
* sizes: array, | ||
* image_meta: array, | ||
* filesize: int, | ||
* sources?: array<string, array{ | ||
* file: string, | ||
* filesize: int | ||
* }> | ||
* } An array with the updated structure for the metadata before is stored in the database. | ||
*/ | ||
function webp_uploads_create_sources_property( array $metadata, $attachment_id ) { | ||
// This should take place only on the JPEG image. | ||
|
@@ -538,7 +549,27 @@ function webp_uploads_update_image_references( $content ) { | |
* @return string The updated img tag. | ||
*/ | ||
function webp_uploads_img_tag_update_mime_type( $original_image, $context, $attachment_id ) { | ||
$image = $original_image; | ||
$image = $original_image; | ||
|
||
/** | ||
* Metadata potentially amended by webp_uploads_create_sources_property(). | ||
* | ||
* Note the sources key is not normally present in the response for wp_get_attachment_metadata(). The sources | ||
* key here, however, is being injected via the 'wp_generate_attachment_metadata' filter via the | ||
* webp_uploads_create_sources_property() function. | ||
* | ||
* @see webp_uploads_create_sources_property() | ||
* | ||
* @var array{ | ||
* width: int, | ||
* height: int, | ||
* file: non-falsy-string, | ||
* sizes: array, | ||
* image_meta: array, | ||
* filesize: int, | ||
* sources?: array<string, array{ file: string, filesize: int }> | ||
* } $metadata | ||
*/ | ||
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. Without this type definition, the 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. I revisited this when bumping PHPStan to level 3. See #1200. |
||
$metadata = wp_get_attachment_metadata( $attachment_id ); | ||
|
||
if ( empty( $metadata['file'] ) ) { | ||
|
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.
I guess
WPINC
should be added to https://github.com/szepeviktor/phpstan-wordpressThere 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.
I know there is no core function to get the value of WPINC but I do not want to encourage the users of my package to use WPINC.