Completed
Push — update/remove-disconnect-link ( 4b6a2c )
by
unknown
73:18 queued 63:47
created

Jetpack_JSON_API_Translations_Modify_Endpoint   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 33.33 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A default_action() 9 9 3
A update() 0 9 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
class Jetpack_JSON_API_Translations_Modify_Endpoint extends Jetpack_JSON_API_Translations_Endpoint {
4
	// POST /sites/%s/translations
5
	// POST /sites/%s/translations/update
6
	protected $action              = 'default_action';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 14 spaces

This check looks for improperly formatted assignments.

Every assignment must have exactly one space before and one space after the equals operator.

To illustrate:

$a = "a";
$ab = "ab";
$abc = "abc";

will have no issues, while

$a   = "a";
$ab  = "ab";
$abc = "abc";

will report issues in lines 1 and 2.

Loading history...
7
	protected $new_version;
8
	protected $log;
9
10 View Code Duplication
	public function default_action() {
11
		$args = $this->input();
12
13
		if ( isset( $args['autoupdate'] ) && is_bool( $args['autoupdate'] ) ) {
14
			Jetpack_Options::update_option( 'autoupdate_translations', $args['autoupdate'] );
15
		}
16
17
		return true;
18
	}
19
20
	protected function update() {
21
		include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
22
23
		$upgrader = new Language_Pack_Upgrader( new Automatic_Upgrader_Skin() );
24
		$result = $upgrader->bulk_upgrade();
25
26
		$this->log = $upgrader->skin->get_upgrade_messages();
27
		$this->success = ( ! is_wp_error( $result ) ) ? (bool) $result : false;
28
	}
29
}
30