Repository navigation
PHPStan: Retire booleanAnd.alwaysFalse baseline - #13980
huzaifaalmesbah wants to merge 3 commits into
Conversation
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
- 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.
a4a5d84 to
bfd3f97
Compare
…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
Description
This PR retires the
booleanAnd.alwaysFalsebaseline file by resolving both reported instances in WordPress core:src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php:In
update_item(), line 996 had an unassigned$schemavariable (if ( ! empty( $schema['properties']['featured_media'] ) && isset( $request['featured_media'] ) )).Crucially,
parent::update_item( $request )(inWP_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 inWP_REST_Attachments_Controller::update_item()caused non-audio/non-video attachments (such as standard images) to fail with arest_no_featured_media400 error. The duplicate block was dead code that only existed because$schemawas unassigned. Removing this redundant block cleans up the dead code and properly delegates featured media updates to the parent controller.src/wp-admin/themes.php:Line 128 statically initializes
$parent_file = 'themes.php';. Therefore, the sub-expressionempty( $parent_file )inside the menu highlighting condition at line 376 was always false. Simplified the check toif ( $item[2] === $parent_file ) { $class = ' current'; }.Changes Made
handle_featured_media()block inWP_REST_Attachments_Controller::update_item().$parent_filematching condition insrc/wp-admin/themes.php.tests/phpstan/baselines/booleanAnd.alwaysFalse.neon.phpstan.neon.dist.booleanAnd.leftAlwaysTrue.neon(-1),empty.variable.neon(-2), andvariable.undefined.neon(-1) that were eliminated by these fixes.Testing Instructions
./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.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.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.