Completed
Push — branch-5.0 ( 360082...ee9cce )
by Jeremy
96:49 queued 85:16
created

result()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 0
dl 11
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3 View Code Duplication
class Jetpack_JSON_API_Get_User_Backup_Endpoint extends Jetpack_JSON_API_Endpoint {
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
4
	// /sites/%s/users/%d/backup      -> $blog_id, $user_id
5
6
	protected $needed_capabilities = array(); // This endpoint is only accessible using a site token
7
	protected $user_id;
8
9
	function validate_input( $user_id ) {
10
		if ( empty( $user_id ) || ! is_numeric( $user_id ) ) {
11
			return new WP_Error( 'user_id_not_specified', __( 'You must specify a User ID', 'jetpack' ), 400 );
12
		}
13
14
		$this->user_id = intval( $user_id );
15
16
		return true;
17
	}
18
19
	protected function result() {
20
		$user = get_user_by( 'id', $this->user_id );
21
		if ( empty( $user ) ) {
22
			return new WP_Error( 'user_not_found', __( 'User not found', 'jetpack' ), 404 );
23
		}
24
25
		return array(
26
			'user' => (array)$user,
27
			'meta' => get_user_meta( $user->ID ),
28
		);
29
	}
30
31
}
32
33