Skip to content

Remove redundant truthiness checks after ! empty() - #86094

Merged
westonruter merged 2 commits into
WordPress:trunkfrom
huzaifaalmesbah:fix/phpstan-redundant-conditions
Nov 1, 2026
Merged

westonruter merged 2 commits into
WordPress:trunkfrom
huzaifaalmesbah:fix/phpstan-redundant-conditions

Conversation

@huzaifaalmesbah

@huzaifaalmesbah huzaifaalmesbah commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

What?

See #86088

Removes redundant truthiness checks that follow ! empty(), and removes the resolved entries from the PHPStan baseline.

Why?

! empty( $value ) && $value checks the same thing twice: ! empty() is only true when the value is set and truthy, so the right side of && is always true. PHPStan reports these as booleanAnd.rightAlwaysTrue. Together, these changes clear 5 of the 226 errors initially baselined in #66693.

How?

Dropped the redundant right-hand check in:

  • Categories: showOnlyTopLevel
  • Comments Title: showPostTitle and showCommentsCount
  • Navigation: isResponsive
  • Typography block support (lib/block-supports/typography.php): fitText. WordPress Core already has the simplified condition, so this brings Gutenberg in line with Core.

Removed the 5 corresponding entries from tools/phpstan/baseline.neon.

There is no change in behavior.

Testing Instructions

  1. Run composer phpstan and confirm it passes with no unmatched ignored errors.
  2. Run composer phpstan:baselines and confirm tools/phpstan/baseline.neon has no further changes.
  3. Optional smoke test: on the front end, check that a Categories block with "Show only top level categories" enabled, a Comments Title block with "Show post title" and "Show comments count" toggled, and a paragraph with "Fit text" enabled all render as before.

Testing Instructions for Keyboard

Not applicable. There are no UI changes.

Screenshots or screencast

Not applicable.

Use of AI Tools

I used Claude Code to identify the affected occurrences and draft the change. I reviewed the diff and take responsibility for it.

`! empty( $value ) && $value` checks the same thing twice, since `! empty()` is only true for truthy values. Drop the second check in the Categories, Comments Title, and Navigation blocks and in the typography block support, which matches WordPress Core. Remove the 5 resolved entries from the PHPStan baseline.

See WordPress#86088.
@huzaifaalmesbah huzaifaalmesbah added the [Type] Code Quality Issues or PRs that relate to code quality label Nov 1, 2026
@github-actions github-actions Bot added the [Package] Block library /packages/block-library label Nov 1, 2026
@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: huzaifaalmesbah <huzaifaalmesbah@git.wordpress.org>
Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

@huzaifaalmesbah huzaifaalmesbah added the No Core Sync Required Indicates that any changes do not need to be synced to WordPress Core label Nov 1, 2026
@huzaifaalmesbah
huzaifaalmesbah marked this pull request as ready for review November 1, 2026 02:33
…t-conditions

# Conflicts:
#	tools/phpstan/baseline.neon
@manzoorwanijk manzoorwanijk added the props-bot Manually triggers Props Bot to ensure the list of props is up to date. label Nov 1, 2026
@github-actions github-actions Bot removed the props-bot Manually triggers Props Bot to ensure the list of props is up to date. label Nov 1, 2026
@westonruter
westonruter merged commit baf9aea into WordPress:trunk Nov 1, 2026
94 checks passed
@github-actions github-actions Bot added this to the Gutenberg 24.4 milestone Nov 1, 2026
Vedant-Gandhi pushed a commit to Vedant-Gandhi/gutenberg that referenced this pull request Nov 30, 2026
`! empty( $value ) && $value` checks the same thing twice, since `! empty()` is only true for truthy values. Drop the second check in the Categories, Comments Title, and Navigation blocks and in the typography block support, which matches WordPress Core. Remove the 5 resolved entries from the PHPStan baseline.

See WordPress#86088.

Co-authored-by: huzaifaalmesbah <huzaifaalmesbah@git.wordpress.org>
Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

No Core Sync Required Indicates that any changes do not need to be synced to WordPress Core [Package] Block library /packages/block-library [Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants