Completed
Push — branch-4.1 ( 1d03cd...834c58 )
by Jeremy
57:44 queued 46:16
created

class.wpcom-json-api-get-post-v1-1-endpoint.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
class WPCOM_JSON_API_Get_Post_v1_1_Endpoint extends WPCOM_JSON_API_Post_v1_1_Endpoint {
3
	// /sites/%s/posts/%d      -> $blog_id, $post_id
4
	// /sites/%s/posts/slug:%s -> $blog_id, $post_id
5
	function callback( $path = '', $blog_id = 0, $post_id = 0 ) {
6
		$blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) );
7
		if ( is_wp_error( $blog_id ) ) {
8
			return $blog_id;
9
		}
10
11
		$args = $this->query_args();
12
13
		if ( false !== strpos( $path, '/posts/slug:' ) ) {
14
			$post_id = $this->get_platform()->get_site( $blog_id )->get_post_id_by_name( $post_id );
15
			if ( is_wp_error( $post_id ) ) {
16
				return $post_id;
17
			}
18
		}
19
20
		if ( defined( 'IS_WPCOM' ) && IS_WPCOM &&
21
				! in_array( get_post_type( $post_id ), array( false, 'post', 'page', 'revision' ) ) ) {
22
			$this->load_theme_functions();
23
		}
24
25
		$return = $this->get_post_by( 'ID', $post_id, $args['context'] );
0 ignored issues
show
$post_id is of type integer|object, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
26
27
		if ( !$return || is_wp_error( $return ) ) {
28
			return $return;
29
		}
30
31 View Code Duplication
		if ( ! $this->current_user_can_access_post_type( $return['type'], $args['context'] ) ) {
32
			return new WP_Error( 'unknown_post', 'Unknown post', 404 );
33
		}
34
35
		/** This action is documented in json-endpoints/class.wpcom-json-api-site-settings-endpoint.php */
36
		do_action( 'wpcom_json_api_objects', 'posts' );
37
38
		return $return;
39
	}
40
}
41