-
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
Eliminate usage of empty()
construct
#1803
Eliminate usage of empty()
construct
#1803
Conversation
Signed-off-by: Shyamsundar Gadde <[email protected]>
Signed-off-by: Shyamsundar Gadde <[email protected]>
Signed-off-by: Shyamsundar Gadde <[email protected]>
Signed-off-by: Shyamsundar Gadde <[email protected]>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## trunk #1803 +/- ##
==========================================
+ Coverage 65.85% 65.89% +0.03%
==========================================
Files 88 88
Lines 6851 6878 +27
==========================================
+ Hits 4512 4532 +20
- Misses 2339 2346 +7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
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.
Looking mostly good! Just some minor feedback.
@@ -220,7 +220,7 @@ public function use_output_buffer(): bool { | |||
* | |||
* @since 1.8.0 | |||
* | |||
* @param bool $use_output_buffer Whether to use an output buffer. | |||
* @param bool $enabled Whether to use an output buffer. |
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.
Good catch.
if ( empty( $option_name ) ) { | ||
if ( '' === $option_name ) { |
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.
If someone passed an option_name
of '0'
then this will pass through the condition since empty( '0' ) === true
: https://3v4l.org/LurUe
I don't think this is a problem here though 😄
plugins/performance-lab/includes/site-health/audit-enqueued-assets/hooks.php
Outdated
Show resolved
Hide resolved
plugins/performance-lab/includes/site-health/audit-enqueued-assets/hooks.php
Outdated
Show resolved
Hide resolved
plugins/performance-lab/includes/site-health/audit-enqueued-assets/hooks.php
Outdated
Show resolved
Hide resolved
plugins/webp-uploads/helper.php
Outdated
@@ -185,7 +185,7 @@ function webp_uploads_generate_additional_image_source( int $attachment_id, stri | |||
return $image; | |||
} | |||
|
|||
if ( empty( $image['file'] ) ) { | |||
if ( ! isset( $image['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.
Technically:
if ( ! isset( $image['file'] ) ) { | |
if ( ! isset( $image['file'] ) || '' === $image['file'] ) { |
However, in practice it seems that if $image
is not a WP_Error
then really the file
should always be set. So this entire if
statement seems it might be worth removing.
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.
Updated the check in 375a1ed.
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 think it might be safer to leave the check in because of the image_make_intermediate_size
filter applied to the file
key. Let me know if you feel strongly about removing it!
Co-authored-by: Weston Ruter <[email protected]>
Co-authored-by: Weston Ruter <[email protected]>
Co-authored-by: Weston Ruter <[email protected]>
Co-authored-by: Weston Ruter <[email protected]>
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.
@ShyamGadde This looks good, thank you for working on this! Just a few small notes on potential improvements.
Co-authored-by: Felix Arntz <[email protected]>
Co-authored-by: Felix Arntz <[email protected]>
Co-authored-by: Felix Arntz <[email protected]>
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.
Thanks for the updates @ShyamGadde, this basically looks good to me.
Two more things that I missed in the review before. Would be great if you could address them, but I will preemptively approve.
Co-authored-by: Felix Arntz <[email protected]>
Co-authored-by: Weston Ruter <[email protected]>
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.
Just a nit suggestion left, but pre-approving!
Co-authored-by: Weston Ruter <[email protected]>
Summary
Fixes #1219
Relevant technical choices
This PR eliminates the use of
empty()
in the following plugins:dominant-color-images
performance-lab
webp-uploads