Opened 7 years ago
Closed 7 years ago
#44227 closed defect (bug) (duplicate)
Inconsistency in Yoda condition check in WordPress core
Reported by: | subrataemfluence | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | General | Keywords: | |
Focuses: | coding-standards | Cc: |
Description
According to @pento in #42885
Ultimately, the aim is to have phpcs run on every commit. If we don't allow assignments in conditions, then the reason for Yoda conditions (avoiding accidental assignment in conditions) should no longer be necessary.
@jdgrimes says in the same ticket
Before committing this, maybe a good time to reconsider this rule? Now that we can run PHPCS over the code, we could just disallow assignments in conditions, and then Yoda conditions wouldn't really be necessary.
However, we have a good amount of Yoda condition applied already. Here is an example:
<?php if ( '.' !== $plugin_slug && false === strpos( $plugin_slug, '/' ) ) { ... }
at line number 98 of wp-admin/includes/plugin.php
.
I think the coding style and pattern should be consistent across the whole application. Otherwise, it will lead to even more confusion if both exist side by side.
Please correct me if I am wrong.
@subrataemfluence I would suggest continuing the discussion about this in #42885.