Skip to content

Code Quality: Fix the argument.unresolvableType PHPStan error and remove the baseline - #15450

Closed
mukeshpanchal27 wants to merge 6 commits into
WordPress:trunkfrom
mukeshpanchal27:fix/argument-unresolvabletype-baseline
Closed

mukeshpanchal27 wants to merge 6 commits into
WordPress:trunkfrom
mukeshpanchal27:fix/argument-unresolvabletype-baseline

Conversation

@mukeshpanchal27

@mukeshpanchal27 mukeshpanchal27 commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

✅ Committed in r65783 (4293f64).


This PR fixes the only argument.unresolvableType error and deletes tests/phpstan/baselines/argument.unresolvableType.neon. It also documents the arguments of wp_get_recent_posts() and fixes the level 10 error on its call to get_posts(). There is no runtime change.

Since r65566, PHPStan loads the baselines from tests/phpstan/baselines/ automatically, so deleting the file is enough and phpstan.neon.dist does not change.

The error

src/wp-includes/post.php:4726
Parameter #1 $maybeint of function absint contains unresolvable type.

wp_get_recent_posts() still accepts an integer number of posts, which has been deprecated since 3.1.0:

if ( is_numeric( $args ) ) {
	_deprecated_argument( __FUNCTION__, '3.1.0', ... );
	$args = array( 'numberposts' => absint( $args ) );
}

The @param tag documented $args as array only. PHPStan trusts the docblock, so it concluded that is_numeric( $args ) can never be true. Inside that branch, $args has no possible type, and the absint() call receives an unresolvable type.

This error is not a false positive. The docblock was incomplete, because it left out a form that the function still accepts.

The fix

  • $args is documented as array|int, with the deprecation stated in the description. This follows wp_get_typography_font_size_value(), whose @param still lists the deprecated bool (r64163). The code does not change, because plugins can still pass an integer. No caller in core passes one.
  • A hash documents the keys whose defaults differ from those of get_posts(): numberposts, offset, orderby, and post_status. It refers to get_posts() and WP_Query::parse_query() for the rest.
  • A @phpstan-param narrows the deprecated integer to positive-int. absint() would silently turn a negative number into a positive count, and 0 falls back to the posts_per_page option, so PHPStan now flags calls passing 0, a negative number, or a numeric string. The shape is written by hand, as in wp_delete_term(), because the hash cannot express positive-int. It stays open with ..., since any WP_Query argument is accepted.
  • The arguments passed to get_posts() are typed. The inline @var on $parsed_args typed only fields, so at level 10 the other keys were mixed and did not match the shape derived from the get_posts() hash. The @var and the $args shape now also type category, include, exclude, and suppress_filters. The include and exclude defaults change from '' to array(), matching get_posts() and its documented int[]. This makes no runtime difference, because get_posts() only reads them when they are not empty.
  • fields is limited to ''|'all'. The @var used to pin fields to null so that the conditional return type of get_posts() resolves to WP_Post[], but nothing checked it. A caller passing 'fields' => 'ids' with the default ARRAY_A output makes get_object_vars() receive an integer and throw a TypeError. The $args shape now rejects that, and the @var repeats the same type.

Testing

  • composer phpstan:default and composer phpstan:strict both report no errors with the baseline deleted.
  • At level 10, wp_get_recent_posts() and its core caller in class-wp-xmlrpc-server.php report no errors.
  • A probe file confirms that wp_get_recent_posts( 5 ) and array arguments pass, while 0, -3, '5', array( 'numberposts' => 'x' ), and array( 'fields' => 'ids' ) are flagged. The return type still resolves to array<int, non-empty-array<string, mixed>> for ARRAY_A and array<WP_Post>|false for OBJECT.
  • PHPCS reports the same warnings on src/wp-includes/post.php as on trunk.

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

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5 (medium effort for the follow-up commits)
Used for: Finding the cause of the error, editing the docblock and baseline, writing the follow-up commits that document $args and type the arguments passed to get_posts(), and drafting the PR. The changes were reviewed by a human.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

