Completed
Push — update/travis-matrix-7 ( 497e3e...cc9f21 )
by
unknown
34:26 queued 14:09
created

WPCOM_JSON_API_Update_Option_Endpoint   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 21
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A result() 0 8 2
A validate_input() 0 8 3
1
<?php
2
3
class WPCOM_JSON_API_Update_Option_Endpoint extends WPCOM_JSON_API_Get_Option_Endpoint {
4
	public $option_value;
5
6
	function result() {
7
		if ( $this->site_option ) {
8
			update_site_option( $this->option_name, $this->option_value );
9
		} else {
10
			update_option( $this->option_name, $this->option_value );
11
		}
12
		return parent::result();
13
	}
14
15
	function validate_input( $object ) {
16
		$input = $this->input();
17
		if ( ! isset( $input['option_value'] ) || is_array( $input['option_value'] ) ) {
18
			return new WP_Error( 'option_value_not_set', __( 'You must specify an option_value', 'jetpack' ) );
19
		}
20
		$this->option_value = $input['option_value'];
21
		return parent::validate_input( $object );
22
	}
23
}
24