Skip to content

Build/QA: Retire empty.offset baseline - #14027

Closed
huzaifaalmesbah wants to merge 1 commit into
WordPress:trunkfrom
huzaifaalmesbah:phpstan/retire-empty-offset
Closed

huzaifaalmesbah wants to merge 1 commit into
WordPress:trunkfrom
huzaifaalmesbah:phpstan/retire-empty-offset

Conversation

@huzaifaalmesbah

Copy link
Copy Markdown
Member

Description

This PR resolves all occurrences of empty.offset in WordPress core and retires the baseline file tests/phpstan/baselines/empty.offset.neon:

  1. In WP_Internal_Pointers::enqueue_scripts(), $registered_pointers is initialized as an empty array (array()) awaiting future feature pointers. PHPStan flagged empty( $registered_pointers[ $hook_suffix ] ) because $registered_pointers was inferred as a closed empty array shape array{}. Adding /** @var array<string, string|string[]> $registered_pointers */ and /** @var array<string, string[]> $caps_required */ documents the expected dictionary structure and avoids false positives and dead-code warnings.
  2. In wp_read_video_metadata(), $metadata is dynamically built across several format checks. In empty( $metadata[\x27created_timestamp\x27] ), PHPStan flagged that \x27created_timestamp\x27 was not present in the closed array shape inferred from earlier keys. Adding /** @var array<string, mixed> $metadata */ aligns with wp_read_audio_metadata() and reflects the open associative array structure.

With these refined docblocks, empty.offset.neon is completely emptied and deleted, and an obsolete deadCode.unreachable baseline entry for class-wp-internal-pointers.php is also retired.

Testing Instructions

  1. Run PHPStan static analysis:
    composer phpstan
    Verify 0 errors are found.
  2. Run media and pointers unit tests:
    npm run test:php -- --filter=test_wp_read_video_metadata
    npm run test:php -- tests/phpunit/tests/media.php
    Verify all tests pass.

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

Use of AI Tools

AI assistance: Yes
Tool(s): Google Antigravity
Model(s): Gemini 3.8 Flash
Used for: Researching static analysis reports, array shapes, and drafting initial baseline diffs; all logic, type declarations, and analysis results were manually investigated, verified, and run locally by me.

@github-actions

github-actions Bot commented Oct 6, 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 6, 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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are identified for the array-type annotation and PHPStan baseline cleanup.

No open issues 🎉

What changed in this PR

This PR retires WordPress core’s PHPStan empty.offset baseline by documenting array types in internal pointers and video metadata handling. It changes static-analysis annotations and configuration without changing runtime logic.

Changes:

  • Add array-type annotations for pointer registrations, required capabilities, and video metadata.
  • Delete the empty.offset baseline and remove its configuration include.
  • Remove the obsolete internal-pointers entry from the unreachable-code baseline.
File Description
tests/​phpstan/​baselines/​empty.offset.neon Delete the retired baseline.
tests/​phpstan/​baselines/​deadCode.unreachable.neon Remove the internal-pointers suppression.
src/​wp-admin/​includes/​media.php Document the video metadata array type.
src/​wp-admin/​includes/​class-wp-internal-pointers.php Document pointer and capability array types.
phpstan.neon.dist Remove the deleted baseline’s include.

Review effort: Balanced

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The source changes are analysis annotations only, and the array types match the existing pointer and metadata structures. Full PHPStan analysis passed locally on the reviewed head with its pinned dependencies. CI is green, Copilot found no active issues, and an SVN dry run applies all hunks. No additional PHPUnit tests are needed for these annotations.

AI review · gpt-6

wporg-sync pushed a commit that referenced this pull request Oct 31, 2026
Clarify pointer, metadata, and REST array types. Simplify equivalent Site Health, timezone, and upload checks while preserving the theme filter re-evaluation. Remove the resolved `empty.offset`, `booleanAnd.rightAlwaysTrue`, and `identical.alwaysTrue` baselines and the related unreachable-code entry.

Developed in: #14027, #14031, #14032

Props huzaifaalmesbah.
See #65817.


git-svn-id: https://develop.svn.wordpress.org/trunk@65149 602fd350-edb4-49c9-b593-d223f7449a82
@lancewillett

Copy link
Copy Markdown
Member

wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Oct 31, 2026
Clarify pointer, metadata, and REST array types. Simplify equivalent Site Health, timezone, and upload checks while preserving the theme filter re-evaluation. Remove the resolved `empty.offset`, `booleanAnd.rightAlwaysTrue`, and `identical.alwaysTrue` baselines and the related unreachable-code entry.

