Make WordPress Core

Opened 7 months ago

Closed 9 days ago

#63249 closed defect (bug) (fixed)

Minor code and inline docs improvements in class-wp-rest-server.php

Reported by: dilipbheda's profile dilipbheda Owned by: audrasjb's profile audrasjb
Milestone: 6.9 Priority: normal
Severity: normal Version:
Component: REST API Keywords: has-patch
Focuses: docs Cc:

Description

Inline Documentation Improvement

Some @param tags are missing default value annotations. e.g:

  • @param string|null — the default value should be specified when applicable.
  • @param false|null — missing mention of the default value.

Conditional Logic Adjustment

Function: get_json_last_error()

The current condition:

if ( JSON_ERROR_NONE === $last_error_code || empty( $last_error_code ) ) {

Proposed change:

if ( empty( $last_error_code ) || JSON_ERROR_NONE === $last_error_code ) {

This change reorders the condition to check for an empty value first, which is a common best practice. It improves readability and slightly optimizes performance by short-circuiting sooner when $last_error_code is empty.

Change History (16)

This ticket was mentioned in PR #8662 on WordPress/wordpress-develop by @dilipbheda.


7 months ago
#1

#2 @audrasjb
7 months ago

  • Milestone changed from Awaiting Review to 6.9
  • Owner set to audrasjb
  • Status changed from new to reviewing

#3 @SergeyBiryukov
7 months ago

In 60151:

Coding Standards: Remove extra check in WP_REST_Server::get_json_last_error().

json_last_error() can only return an integer, and the JSON_ERROR_NONE constant has the value of 0, so the empty() check is redundant here.

Follow-up to [34928], [46206].

Props dilipbheda, audrasjb, SergeyBiryukov.
See #63249.

This ticket was mentioned in Slack in #core by welcher. View the logs.


2 weeks ago

#5 @welcher
2 weeks ago

  • Keywords needs-refresh added

This was reviewed in the 6.9 Bug Scrub today. The associated PR has conflicts and needs to be refreshed.

#6 @khushdoms
2 weeks ago

I’ve reviewed the latest code in class-wp-rest-server.php on trunk.
The get_json_last_error() function correctly checks only for JSON_ERROR_NONE and returns false as expected.
The redundant empty() check has been removed as per changeset [60151].
Inline docs are consistent as well.
Looks good to mark as fixed. Thanks everyone!

#7 @kirasong
11 days ago

I left a comment in the PR.

The only chunk that doesn't currently apply has already been resolved, as noted by @khushdoms.

The rest of the changes in the PR seem to still be pending and apply cleanly.

#8 @khushdoms
11 days ago

Thanks @kirasong for confirming.
I’ve rechecked the latest trunk — everything looks good, and the conflicting part was already resolved in [60151].
This can be refreshed or marked as fixed.

This ticket was mentioned in PR #10447 on WordPress/wordpress-develop by @shailu25.


11 days ago
#9

  • Keywords needs-refresh removed

@shailu25 commented on PR #8662:


11 days ago
#10

I have Created PR 10447 & Rebased with Latest Trunk and also removed mentioned Changes

@mukesh27 commented on PR #8662:


11 days ago
#11

I have Created PR 10447 & Rebased with Latest Trunk and also removed mentioned Changes

I don't think separate PR needed as it's minor revert that can be taken care when commit.

#12 @SergeyBiryukov
10 days ago

In 61112:

Docs: Correct @return type for WP_REST_Response::remove_link().

Follow-up to [34928].

Props dilipbheda, mukesh27, kirasong, shailu25, khushdoms, welcher, audrasjb, SergeyBiryukov.
See #63249.

#13 @SergeyBiryukov
10 days ago

In 61113:

Docs: Correct the type for some method parameters in WP_REST_Server class.

Follow-up to [34928].

Props dilipbheda, mukesh27, kirasong, shailu25, khushdoms, welcher, audrasjb, SergeyBiryukov.
See #63249.

#16 @SergeyBiryukov
9 days ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 61114:

Docs: Update description for some method parameters in WP_REST_Server class.

Follow-up to [47224], [59032].

Props dilipbheda, mukesh27, kirasong, shailu25, khushdoms, welcher, audrasjb, SergeyBiryukov.
Fixes #63249.

Note: See TracTickets for help on using tickets.