Skip to content

PHPStan: Retire booleanAnd.alwaysFalse baseline - #13980

Open
huzaifaalmesbah wants to merge 3 commits into
WordPress:trunkfrom
huzaifaalmesbah:fix/phpstan-booleanand-alwaysfalse
Open

huzaifaalmesbah wants to merge 3 commits into
WordPress:trunkfrom
huzaifaalmesbah:fix/phpstan-booleanand-alwaysfalse

Conversation

@huzaifaalmesbah

@huzaifaalmesbah huzaifaalmesbah commented Oct 4, 2026 •

Copy link
Copy Markdown
Member

Description

This PR retires the booleanAnd.alwaysFalse baseline file by resolving both reported instances in WordPress core:

  1. src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php:
    In update_item(), line 996 had an unassigned $schema variable (if ( ! empty( $schema['properties']['featured_media'] ) && isset( $request['featured_media'] ) )).
    Crucially, parent::update_item( $request ) (in WP_REST_Posts_Controller) already invokes $this->handle_featured_media( $request['featured_media'], $post_id ) at line 1003.
    Calling handle_featured_media() a second time directly in WP_REST_Attachments_Controller::update_item() caused non-audio/non-video attachments (such as standard images) to fail with a rest_no_featured_media 400 error. The duplicate block was dead code that only existed because $schema was unassigned. Removing this redundant block cleans up the dead code and properly delegates featured media updates to the parent controller.

  2. src/wp-admin/themes.php:
    Line 128 statically initializes $parent_file = 'themes.php';. Therefore, the sub-expression empty( $parent_file ) inside the menu highlighting condition at line 376 was always false. Simplified the check to if ( $item[2] === $parent_file ) { $class = ' current'; }.

Changes Made

  • Removed the duplicate/redundant handle_featured_media() block in WP_REST_Attachments_Controller::update_item().
  • Simplified the $parent_file matching condition in src/wp-admin/themes.php.
  • Regenerated PHPStan baselines:
    • Retired and deleted tests/phpstan/baselines/booleanAnd.alwaysFalse.neon.
    • Updated phpstan.neon.dist.
    • Also cleared cascade-resolved baseline entries in booleanAnd.leftAlwaysTrue.neon (-1), empty.variable.neon (-2), and variable.undefined.neon (-1) that were eliminated by these fixes.

Testing Instructions

  1. Run ./vendor/bin/phpstan analyse src/wp-admin/themes.php src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php — verifies 0 errors reported.
  2. Run npm run test:php -- --filter WP_Test_REST_Attachments_Controller::test_create_update_post_with_featured_media — verifies featured media updates via REST API pass across all supported environments.
  3. Verify that the Appearance > Themes menu item is highlighted as active when viewing themes.php.

Trac ticket: https://core.trac.wordpress.org/ticket/65817

Use of AI Tools

AI assistance: Yes
Tool(s): Antigravity
Model(s): Gemini 3.8 Flash
Used for: Assisting with static analysis archaeology, tests, and diff preparation; all code and tests were manually reviewed, verified, and locally run by me.

@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props huzaifaalmesbah.

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

@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

- In src/wp-admin/themes.php, line 128 statically sets $parent_file = 'themes.php'. Therefore, empty( $parent_file ) is always false. Simplify the current menu item check to $item[2] === $parent_file.
- In src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php, $schema was used in update_item() without being assigned, causing $schema['properties']['featured_media'] to always evaluate to empty/false and generating an undefined variable notice. Initialize $schema = $this->get_item_schema(); as done in create_item().
- Regenerate PHPStan baselines to delete tests/phpstan/baselines/booleanAnd.alwaysFalse.neon and update phpstan.neon.dist.
@huzaifaalmesbah
huzaifaalmesbah force-pushed the fix/phpstan-booleanand-alwaysfalse branch from a4a5d84 to bfd3f97 Compare October 4, 2026 16:05
…ts_Controller::update_item

The parent method WP_REST_Posts_Controller::update_item() already processes and updates featured_media. Calling handle_featured_media() a second time on non-audio/non-video attachments (such as image attachments) caused rest_no_featured_media 400 error.
…nand-alwaysfalse

# Conflicts:
#	tests/phpstan/baselines/empty.variable.neon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant