Skip to content

Code Quality: Fix the nullCoalesce.property PHPStan error and remove the baseline - #15474

Closed
bgturner wants to merge 3 commits into
WordPress:trunkfrom
bgturner:ticket/65817
Closed

bgturner wants to merge 3 commits into
WordPress:trunkfrom
bgturner:ticket/65817

Conversation

@bgturner

@bgturner bgturner commented Nov 4, 2026

Copy link
Copy Markdown

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

Fixes the one remaining nullCoalesce.property error and removes tests/phpstan/baselines/nullCoalesce.property.neon.

The error

src/wp-includes/general-template.php:4986
Property WP_Query::$max_num_pages (int) on left side of ?? is not nullable.

WP_Query::$max_num_pages defaults to 0 and is never null, so ?? 1 in paginate_links() never ran.

The fix

Swap ?? for ?:, which falls back on any falsy value, including 0. This matches what the function's own docblock already claims: "Default is the value WP_Query's max_num_pages or 1."

Why this is safe

This is narrower than the attempt in #13982, where a reviewer asked for this exact line to be reverted because it also added a null-guard around $wp_query itself and broke get_query_var( 'paged' ). This PR doesn't touch $wp_query's nullability -- only the fallback condition on one property that can never be null.

A new test, test_paginate_links_falls_back_to_global_query_with_zero_max_num_pages, pins the only caller-visible path through this line (max_num_pages = 0 returns null, since paginate_links() treats totals under 2 the same way) and passes identically before and after this change.

Add a test that `paginate_links()` returns null when the global query
reports zero total pages, matching its behavior for a single total page.

See #65817.
…e the baseline.

`WP_Query::$max_num_pages` defaults to `0` and is never `null`, so the
`?? 1` fallback in `paginate_links()` never ran. Use `?:` instead, which
also falls back for `0`, and retire the now-empty baseline.

See #65817.
@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 bgturner.

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.

@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.

…ort ternary.

WordPress Coding Standards disallows `?:` (Universal.Operators.DisallowShortTernary).
Use the `$x ? $x : $y` form already used elsewhere in core for a falsy fallback.

See #65817.
@bgturner

bgturner commented Nov 4, 2026

Copy link
Copy Markdown
Author

Closed accidentally by a branch rename (GitHub's branch-rename API deleted the old ref instead of retargeting this PR). Same commits now live at #15475.

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