WordPress / WordPress/WordPress-Coding-Standards

Handbook: Check that ternaries test for `true`

Open
#643 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Component: Core Type: Enhancement
Dominant language
PHP
Stars
2.8k
Forks
521
Avg merge
5d 20h
Merged PRs (30d)
1

Description

Ternary operators are fine, but always have them test if the statement is true, not false. Otherwise, it just gets confusing. (An exception would be using ! empty(), as testing for false here is generally more intuitive.)

ref: https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#ternary-operator

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read the referenced WordPress coding-standards handbook section, then locate the existing PHP_CodeSniffer rule or entry point for ternary operators. Confirm how the exception for ! empty() should be treated, and consider the work complete when ternaries consistently test for true unless that exception applies.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.