Skip to content
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

Use Elvis operator (a ?: b) where possible to replace a ? a : b style of ternary expressions #4942

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

Ayesh
Copy link

@Ayesh Ayesh commented Jul 31, 2023

This is a somewhat big change, but a simple one at that.

Replaces a ? a : b patterns of ternary statements to use the Elvis operator a ?: b.

Null coalescing operator (??) was added in PHP 7.0, which WordPress now requires as the minimum version. However, to make this ticket focused and easier to review, this ticket only proposes the Elvis operator.

On tainted lines, it follows WordPress CS to use uppercase constants (NULL instead of null, for example), and removes a few cases of unnecessary braces. Apart from them, the diff output should be quite minimal and straight forward.

Perhaps, the review will be easier with word-diff (git show --word-diff), or on GitHub, where it highlights word diffs in the line-diff mode.

Trac ticket: https://core.trac.wordpress.org/ticket/58948


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@@ -702,7 +702,7 @@ function twentythirteen_get_link_url() {
$content = get_the_content();
$has_url = get_url_in_content( $content );

return ( $has_url ) ? $has_url : apply_filters( 'the_permalink', get_permalink() );
return ( $has_url ) ?: apply_filters( 'the_permalink', get_permalink() );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return ( $has_url ) ?: apply_filters( 'the_permalink', get_permalink() );
return $has_url ?: apply_filters( 'the_permalink', get_permalink() );

remove brackets

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants