Make WordPress Core

Opened 19 months ago

Closed 19 months ago

Last modified 19 months ago

#62033 closed enhancement (wontfix)

Fix missing Yoda Conditions

Reported by: debarghyabanerjee's profile debarghyabanerjee Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: General Keywords: has-patch
Focuses: coding-standards Cc:

Description

I noticed that Yoda conditions are not consistently used. This oversight appears in several areas of the codebase. It is important to address these inconsistencies to align with the coding standards and best practices.

I am mentioning the files, where I have encountered these missing Yoda conditions, however there can be more instances as well.

wp-admin/includes/misc.php
wp-admin/includes/upgrade.php
wp-admin/menu-header.php
wp-admin/update-core.php
wp-includes/blocks.php
wp-includes/class-wp-query.php
wp-includes/class-wpdb.php
wp-includes/formatting.php
wp-includes/functions.php
wp-includes/meta.php
wp-includes/ms-load.php
wp-includes/rest-api.php
wp-includes/template.php
wp-login.php

Change History (3)

This ticket was mentioned in PR #7325 on WordPress/wordpress-develop by @debarghyabanerjee.


19 months ago
#1

  • Keywords has-patch added

Trac Ticket: Core-62033

## Problem Statement

  • During a recent review of the codebase, it was observed that several comparison statements are missing Yoda conditions. This inconsistency may affect readability and increase the risk of errors due to potential assignment mistakes.

## Solution

  • This PR addresses the issue by refactoring the code to include Yoda conditions where appropriate. Specifically, I have updated comparison statements to ensure that constants are placed on the left side of comparisons, in line with the coding standards.

## Changes Made

  • Updated comparison statements to use Yoda conditions.
  • Ensured that all modifications are thoroughly tested to maintain code functionality.

## Impact

  • Improved readability and consistency in the codebase.
  • Reduced risk of assignment errors in comparison statements.

#2 @jrf
19 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

@debarghyabanerjee While I understand and appreciate your wish to improve WordPress, in none of the cases you flagged Yoda conditions are needed as none of these conditions do a comparison with a variable.
The patch would only decrease code readability for no benefit.

Also see: https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#yoda-conditions

@jrf commented on PR #7325:


19 months ago
#3

This patch should not be applied as none of these comparisons involve a variable.

Note: See TracTickets for help on using tickets.