Completed
Push — add/changelog-50 ( 40a63e...720d2c )
by Jeremy
108:21 queued 97:51
created

callback()   D

Complexity

Conditions 10
Paths 12

Size

Total Lines 34
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
eloc 20
nc 12
nop 2
dl 0
loc 34
rs 4.8196
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
class WPCOM_JSON_API_Update_Site_Logo_Endpoint extends WPCOM_JSON_API_Endpoint {
4
	function callback( $path = '', $site_id = 0 ) {
5
		// Switch to the given blog.
6
		$blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $site_id ) );
7
		if ( is_wp_error( $blog_id ) ) {
8
			return $blog_id;
9
		}
10
11
		if ( ! current_user_can( 'edit_theme_options' ) ) {
12
			return new WP_Error( 'unauthorized', 'User is not authorized to access logo settings', 403 );
13
		}
14
15
		if ( strpos( $path, '/delete' ) ) {
16
			delete_option( 'site_logo' );
17
			return array();
18
		}
19
20
		$args = $this->input();
21
		$logo_settings = $this->get_current_settings();
22
		if ( empty( $args ) || ! is_array( $args ) ) {
23
			return $logo_settings;
24
		}
25
26
		if ( isset( $args['id'] ) ) {
27
			$logo_settings['id'] = intval( $args['id'], 10 );
28
		}
29
		if ( isset( $args['url'] ) ) {
30
			$logo_settings['url'] = $args['url'];
31
		}
32
		if ( isset( $args['url'] ) || isset( $args['id'] ) ) {
33
			update_option( 'site_logo', $logo_settings );
34
		}
35
36
		return $this->get_current_settings();
37
	}
38
39
	function get_current_settings() {
40
		$logo_settings = get_option( 'site_logo' );
41
		if ( ! is_array( $logo_settings ) ) {
42
			$logo_settings = array();
43
		}
44
		return $logo_settings;
45
	}
46
}
47
48