-
Notifications
You must be signed in to change notification settings - Fork 139
Use null coalescing operator in ternaries #2339
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
base: trunk
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## trunk #2339 +/- ##
=======================================
Coverage 69.17% 69.17%
=======================================
Files 90 90
Lines 7696 7696
=======================================
Hits 5324 5324
Misses 2372 2372
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
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.
Pull request overview
This PR modernizes code style by replacing a ternary operator with the null coalescing operator (??) for better readability and consistency with modern PHP best practices.
Changes:
- Replaced
isset()ternary pattern with null coalescing operator on line 159
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| $height = isset( $size_data['height'] ) ? (int) $size_data['height'] : 0; | ||
| $width = isset( $size_data['width'] ) ? (int) $size_data['width'] : 0; |
Copilot
AI
Jan 10, 2026
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.
For consistency with the updated line 159, lines 157-158 should also use the null coalescing operator since they follow the same pattern. However, note that lines 157-158 include type casting to (int), so they should be updated to maintain that casting:
- Line 157:
$height = (int) ($size_data['height'] ?? 0); - Line 158:
$width = (int) ($size_data['width'] ?? 0);
This would make all three assignments consistent in style.
| $height = isset( $size_data['height'] ) ? (int) $size_data['height'] : 0; | |
| $width = isset( $size_data['width'] ) ? (int) $size_data['width'] : 0; | |
| $height = (int) ( $size_data['height'] ?? 0 ); | |
| $width = (int) ( $size_data['width'] ?? 0 ); |
See Core-58874.
I only found one instance.