Developed in: WordPress/wordpress-develop#14027, WordPress/wordpress-develop#14031, WordPress/wordpress-develop#14032

Props huzaifaalmesbah.
See #65817.

Built from https://develop.svn.wordpress.org/trunk@65149


git-svn-id: http://core.svn.wordpress.org/trunk@64298 1a063a9b-81f0-0310-95a4-ce76da25c4cd
* 'themes.php' => 'wp390_widgets'
* )
*/
/** @var array<string, string|string[]> $registered_pointers */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: The @var could have been included with the existing comment:

diff --git a/src/wp-admin/includes/class-wp-internal-pointers.php b/src/wp-admin/includes/class-wp-internal-pointers.php
index 448e7af914..0e11d759a9 100644
--- a/src/wp-admin/includes/class-wp-internal-pointers.php
+++ b/src/wp-admin/includes/class-wp-internal-pointers.php
@@ -35,7 +35,7 @@ final class WP_Internal_Pointers {
 	 * @param string $hook_suffix The current admin page.
 	 */
 	public static function enqueue_scripts( $hook_suffix ) {
-		/*
+		/**
 		 * Register feature pointers
 		 *
 		 * Format:
@@ -47,8 +47,9 @@ final class WP_Internal_Pointers {
 		 *     array(
 		 *         'themes.php' => 'wp390_widgets'
 		 *     )
+		 *
+		 * @var array<string, string|string[]> $registered_pointers
 		 */
-		/** @var array<string, string|string[]> $registered_pointers */
 		$registered_pointers = array(
 			// None currently.
 		);
@@ -60,7 +61,7 @@ final class WP_Internal_Pointers {
 
 		$pointers = (array) $registered_pointers[ $hook_suffix ];
 
-		/*
+		/**
 		 * Specify required capabilities for feature pointers
 		 *
 		 * Format:
@@ -72,8 +73,9 @@ final class WP_Internal_Pointers {
 		 *     array(
 		 *         'wp390_widgets' => array( 'edit_theme_options' )
 		 *     )
+		 *
+		 * @var array<string, string[]> $caps_required
 		 */
-		/** @var array<string, string[]> $caps_required */
 		$caps_required = array(
 			// None currently.
 		);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested in #15303

return false;
}

/** @var array<string, mixed> $metadata */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems to have masked a real bug. Namely, look below at this code:

if ( empty( $metadata['created_timestamp'] ) ) {
$created_timestamp = wp_get_media_creation_timestamp( $data );
if ( false !== $created_timestamp ) {
$metadata['created_timestamp'] = $created_timestamp;
}
}

There is no nowhere between this if statement and the $metadata variable initialization that the created_timestamp key is set. So PHPStan was indeed flagging dead code. This is the change that should be made:

diff --git a/src/wp-admin/includes/media.php b/src/wp-admin/includes/media.php
index 896af458eb..9f5b87ce85 100644
--- a/src/wp-admin/includes/media.php
+++ b/src/wp-admin/includes/media.php
@@ -3677,7 +3677,6 @@ function wp_read_video_metadata( $file ) {
 		return false;
 	}
 
-	/** @var array<string, mixed> $metadata */
 	$metadata = array();
 
 	if ( ! defined( 'GETID3_TEMP_DIR' ) ) {
@@ -3751,12 +3750,9 @@ function wp_read_video_metadata( $file ) {
 		$metadata['audio'] = $data['audio'];
 	}
 
-	if ( empty( $metadata['created_timestamp'] ) ) {
-		$created_timestamp = wp_get_media_creation_timestamp( $data );
-
-		if ( false !== $created_timestamp ) {
-			$metadata['created_timestamp'] = $created_timestamp;
-		}
+	$created_timestamp = wp_get_media_creation_timestamp( $data );
+	if ( false !== $created_timestamp ) {
+		$metadata['created_timestamp'] = $created_timestamp;
 	}
 
 	wp_add_id3_tag_data( $metadata, $data );

cc @lancewillett

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up PR: #15303

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. The broad array<string, mixed> annotation hid the useful diagnostic: created_timestamp has not been set at that point, so the outer condition is redundant. I should have traced the assignment path instead of accepting the wider type. I’m reviewing #15303, including PHPStan and the existing media checks, as the follow-up.

AI review · gpt-6

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.

4 participants