Repository navigation
Docs: Clarify the weekday range in WP_Locale::get_weekday(). - #14827
rootzero00 wants to merge 3 commits into
Conversation
Trac ticket: https://core.trac.wordpress.org/ticket/64522 WordPress.org contributor: raulsalvat
|
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:
|
This comment has been minimized.
This comment has been minimized.
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. |
| * @param int<0, 6> $weekday_number 0 for Sunday through 6 Saturday. | ||
| * @return string Full translated weekday. |
There was a problem hiding this comment.
Let's keep the @param as-is since the int<0, 6> syntax is specific to PHPStan and not yet used for standard tags.
| * @param int<0, 6> $weekday_number 0 for Sunday through 6 Saturday. | |
| * @return string Full translated weekday. | |
| * @param int $weekday_number 0 for Sunday through 6 Saturday. | |
| * @return string Full translated weekday. | |
| * | |
| * @phpstan-param int<0, 6> $weekday_number |
westonruter
left a comment
There was a problem hiding this comment.
While we're here, we should go ahead and update the other methods with similar type narrowings. For example, the get_meridiem() method should add a:
@phpstan-param 'am'|'pm'|'AM'|'PM' $meridiem
Same for the other methods where relevant. I think get_month() and get_month_genitive() are the other candidates.
|
🤖 Comment by Claude Opus 5.5 Several follow-up changes were made while reviewing the new Changes
Upstream PHPStan fix for
|
| File | Count | Trunk message |
|---|---|---|
src/wp-includes/functions.php |
1 | Parameter #1 $weekday_number of method WP_Locale::get_weekday() expects int, string given. |
src/wp-includes/general-template.php |
2 | Parameter #1 $weekday_number of method WP_Locale::get_weekday() expects int, string|false given. |
Level 10
| Trunk base | PR head | With follow-ups | |
|---|---|---|---|
| Errors | 1955 | 1964 | 1950 |
Fixed relative to the PR head: 14 errors
| Identifier | Count | Where (line numbers at the PR head) |
|---|---|---|
argument.type |
6 | get_month() given non-empty-string, non-falsy-string, string|false, or int: src/wp-admin/export.php:167, src/wp-admin/includes/class-wp-list-table.php:815, src/wp-admin/includes/media.php:2969, and src/wp-includes/general-template.php:1653, 1951, and 2740 |
argument.type |
1 | get_weekday() given int<-6, 6>: src/wp-includes/general-template.php:2749 |
method.nonObject |
7 | Cannot call method …() on DateTime|false. on every use of $datetime in wp_date(): src/wp-includes/functions.php:261, 264, 271, 272, 289, 292, and 308 |
Seven more errors at the PR head are not fixed but go back to their trunk wording, because get_month() again expects int|string: the six mixed arguments from query vars and database rows (general-template.php:1661, 1948, 2381, 2851, and 2863, and media.php:5062) and the zeroise() call inside get_month().
Relative to trunk: 7 fixed, 2 introduced
- Fixed: the 7
method.nonObjecterrors inwp_date()listed above. - Introduced: 2
argument.typeerrors forget_meridiem()atsrc/wp-includes/functions.php:294and297, which Infer literal types for word date format characters phpstan/phpstan-src#6838 resolves. - Unchanged apart from wording: the
zeroise()call inget_month_genitive()now reportsint<1, 12>|string giveninstead ofint|string given.
|
@rootzero00 please able maintainer edits for this PR and others as that will facilitate getting changes into core. |
Clarifies the expected weekday range for
WP_Locale::get_weekday()by changing$weekday_numberfrominttoint<0, 6>, following the suggestion in the Trac discussion. The range is inclusive: 0 is Sunday and 6 is Saturday. Runtime behavior is unchanged.Trac ticket: https://core.trac.wordpress.org/ticket/64522
Verification
php8.2 -n -d memory_limit=128M -d log_errors=0 -d display_errors=stderr -l.git diff --no-ext-diff --no-textconv --checkpassed.src/wp-includes/class-wp-locale.php; executable PHP is unchanged. Runtime tests were not run for this documentation-only change.Contributor: Raul Salvat. Requested WordPress.org props:
raulsalvat.Use of AI Tools
AI assistance: Yes.
Tool: ChatGPT/Codex.
Used for: Preparing the one-line annotation edit and the verification/submission commands, reviewing command results and the diff, and drafting this PR description. The annotation follows the proposal already present in the Trac discussion. Server commands were executed by the contributor.
This pull request is for code review only. Please keep other discussion in the Trac ticket; do not merge this pull request on GitHub.