Make WordPress Core

Opened 6 years ago

Closed 5 years ago

#44365 closed enhancement (fixed)

Coding Standards: Yoda condition check is not present

Reported by: subrataemfluence's profile subrataemfluence Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 5.4 Priority: normal
Severity: normal Version:
Component: Administration Keywords:
Focuses: coding-standards Cc:

Description

In wp-admin/admin.php between line nos. 358 and 372, Yoda conditions are not met according to the sniffer.

Here is the code we have now:

<?php
if ( $typenow == 'page' ) {
   if ( $pagenow == 'post-new.php' ) {
     do_action( 'load-page-new.php' );
   } elseif ( $pagenow == 'post.php' ) {
     do_action( 'load-page.php' );
   }
} elseif ( $pagenow == 'edit-tags.php' ) {
   if ( $taxnow == 'category' ) {
     do_action( 'load-categories.php' );
   } elseif ( $taxnow == 'link_category' ) {
     do_action( 'load-edit-link-categories.php' );
   }
} elseif ( 'term.php' === $pagenow ) {
   do_action( 'load-edit-tags.php' );
}

One thing to notice at the end of the above code block. We have a Yoda condition checked. I am not sure why it used only at one place. Is this done in purpose?

<?php
...
} elseif ( 'term.php' === $pagenow ) {
   do_action( 'load-edit-tags.php' );
}

Can we re-write the block of code and make it consistent as proposed in my patch?

Attachments (1)

44365.diff (1002 bytes) - added by subrataemfluence 6 years ago.

Download all attachments as: .zip

Change History (7)

#1 @abdullahramzan
6 years ago

  • Keywords 2nd-opinion removed
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #44028.

#2 @subrataemfluence
6 years ago

  • Resolution duplicate deleted
  • Status changed from closed to reopened

Thank you for looking into it.
But as far as I have seen there is no patch for admin.php in #44208.
Should I upload the patch there?

#3 @pento
6 years ago

  • Version trunk deleted

#4 @mukesh27
5 years ago

#47193 was marked as a duplicate.

#5 @SergeyBiryukov
5 years ago

  • Component changed from General to Administration
  • Milestone changed from Awaiting Review to 5.4
  • Owner set to SergeyBiryukov
  • Status changed from reopened to reviewing

#6 @SergeyBiryukov
5 years ago

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

In 47218:

Coding Standards: Use Yoda conditions in some wp-admin files.

Props subrataemfluence, marcio-zebedeu, bookdude13, 1naveengiri, alishankhan.
Fixes #44365, #48455.

Note: See TracTickets for help on using tickets.