Repository navigation
Code Quality: Remove the resolved identical.alwaysFalse PHPStan baseline - #13782
arshidkv12 wants to merge 5 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. 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. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
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. |
There was a problem hiding this comment.
Thanks for working on this! I checked each change against the surrounding code. All four source changes keep behavior the same, and CI is green. A few notes:
1. plugins.php: removing the update-selected notice ✅
The notice could never run. case 'update-selected': always ends with exit;, so execution never reaches the elseif further down. Safe to remove.
2. class-wp-html-processor.php: simplifying the catch ✅ (nit)
bookmark_token() throws in only one place, and it always sets last_error = ERROR_EXCEEDED_MAX_BOOKMARKS first, so returning false directly is equivalent.
- Nit: the catch now ignores which exception it got. If
bookmark_token()ever throws for another reason, that error will quietly becomereturn false. A short comment would help future readers, e.g.// bookmark_token() only throws after setting ERROR_EXCEEDED_MAX_BOOKMARKS. $eneeds to stay, since a catch without a variable requires PHP 8.0.- The similar catch in
step()'s outertryblock should stay as it is. That block can throw other exceptions, so its check does real work.
3. pluggable.php: wp_rand()
3000000000 === 2147483647 wasn't really dead code. It was a runtime check for broken 32-bit builds (Entropy PHP), where the literal gets cut down to PHP_INT_MAX. PHPStan flags it only because it analyzes on 64-bit. PHP_INT_SIZE === 4 still gives the right result on both normal and broken 32-bit builds, so the change is fine. Two suggestions:
- Please update the comment above this line. It still describes the truncation check, which the new condition no longer performs.
- Could we simplify further to
$max_random_number = 4294967295; // 0xffffffff? That truncation bug came from the PHP 5 era. Core now needs PHP 7.4+, where a literal that's too big for an int always becomes a float, so the ternary and the comment could both go. If you'd rather keep the smaller change,PHP_INT_SIZE === 4is fine and matches existing usage inwp-includes/update.php.
4. WP_REST_Users_Controller::check_reassign() ✅
empty( false ) is already true, so false === $value added nothing.
5. Baseline removal ✅
The include and the baseline file are both removed, and the PHPStan job passes.
🤖 Comment by Claude Opus 5.5
c3539a9 to
5de0787
Compare
This comment has been minimized.
This comment has been minimized.
|
I think, already fixed by r65566. |
No. I don't see the changes in trunk. |
|
There are PHPStan errors being reported. |
| phpstan: | ||
| name: PHP static analysis | ||
| uses: ./.github/workflows/reusable-phpstan-static-analysis-v1.yml | ||
| uses: ./.github/workflows/reusable-phpstan-static-analysis-v2.yml |
f794568 to
5de0787
Compare
a8d2b6a to
59dd1a6
Compare
The check-and-rethrow in the `catch` around `bookmark_token()` was added deliberately in r61755 so that only bookmark exhaustion is swallowed and any other exception still surfaces. It matches the guard in the second `catch` of `step()`, and PHPStan's report on it is a known false positive already ignored with an explanation in `phpstan.neon.dist`, so that ignore goes back to covering both occurrences. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Code-Session-Id: 8c9f232d-63db-4e34-bda9-62a5e32e95a7
The comment described detecting integer truncation, which the ternary no longer does. It now explains that 0xffffffff is cast to a float on every 32-bit system, with the misconfigured environments as the reason the cast is explicit rather than left to integer overflow. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Code-Session-Id: 8c9f232d-63db-4e34-bda9-62a5e32e95a7
In `wp_rand()` the `3000000000 === 2147483647` comparison was added in r21685 to detect misconfigured 32-bit PHP builds (Entropy PHP, for example) that truncate integer literals larger than `PHP_INT_MAX` instead of overflowing them to floats, so that `0xffffffff` could be built from a string cast to a float on them. PHPStan evaluates the literals as a 64-bit build does, so it reported the comparison as always false. It is replaced with a `PHP_INT_SIZE` check, which uses the explicit float on every 32-bit build. Behavior is unchanged, since on a correctly configured 32-bit build the literal already overflows to the same float. This empties the baseline, so it is removed. The `identical.alwaysFalse` ignore for `WP_HTML_Processor::step()` in `phpstan.neon.dist` remains, since that report is a false positive for the bookmark exhaustion guards added in r61755, which are intentional. Developed in #13782. Follow-up to r21685, r63023. Props arshidkv12, westonruter, mukesh27. See #66739. git-svn-id: https://develop.svn.wordpress.org/trunk@65792 602fd350-edb4-49c9-b593-d223f7449a82
In `wp_rand()` the `3000000000 === 2147483647` comparison was added in r21685 to detect misconfigured 32-bit PHP builds (Entropy PHP, for example) that truncate integer literals larger than `PHP_INT_MAX` instead of overflowing them to floats, so that `0xffffffff` could be built from a string cast to a float on them. PHPStan evaluates the literals as a 64-bit build does, so it reported the comparison as always false. It is replaced with a `PHP_INT_SIZE` check, which uses the explicit float on every 32-bit build. Behavior is unchanged, since on a correctly configured 32-bit build the literal already overflows to the same float. This empties the baseline, so it is removed. The `identical.alwaysFalse` ignore for `WP_HTML_Processor::step()` in `phpstan.neon.dist` remains, since that report is a false positive for the bookmark exhaustion guards added in r61755, which are intentional. Developed in WordPress/wordpress-develop#13782. Follow-up to r21685, r63023. Props arshidkv12, westonruter, mukesh27. See #66739. Built from https://develop.svn.wordpress.org/trunk@65792 git-svn-id: http://core.svn.wordpress.org/trunk@64821 1a063a9b-81f0-0310-95a4-ce76da25c4cd
✅ Committed in r65792 (f470162).
Remove the
identical.alwaysFalsePHPStan baseline by fixing the one error it suppressed.wp_rand(), usePHP_INT_SIZE === 4instead of the3000000000 === 2147483647literal comparison to decide whether to build0xffffffffas an explicit float. The old comparison, added in r21685 (Core-19571), was only true on misconfigured 32-bit builds (Entropy PHP, for example) that truncate integer literals larger thanPHP_INT_MAXinstead of overflowing them to floats. On a correctly configured 32-bit build that literal already overflows to the same float, so using the explicit cast on every 32-bit build changes nothing there, while still covering the misconfigured builds. The comment is updated to match.tests/phpstan/baselines/identical.alwaysFalse.neon, which is now empty.The
identical.alwaysFalseignore inphpstan.neon.distfor the twocatchblocks inWP_HTML_Processor::step()stays as is. It is a documented false positive, and the check-and-rethrow guards added in r61755 are intentional.Trac ticket: Core-66739
Use of AI Tools
AI assistance: Yes
Tool(s): ChatGPT, Claude Code
Model(s): GPT-5.6 Luna, Claude Opus 5.5 (medium effort)
Used for: ChatGPT was used for reviewing PHPStan findings and discussing possible fixes; the initial implementation was reviewed and made by the PR author. Claude Code was used during review to restore the
WP_HTML_Processor::step()guard, update thewp_rand()comment, and rewrite this description; those changes were reviewed by a maintainer.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.