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

Jetpack_JSON_API_Get_User_Backup_Endpoint   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 29
loc 29
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate_input() 9 9 3
A result() 11 11 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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