Opened 7 years ago
Closed 3 weeks ago
#46846 closed defect (bug) (fixed)
Tight comparisons and use of Yoda conditions are not consistent
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 6.9 | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | Formatting | Keywords: | has-patch dev-feedback |
| Focuses: | coding-standards | Cc: |
Description
In wp-includes/formatting.php, as I have seen comparisons and use of Yoda conditions are not consistent through out the file. I have made some changes and uploading a proposed patch here. Let me know if this helps!
Attachments (2)
Change History (10)
#2
in reply to:
↑ 1
;
follow-up:
↓ 7
@
5 months ago
- Keywords 2nd-opinion added
most if not all conditionals are now written as yoda conditions
All the proposed comparisons are now strict, and most of them have switched to Yoda condition order.
- r45887: strict comparison and Yoda condition in
iso8601_to_datetime() - r47219: strict comparison and Yoda condition in
iso8601_timezone_to_offset(), plus Yoda conditions forantispambot()andsanitize_option() - r47808: strict comparisons in
convert_smilies(),wp_trim_excerpt(),esc_url(),sanitize_option(), andwp_staticize_emoji() - r55642: strict comparison in
wp_sprintf_l() - r56325: strict comparison in
antispambot()
That still leaves two from the first patch. However, similar comparisons exist elsewhere in the same file.
if ( count( $matches ) === 0 )on line 3432 fortranslate_smiley()is likeif ( strpos( $email, '@', 1 ) === false )on line 3558 foris_email()matches- line 3772 for
sanitize_email()
- line 3772 for
In addition to those, I found
if ( trim( $text ) === '' )on line 449 forwpautop()if ( $force || (int) get_option( 'use_balanceTags' ) === 1 )on line 2544 forbalanceTags()if ( stripos( $text, 'target' ) === false || stripos( $text, '<a ' ) === false || is_serialized( $text ) )on line 3312 forwp_targeted_link_rel(), which r59120 deprecated
I'll upload a patch editing those 8 lines, in case it is worth reopening the ticket for any of them.
#3
@
5 months ago
- Milestone changed from Awaiting Review to 6.9
- Resolution worksforme deleted
- Status changed from closed to reopened
@sabernhardt I've reopened the ticket to consider your patch and placed it on the 6.9 milestone. That will ensure the props are assigned correctly.
This ticket was mentioned in PR #9607 on WordPress/wordpress-develop by IshikaBansal95.
3 months ago
#4
Trac ticket:
This ticket was mentioned in Slack in #core by ishika_bansal. View the logs.
3 months ago
#6
@
3 months ago
- Keywords 2nd-opinion removed
removing the '2nd-opinion' keyword since the ticket was reopened and we have a pull request
#7
in reply to:
↑ 2
@
3 weeks ago
- Owner set to SergeyBiryukov
- Status changed from reopened to reviewing
Replying to sabernhardt:
I'll upload a patch editing those 8 lines, in case it is worth reopening the ticket for any of them.
Thanks for the patch!
Looking at the PHP coding standards, Yoda conditions are mostly relevant for variables:
When doing logical comparisons involving variables, always put the variable on the right side and put constants, literals, or function calls on the left side. If neither side is a variable, the order is not important.
So technically, I'm not sure this needs any changes. However, if the goal is to make the order more consistent throughout the file, I have no objections to that :)
Hi @subrataemfluence,
I have taken a quick look into this, and compared your patch to whats there today in the file, and I can see that most if not all conditionals are now written as yoda conditions. As of such I am going to close this ticket, but if you have anything further to add on this please reopen it.