WordPress.org

Make WordPress Core

Opened 4 weeks ago

#44437 new defect (bug)

Invocation parameter types are not compatible with declared

Reported by: subrataemfluence Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: trunk
Component: REST API Keywords: 2nd-opinion
Focuses: docs, coding-standards Cc:

Description

In class-wp-rest-post-types-controller.php the type of parameter $post_type in function prepare_item_for_response is declared as stdClass.

<?php
* @param stdClass $post_type Post type data.
...
public function prepare_item_for_response( $post_type, $request ) {
   ...
}

The function has been called twice in the class file:

<?php
public function get_item( $request ) {
   $obj = get_post_type_object( $request['type'] );
   ...
   $data = $this->prepare_item_for_response( $obj, $request );
}

and

<?php
public function get_items( $request ) {
   ...
   foreach( get_post_types( array(), 'object' ) as $obj ) {
      ...
   }

   $post_type = $this->prepare_item_for_response( $obj, $request );
}

Since $obj is a known type, i.e. WP_Post_Type can we declare the parameter $post_type type as WP_Post_Type instead of stdClass ?

Also, the object of this class is used in wp-includes/rest-api.php for registering route but the function in question is never invoked in the system separately.

Attachments (1)

44437.diff (672 bytes) - added by subrataemfluence 4 weeks ago.
Proposed patch

Download all attachments as: .zip

Change History (1)

@subrataemfluence
4 weeks ago

Proposed patch

Note: See TracTickets for help on using tickets.