Completed
Push — add/protect-module-sync-packag... ( ad899a...19deca )
by
unknown
133:23 queued 125:08
created

WPCOM_JSON_API_Get_Option_Endpoint::result()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
use Automattic\Jetpack\Sync\Defaults;
4
5
class WPCOM_JSON_API_Get_Option_Endpoint extends Jetpack_JSON_API_Endpoint {
6
7
	protected $needed_capabilities = 'manage_options';
8
9
	public $option_name;
10
	public $site_option;
11
12
	function result() {
13
		if ( $this->site_option ) {
14
			return array( 'option_value' => get_site_option( $this->option_name ) );
15
		}
16
		return array( 'option_value' => get_option( $this->option_name ) );
17
	}
18
19
	function validate_input( $object ) {
20
		$query_args = $this->query_args();
21
		$this->option_name = isset( $query_args['option_name'] ) ? $query_args['option_name'] : false;
22
		if ( ! $this->option_name ) {
23
			return new WP_Error( 'option_name_not_set', __( 'You must specify an option_name', 'jetpack' ) );
0 ignored issues
show
Unused Code introduced by
The call to WP_Error::__construct() has too many arguments starting with 'option_name_not_set'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
24
		}
25
		$this->site_option = isset( $query_args['site_option'] ) ? $query_args['site_option'] : false;
26
27
		/**
28
		 * Filter the list of options that are manageable via the JSON API.
29
		 *
30
		 * @module json-api
31
		 *
32
		 * @since 3.8.2
33
		 *
34
		 * @param array The default list of site options.
35
		 * @param bool Is the option a site option.
36
		 */
37
		if ( ! in_array( $this->option_name, apply_filters( 'jetpack_options_whitelist', Defaults::$default_options_whitelist, $this->site_option ) ) ) {
0 ignored issues
show
Bug introduced by
The property default_options_whitelist cannot be accessed from this context as it is declared private in class Automattic\Jetpack\Sync\Defaults.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
38
			return new WP_Error( 'option_name_not_in_whitelist', __( 'You must specify a whitelisted option_name', 'jetpack' ) );
0 ignored issues
show
Unused Code introduced by
The call to WP_Error::__construct() has too many arguments starting with 'option_name_not_in_whitelist'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
39
		}
40
		return true;
41
	}
42
}
43