[wp-trac] [WordPress Trac] #44437: Invocation parameter types are not compatible with declared
WordPress Trac
noreply at wordpress.org
Fri Jun 22 12:30:24 UTC 2018
#44437: Invocation parameter types are not compatible with declared
------------------------------------+-----------------------------
Reporter: subrataemfluence | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: REST API | Version: trunk
Severity: normal | Keywords: 2nd-opinion
Focuses: docs, coding-standards |
------------------------------------+-----------------------------
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
<?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
<?php
public function get_item( $request ) {
$obj = get_post_type_object( $request['type'] );
...
$data = $this->prepare_item_for_response( $obj, $request );
}
}}}
and
{{{#!php
<?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.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/44437>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list