WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 4 months ago

#38296 closed enhancement (fixed)

Remove $sep variable duplication from Ternary Operator

Reported by: joelcj91 Owned by: SergeyBiryukov
Milestone: 5.9 Priority: normal
Severity: minor Version: 3.1
Component: Administration Keywords: has-patch
Focuses: administration, coding-standards Cc:

Description

In WP_List_Table class, we are using ternary operators a lot. We know that the main advantage of the ternary operator is, it makes code shorter.

Instead of uisng ternary operator like this,

( $i == $action_count ) ? $sep = '' : $sep = ' | ';

Can we use,

$sep = ( $i == $action_count ) ? '' : ' | ';

So the variable $sep is written once. Shortening the code a bit.

Attachments (3)

38296.patch (609 bytes) - added by joelcj91 5 years ago.
Patch to remove variable duplication
38296.2.patch (634 bytes) - added by joelcj91 3 years ago.
Patch refresh
38296.3.diff (604 bytes) - added by audrasjb 4 months ago.
Coding standards: Fix an inconsistency in the usage of ternary operators for the $sep variable/

Download all attachments as: .zip

Change History (11)

@joelcj91
5 years ago

Patch to remove variable duplication

#1 @joelcj91
5 years ago

  • Keywords has-patch added

#2 @desrosj
3 years ago

  • Keywords needs-refresh added
  • Milestone changed from Awaiting Review to Future Release
  • Version changed from 4.6.1 to 3.1

Thanks for this, @joelcj91! Sorry that it took so long to receive a response.

This is a good suggestion, IMO. Are you able to refresh the patch to apply cleanly to trunk?

@joelcj91
3 years ago

Patch refresh

#3 @joelcj91
3 years ago

  • Keywords needs-refresh removed

Thanks, @desrosj. I have updated the patch after updating the trunk.

#4 @audrasjb
4 months ago

  • Resolution set to fixed
  • Status changed from new to closed

Closing this ticket as fixed since it looks like it was previously fixed in another one.
Now the related code is:
$sep = ( $i < $action_count ) ? ' | ' : '';

#5 @audrasjb
4 months ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Hmm. Reopening this ticket as it appears that the issue wasn't fixed for every files.
Patch incoming.

@audrasjb
4 months ago

Coding standards: Fix an inconsistency in the usage of ternary operators for the $sep variable/

#6 @audrasjb
4 months ago

  • Milestone changed from Future Release to 5.9
  • Severity changed from normal to minor

Moving this minor patch for 5.9 consideration.

#7 @SergeyBiryukov
4 months ago

  • Focuses coding-standards added

#8 @SergeyBiryukov
4 months ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from reopened to closed

In 51873:

Coding Standards: Remove duplicate assignment from a ternary operator in WP_MS_Sites_List_Table::site_states().

Adjust similar code in _post_states() and _media_states() for consistency.

Follow-up to:

Props joelcj91, audrasjb, desrosj.
Fixes #38296.

Note: See TracTickets for help on using tickets.