…()`.

`wp_get_recent_posts()` still accepts an integer number of posts, which has been deprecated since 3.1.0. The `@param` tag documented `$args` as `array` only, so PHPStan concluded that `is_numeric( $args )` can never be true. It then reported that the `absint()` call in that branch receives an unresolvable type.

This change documents `$args` as `array|int`, states the deprecation in its description, deletes the now empty `argument.unresolvableType` baseline, and removes its `includes` line from `phpstan.neon.dist`. There is no runtime change.

See #65817.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 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.

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

Props mukesh27, westonruter.

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 or WordPress.org 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.

@mukeshpanchal27 mukeshpanchal27 self-assigned this Nov 4, 2026
@github-actions

github-actions Bot commented Nov 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.

@mukeshpanchal27 mukeshpanchal27 changed the title Docs: Fix the argument.unresolvableType PHPStan error and remove the baseline Code Quality:: Fix the argument.unresolvableType PHPStan error and remove the baseline Nov 4, 2026
@mukeshpanchal27
mukeshpanchal27 requested a lite review from Copilot November 4, 2026 08:58

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 remain, and the documented supported argument type aligns with removing the obsolete PHPStan baseline and configuration entry.

No open issues 🎉

What changed in this PR

This pull request fixes the remaining PHPStan argument.unresolvableType error by documenting the deprecated integer form accepted by wp_get_recent_posts(). Runtime behavior is unchanged.

Changes:

  • Documents $args as array|int and notes the deprecated integer usage.
  • Removes the resolved PHPStan baseline.
  • Removes the deleted baseline from phpstan.neon.dist.
File Description
tests/​phpstan/​baselines/​argument.unresolvableType.neon Removes the obsolete PHPStan error baseline.
src/​wp-includes/​post.php Documents the supported deprecated integer argument form.
phpstan.neon.dist Removes the deleted baseline from the PHPStan includes.

Review effort: Lite

Comment thread phpstan.neon.dist Resolved
…vabletype-baseline

# Conflicts:
#	phpstan.neon.dist
#	tests/phpstan/baselines/argument.unresolvableType.neon
@mukeshpanchal27 mukeshpanchal27 changed the title Code Quality:: Fix the argument.unresolvableType PHPStan error and remove the baseline Code Quality: Fix the argument.unresolvableType PHPStan error and remove the baseline Nov 24, 2026
westonruter and others added 4 commits November 25, 2026 00:13
Add a hash for `$args` listing the keys whose defaults differ from those of `get_posts()`, and a `@phpstan-param` that narrows the deprecated integer form to `positive-int`.

The function passes an integer through `absint()`, so a caller passing a negative number silently gets that many posts as a positive count, and one passing `0` gets the number from the `posts_per_page` option. PHPStan now flags those calls. The shape is written by hand rather than derived from the hash, since the hash cannot express `positive-int`, as in `wp_delete_term()`. It is left open with `...`, because any `WP_Query` argument is accepted.

Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>
Claude-Code-Session-Id: afd4d078-9c23-4da0-9ee0-7b1e32f41dd6
…et_posts()`.

The inline `@var` on the parsed arguments only typed `fields`, so every other key was `mixed`, and at level 10 PHPStan reported that the array could not be passed to `get_posts()`, whose hash types `numberposts`, `category`, `include`, `exclude`, and `suppress_filters`. The `@var` now types those keys too.

The `$args` shape gains the same keys, so callers are checked against the same contract as callers of `get_posts()`. The `include` and `exclude` defaults change from `''` to `array()`, matching `get_posts()` and the documented `int[]`. There is no runtime change, since `get_posts()` only reads either one when it is not empty.

Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>
Claude-Code-Session-Id: afd4d078-9c23-4da0-9ee0-7b1e32f41dd6
…objects.

The inline `@var` on the parsed arguments pinned `fields` to `null` so that the conditional return type of `get_posts()` resolves to `WP_Post[]`. Nothing checked that claim, so a caller could pass `'fields' => 'ids'` unflagged, and with the default `ARRAY_A` output `get_object_vars()` then receives an integer and throws a `TypeError`.

The `$args` shape now limits `fields` to `''` or `'all'`, so PHPStan flags callers that ask for IDs, and the `@var` repeats that type in place of `null`. There is no runtime change.

Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>
Claude-Code-Session-Id: afd4d078-9c23-4da0-9ee0-7b1e32f41dd6
wporg-sync pushed a commit that referenced this pull request Nov 25, 2026
The `$args` parameter was documented as accepting only an array, even though a deprecated integer number of posts is still accepted. PHPStan therefore concluded that the deprecated branch could never run, and reported the value passed to `absint()` there as an unresolvable type. Documenting the integer form, as was done for `wp_get_typography_font_size_value()` in r64163, empties the `argument.unresolvableType` baseline, so it is removed.

For static analysis the integer is narrowed to `positive-int`, since `absint()` silently turns a negative number into a positive count and `0` falls back to the `posts_per_page` option. A hash now documents the arguments whose defaults differ from those of `get_posts()`.

At level 10 the parsed arguments could not be passed to `get_posts()`, because the inline `@var` typed only `fields`. It now types the keys that `get_posts()` documents. Instead of being asserted to be `null`, `fields` is limited to `''` or `'all'`, since a caller asking for IDs would make `get_object_vars()` throw a `TypeError` with the default `ARRAY_A` output. The `include` and `exclude` defaults become empty arrays to match their documented type, which has no runtime effect.

Developed in #15450.
Follow-up to r62648, r63024, r64163.

Props mukesh27, westonruter.
See #66739.


git-svn-id: https://develop.svn.wordpress.org/trunk@65783 602fd350-edb4-49c9-b593-d223f7449a82
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Nov 25, 2026
The `$args` parameter was documented as accepting only an array, even though a deprecated integer number of posts is still accepted. PHPStan therefore concluded that the deprecated branch could never run, and reported the value passed to `absint()` there as an unresolvable type. Documenting the integer form, as was done for `wp_get_typography_font_size_value()` in r64163, empties the `argument.unresolvableType` baseline, so it is removed.

For static analysis the integer is narrowed to `positive-int`, since `absint()` silently turns a negative number into a positive count and `0` falls back to the `posts_per_page` option. A hash now documents the arguments whose defaults differ from those of `get_posts()`.

At level 10 the parsed arguments could not be passed to `get_posts()`, because the inline `@var` typed only `fields`. It now types the keys that `get_posts()` documents. Instead of being asserted to be `null`, `fields` is limited to `''` or `'all'`, since a caller asking for IDs would make `get_object_vars()` throw a `TypeError` with the default `ARRAY_A` output. The `include` and `exclude` defaults become empty arrays to match their documented type, which has no runtime effect.

Developed in WordPress/wordpress-develop#15450.
Follow-up to r62648, r63024, r64163.

Props mukesh27, westonruter.
See #66739.

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


git-svn-id: http://core.svn.wordpress.org/trunk@64812 1a063a9b-81f0-0310-95a4-ce76da25c4cd
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.

3 participants